From 79d97022f2265f82add420c76e5ef9d5a6b0ed6d Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 31 Mar 2017 10:55:25 +0300 Subject: [PATCH 1/1] Send groupped events in finishOperation() until they exist --- src/Events/Events_Loop.cpp | 13 +++++-------- src/Events/Events_Loop.h | 6 +++--- src/Model/Model_Document.cpp | 27 +++++++++++++++++---------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/Events/Events_Loop.cpp b/src/Events/Events_Loop.cpp index 0d380b76b..7b9d16b1c 100644 --- a/src/Events/Events_Loop.cpp +++ b/src/Events/Events_Loop.cpp @@ -241,14 +241,6 @@ void Events_Loop::clear(const Events_ID& theID) } } -void Events_Loop::autoFlush(const Events_ID& theID, const bool theAuto) -{ - if (theAuto) - myFlushed.insert(theID.myID); - else - myFlushed.erase(myFlushed.find(theID.myID)); -} - bool Events_Loop::isFlushed(const Events_ID& theID) { return myFlushed.find(theID.myID) != myFlushed.end(); @@ -261,3 +253,8 @@ void Events_Loop::setFlushed(const Events_ID& theID, const bool theValue) else myFlushed.erase(myFlushed.find(theID.myID)); } + +bool Events_Loop::hasGrouppedEvent(const Events_ID& theID) +{ + return myGroups.find(theID.myID) != myGroups.end(); +} \ No newline at end of file diff --git a/src/Events/Events_Loop.h b/src/Events/Events_Loop.h index 69ea2ed24..94122adbe 100644 --- a/src/Events/Events_Loop.h +++ b/src/Events/Events_Loop.h @@ -86,14 +86,14 @@ class Events_Loop //! Clears all collected messages EVENTS_EXPORT void clear(const Events_ID& theID); - //! Enables flush without grouping for the given message - EVENTS_EXPORT void autoFlush(const Events_ID& theID, const bool theAuto = true); - //! Returns true if the evement is flushed right now EVENTS_EXPORT bool isFlushed(const Events_ID& theID); //! Sets the flag that the event is flished right now EVENTS_EXPORT void setFlushed(const Events_ID& theID, const bool theValue); + //! Returns true if a loop accumulated events to be flashed + EVENTS_EXPORT bool hasGrouppedEvent(const Events_ID& theID); + private: //! Calls "processEvent" for the given listeners. //! If theFlushedNow for grouped listeners is stores message in listeners. diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index ca4c907b0..7c93ab7b5 100755 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -557,10 +557,14 @@ bool Model_Document::finishOperation() } myObjs->synchronizeBackRefs(); Events_Loop* aLoop = Events_Loop::loop(); - aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); - aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); - aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); + static const Events_ID kCreatedEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED); + static const Events_ID kUpdatedEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED); + static const Events_ID kRedispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const Events_ID kDeletedEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED); + aLoop->flush(kCreatedEvent); + aLoop->flush(kUpdatedEvent); + aLoop->flush(kRedispEvent); + aLoop->flush(kDeletedEvent); if (isNestedClosed) { if (myDoc->CommitCommand()) @@ -571,11 +575,19 @@ bool Model_Document::finishOperation() // to avoid messages about modifications outside of the transaction // and to rebuild everything after all updates and creates if (isRoot()) { // once for root document - Events_Loop::loop()->autoFlush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); static std::shared_ptr aFinishMsg (new Events_Message(Events_Loop::eventByName("FinishOperation"))); Events_Loop::loop()->send(aFinishMsg); } + + while(aLoop->hasGrouppedEvent(kCreatedEvent) || aLoop->hasGrouppedEvent(kUpdatedEvent) || + aLoop->hasGrouppedEvent(kRedispEvent) || aLoop->hasGrouppedEvent(kDeletedEvent)) { + aLoop->flush(kCreatedEvent); + aLoop->flush(kUpdatedEvent); + aLoop->flush(kRedispEvent); + aLoop->flush(kDeletedEvent); + } + // to avoid "updated" message appearance by updater //aLoop->clear(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); @@ -587,11 +599,6 @@ bool Model_Document::finishOperation() if (subDoc(*aSubIter)->finishOperation()) aResult = true; - // sub-Part may send updated by flush of deleted (macro circle) - if (isRoot()) { // once for root document - Events_Loop::loop()->autoFlush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED), false); - } - // transaction may be empty if this document was created during this transaction (create part) if (!myTransactions.empty() && myDoc->CommitCommand()) { // if commit is successfull, just increment counters -- 2.30.2