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

List:       kde-commits
Subject:    extragear/base/konq-plugins/domtreeviewer
From:       David Faure <faure () kde ! org>
Date:       2010-11-22 0:28:07
Message-ID: 20101122002807.87C79AC8A0 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1199477 by dfaure:

Port away from kde3support (k3command/k3commandhistory -> qundocommand/kundostack)

Fix crash due to "delete cur_item ; cur_item = foo" without telling the caller of the \
method who passed cur_item by pointer and kept using it afterwards. Interestingly \
this has been in the code forever...
BUG: 206639
FIXED-IN: 4.6


 M  +1 -2      CMakeLists.txt  
 M  +3 -3      domtreecommands.cpp  
 M  +6 -11     domtreecommands.h  
 M  +4 -3      domtreeview.cpp  
 M  +1 -1      domtreeview.h  
 M  +13 -5     domtreewindow.cpp  
 M  +3 -3      domtreewindow.h  


--- trunk/extragear/base/konq-plugins/domtreeviewer/CMakeLists.txt #1199476:1199477
@@ -1,5 +1,4 @@
 
-
 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  ${KDE4_ENABLE_EXCEPTIONS}")
 ########### next target ###############
 
@@ -17,7 +16,7 @@
 
 
 
-target_link_libraries(domtreeviewerplugin  ${KDE4_KDE3SUPPORT_LIBS} \
${KDE4_KHTML_LIBS} ) +target_link_libraries(domtreeviewerplugin ${KDE4_KHTML_LIBS} )
 
 install(TARGETS domtreeviewerplugin  DESTINATION ${PLUGIN_INSTALL_DIR} )
 
--- trunk/extragear/base/konq-plugins/domtreeviewer/domtreecommands.cpp \
#1199476:1199477 @@ -112,7 +112,7 @@
 void ManipulationCommand::handleException(DOM::DOMException &ex)
 {
   _exception = ex;
-  QString msg = name() + ": " + domErrorMessage(ex.code);
+  QString msg = text() + ": " + domErrorMessage(ex.code);
   emit mcse()->error(ex.code, msg);
 }
 
@@ -137,7 +137,7 @@
   changedNodes->insert(node, true);
 }
 
-void ManipulationCommand::execute()
+void ManipulationCommand::redo()
 {
   if (!isValid()) return;
 
@@ -157,7 +157,7 @@
   _reapplied = true;
 }
 
-void ManipulationCommand::unexecute()
+void ManipulationCommand::undo()
 {
   if (!isValid()) return;
 
--- trunk/extragear/base/konq-plugins/domtreeviewer/domtreecommands.h \
#1199476:1199477 @@ -26,7 +26,7 @@
 #include <dom/dom_string.h>
 #include <dom/dom_text.h>
 
-#include <k3command.h>
+#include <QUndoCommand>
 
 #include <qlist.h>
 #include <qobject.h>
@@ -52,14 +52,9 @@
   virtual ~ManipulationCommandSignalEmitter();
 
 // public signals:
-#ifndef Q_MOC_RUN
-#undef signals
-#define signals public
-#endif
 signals:
-#ifndef Q_MOC_RUN
-#undef signals
-#define signals protected
+#if !defined(Q_MOC_RUN) && !defined(DOXYGEN_SHOULD_SKIP_THIS) && \
!defined(IN_IDE_PARSER) +public:
 #endif
   /** emitted if the DOM structure has been changed */
   void structureChanged();
@@ -76,7 +71,7 @@
  * Base class of all dom tree manipulation commands.
  * @author Leo Savernik
  */
-class ManipulationCommand : public K3Command
+class ManipulationCommand : public QUndoCommand
 {
 public:
   ManipulationCommand();
@@ -95,9 +90,9 @@
   static void connect(const char *signal, QObject *recv, const char *slot);
 
   /** does grunt work and calls apply()/reapply() */
-  virtual void execute();
+  virtual void redo();
   /** does grunt work and calls unapply() */
-  virtual void unexecute();
+  virtual void undo();
 
 protected:
   virtual void apply() = 0;
--- trunk/extragear/base/konq-plugins/domtreeviewer/domtreeview.cpp #1199476:1199477
@@ -257,7 +257,7 @@
   }
 
   //kDebug(90180) << node.nodeName().string() << " [" << depth << "]";
-  addElement (node, cur_item, false);
+  cur_item = addElement (node, cur_item, false);
   m_listView->setItemExpanded(cur_item, depth < m_expansionDepth);
 
   if(node.handle()) {
@@ -290,13 +290,13 @@
 	cur_item = new DOMListViewItem(node, parent_item, cur_item);
       }
       //kDebug(90180) << "</" << node.nodeName().string() << ">";
-      addElement(element, cur_item, true);
+      cur_item = addElement(element, cur_item, true);
 //       m_listView->setItemExpanded(cur_item, depth < m_expansionDepth);
     }
   }
 }
 
-void DOMTreeView::addElement ( const DOM::Node &node,  DOMListViewItem *cur_item, \
bool isLast) +DOMListViewItem* DOMTreeView::addElement( const DOM::Node &node,  \
DOMListViewItem *cur_item, bool isLast)  {
   assert(cur_item);
   cur_item->setClosing(isLast);
@@ -371,6 +371,7 @@
   if (cur_item && m_bHighlightHTML && node.ownerDocument().isHTMLDocument()) {
     highlightHTML(cur_item, nodeName);
   }
+  return cur_item;
 }
 
 void DOMTreeView::highlightHTML(DOMListViewItem *cur_item, const QString &nodeName)
--- trunk/extragear/base/konq-plugins/domtreeviewer/domtreeview.h #1199476:1199477
@@ -140,7 +140,7 @@
 	void highlightHTML(DOMListViewItem *cur_item,
 			   const QString &nodeName);
 
-	void addElement(const DOM::Node &node, DOMListViewItem *cur_item,
+	DOMListViewItem* addElement(const DOM::Node &node, DOMListViewItem *cur_item,
 			bool isLast);
         void updateIncrDecreaseButton();
 
--- trunk/extragear/base/konq-plugins/domtreeviewer/domtreewindow.cpp \
#1199476:1199477 @@ -25,7 +25,7 @@
 #include "ui_messagedialog.h"
 
 
-#include <k3command.h>
+#include <kundostack.h>
 #include <kconfig.h>
 #include <khtml_part.h>
 #include <klocale.h>
@@ -135,9 +135,11 @@
 
 void DOMTreeWindow::executeAndAddCommand(ManipulationCommand *cmd)
 {
-    cmd->execute();
-    if (cmd->isValid()) {
-      m_commandHistory->addCommand(cmd, false);
+    m_commandHistory->push(cmd); // calls cmd->redo()
+    if (!cmd->isValid()) {
+        cmd->undo();
+        // TODO: ideally, remove the command from m_commandHistory, but I don't see \
how to do that. +    } else {
       view()->hideMessageLine();
     }
 }
@@ -150,8 +152,14 @@
     KStandardAction::copy(this, SLOT(slotCopy()), \
                actionCollection())->setEnabled(false);
     KStandardAction::paste(this, SLOT(slotPaste()), \
actionCollection())->setEnabled(false);  
-    m_commandHistory = new K3CommandHistory(actionCollection());
+    m_commandHistory = new KUndoStack;
 
+    QAction* undoAction = m_commandHistory->createUndoAction(actionCollection());
+    connect(undoAction, SIGNAL(triggered()), m_commandHistory, SLOT(undo()));
+    QAction* redoAction = m_commandHistory->createRedoAction(actionCollection());
+    connect(redoAction, SIGNAL(triggered()), m_commandHistory, SLOT(redo()));
+
+
     KStandardAction::find(this, SLOT(slotFind()), actionCollection());
 
     KStandardAction::redisplay(m_view, SLOT(refresh()), actionCollection());
--- trunk/extragear/base/konq-plugins/domtreeviewer/domtreewindow.h #1199476:1199477
@@ -40,7 +40,7 @@
 
 class QAction;
 class KConfig;
-class K3CommandHistory;
+class KUndoStack;
 class KHTMLPart;
 class MessageDialog;
 
@@ -75,7 +75,7 @@
     /**
      * returns the command history
      */
-    K3CommandHistory *commandHistory() const { return m_commandHistory; }
+    KUndoStack *commandHistory() const { return m_commandHistory; }
 
     /**
      * creates and returns the context menu for the list info panel
@@ -176,7 +176,7 @@
     DOMTreeView *m_view;
     MessageDialog *msgdlg;
 
-    K3CommandHistory *m_commandHistory;
+    KUndoStack *m_commandHistory;
     QMenu *infopanel_ctx;
     QMenu *domtree_ctx;
     KConfig *_config;


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

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