[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/office/tellico
From:       Robby Stephenson <robby () periapsis ! org>
Date:       2011-04-05 5:11:47
Message-ID: 20110405051147.2F11FAC8CF () svn ! kde ! org
[Download RAW message or body]

SVN commit 1227138 by rstephenson:

Fix bug where removing an entry would not update loans for that entry.
BUG:270129


 M  +4 -0      ChangeLog  
 M  +9 -0      src/borrower.cpp  
 M  +2 -0      src/borrower.h  
 M  +20 -0     src/commands/removeentries.cpp  
 M  +9 -2      src/commands/removeloans.cpp  
 M  +1 -1      src/commands/removeloans.h  


--- trunk/extragear/office/tellico/ChangeLog #1227137:1227138
@@ -1,3 +1,7 @@
+2011-04-04  Robby Stephenson  <robby@periapsis.org>
+
+	* Fixed bug with loans not being updated for removed entries (Bug 270129).
+
 2011-03-21  Robby Stephenson  <robby@periapsis.org>
 
 	* Fixed crashing bug for editing some values (Bug 269044).
--- trunk/extragear/office/tellico/src/borrower.cpp #1227137:1227138
@@ -85,3 +85,12 @@
   m_loans.removeAll(loan_);
   return true;
 }
+
+bool Borrower::hasEntry(Data::EntryPtr entry_) {
+  foreach(const LoanPtr loan, m_loans) {
+    if(loan->entry() == entry_) {
+      return true;
+    }
+  }
+  return false;
+}
--- trunk/extragear/office/tellico/src/borrower.h #1227137:1227138
@@ -96,6 +96,8 @@
   void addLoan(Data::LoanPtr loan);
   bool removeLoan(Data::LoanPtr loan);
 
+  bool hasEntry(Data::EntryPtr entry);
+
 private:
   QString m_name;
   QString m_uid; // uid used by KABC
--- trunk/extragear/office/tellico/src/commands/removeentries.cpp #1227137:1227138
@@ -23,8 +23,10 @@
  ***************************************************************************/
 
 #include "removeentries.h"
+#include "removeloans.h"
 #include "../collection.h"
 #include "../controller.h"
+#include "../tellico_debug.h"
 
 #include <klocale.h>
 
@@ -39,7 +41,21 @@
     setText(m_entries.count() > 1 ? i18n("Delete Entries")
                                   : i18nc("Delete (Entry Title)", "Delete %1", m_entries[0]->title()));
   }
+
+  // also need to allow for removing entries that might be loaned out
+  // nothing for it but to do full-blown iterative search
+  Data::LoanList loans;
+  foreach(Data::BorrowerPtr borrower, m_coll->borrowers()) {
+    foreach(Data::EntryPtr entry, m_entries) {
+      if(borrower->hasEntry(entry)) {
+        loans += borrower->loan(entry);
 }
+    }
+  }
+  if(!loans.isEmpty()) {
+    new RemoveLoans(loans, this);
+  }
+}
 
 void RemoveEntries::redo() {
   if(!m_coll || m_entries.isEmpty()) {
@@ -48,6 +64,8 @@
 
   m_coll->removeEntries(m_entries);
   Controller::self()->removedEntries(m_entries);
+  
+  QUndoCommand::redo();
 }
 
 void RemoveEntries::undo() {
@@ -57,4 +75,6 @@
 
   m_coll->addEntries(m_entries);
   Controller::self()->addedEntries(m_entries);
+
+  QUndoCommand::undo();
 }
--- trunk/extragear/office/tellico/src/commands/removeloans.cpp #1227137:1227138
@@ -33,8 +33,8 @@
 
 using Tellico::Command::RemoveLoans;
 
-RemoveLoans::RemoveLoans(Tellico::Data::LoanList loans_)
-    : QUndoCommand()
+RemoveLoans::RemoveLoans(Tellico::Data::LoanList loans_, QUndoCommand* parent_)
+    : QUndoCommand(parent_)
     , m_loans(loans_)
 {
   if(!m_loans.isEmpty()) {
@@ -78,13 +78,20 @@
     if(loan->inCalendar()) {
       calLoans.append(loan);
     }
+    // if the removeed loan was the only one by the borrower
+    // then instead of modifying the borrower, it has to be added back to the model
+    const bool emptyBorrower = loan->borrower()->isEmpty();
     loan->borrower()->addLoan(loan);
     Data::Document::self()->checkOutEntry(loan->entry());
     Data::EntryList vec;
     vec.append(loan->entry());
     Controller::self()->modifiedEntries(vec);
+    if(emptyBorrower) {
+      Controller::self()->addedBorrower(loan->borrower());
+    } else {
     Controller::self()->modifiedBorrower(loan->borrower());
   }
+  }
   if(!calLoans.isEmpty()) {
     CalendarHandler::addLoans(calLoans);
   }
--- trunk/extragear/office/tellico/src/commands/removeloans.h #1227137:1227138
@@ -38,7 +38,7 @@
 class RemoveLoans : public QUndoCommand  {
 
 public:
-  RemoveLoans(Data::LoanList loans);
+  RemoveLoans(Data::LoanList loans, QUndoCommand* parent = 0);
 
   virtual void redo();
   virtual void undo();
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic