[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/kivio/kiviopart
From: Peter Simonsson <psn () linux ! se>
Date: 2006-01-22 17:43:04
Message-ID: 1137951784.803485.27705.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 501356 by psn:
Fix undo for group and ungroup
M +42 -0 kivio_command.cc
M +28 -0 kivio_command.h
M +22 -72 kivio_page.cpp
--- trunk/koffice/kivio/kiviopart/kivio_command.cc #501355:501356
@@ -23,6 +23,7 @@
#include "kivio_map.h"
#include "kivio_doc.h"
#include "kivio_layer.h"
+#include "kivio_group_stencil.h"
KivioChangePageNameCommand::KivioChangePageNameCommand(const QString &_name, const \
QString & _oldPageName, const QString & _newPageName, KivioPage *_page) : \
KNamedCommand( _name ), @@ -740,6 +741,7 @@
m_page->doc()->updateView(m_page);
}
+
KivioCustomDragCommand::KivioCustomDragCommand(const QString& name, KivioPage* page, \
KivioStencil* stencil,
int customID, const KoPoint& \
originalPoint, const KoPoint& newPoint) : KNamedCommand(name)
@@ -762,3 +764,43 @@
m_stencil->setCustomIDPoint(m_customID, m_originalPoint, m_page);
m_page->doc()->updateView(m_page);
}
+
+
+KivioGroupCommand::KivioGroupCommand(const QString& name, KivioPage* page, \
KivioLayer* layer, + KivioGroupStencil* group)
+ : KNamedCommand(name)
+{
+ m_page = page;
+ m_layer = layer;
+ m_groupStencil = group;
+}
+
+void KivioGroupCommand::execute()
+{
+ QPtrList<KivioStencil>* list = m_groupStencil->groupList();
+ QPtrListIterator<KivioStencil> it(*list);
+ KivioStencil* stencil = 0;
+
+ for(; (stencil = it.current()) != 0; ++it) {
+ m_layer->takeStencil(stencil);
+ }
+
+ m_groupStencil->unselect();
+ m_layer->addStencil(m_groupStencil);
+ m_page->doc()->updateView(m_page);
+}
+
+void KivioGroupCommand::unexecute()
+{
+ QPtrList<KivioStencil>* list = m_groupStencil->groupList();
+ QPtrListIterator<KivioStencil> it(*list);
+ KivioStencil* stencil = 0;
+
+ for(; (stencil = it.current()) != 0; ++it) {
+ stencil->unselect();
+ m_layer->addStencil(stencil);
+ }
+
+ m_layer->takeStencil(m_groupStencil);
+ m_page->doc()->updateView(m_page);
+}
--- trunk/koffice/kivio/kiviopart/kivio_command.h #501355:501356
@@ -23,12 +23,14 @@
#include <kcommand.h>
#include <qfont.h>
#include <qcolor.h>
+#include <qvaluelist.h>
#include <KoRect.h>
#include <koPageLayout.h>
#include <koffice_export.h>
class KivioPage;
class KivioLayer;
class KivioStencil;
+class KivioGroupStencil;
struct KoPageLayout;
class KivioChangePageNameCommand : public KNamedCommand
@@ -441,5 +443,31 @@
KoPoint m_newPoint;
};
+class KivioGroupCommand : public KNamedCommand
+{
+ public:
+ KivioGroupCommand(const QString& name, KivioPage* page, KivioLayer* layer, \
KivioGroupStencil* group); +
+ virtual void execute();
+ virtual void unexecute();
+
+ protected:
+ KivioPage* m_page;
+ KivioLayer* m_layer;
+
+ KivioGroupStencil* m_groupStencil;
+};
+
+class KivioUnGroupCommand : public KivioGroupCommand
+{
+ public:
+ KivioUnGroupCommand(const QString& name, KivioPage* page, KivioLayer* layer, \
KivioGroupStencil* group) + : KivioGroupCommand(name, page, layer, group)
+ {}
+
+ virtual void execute() { KivioGroupCommand::unexecute(); }
+ virtual void unexecute() { KivioGroupCommand::execute(); }
+};
+
#endif
--- trunk/koffice/kivio/kiviopart/kivio_page.cpp #501355:501356
@@ -761,57 +761,18 @@
m_pCurLayer->addStencil(pGroup);
selectStencil(pGroup);
-}
-// The following is the old implementation of groupSelectedStencils. It did
-// not preserve connections so a new method was devised.
-/*
-void KivioPage::groupSelectedStencils()
-{
- KivioGroupStencil *pGroup;
- KivioStencil *pTake;
- KivioStencil *pStencil;
-
-
- debug("*GROUP* About to group");
- // Can't group 0 or 1 stencils
- if( m_lstSelection.count() <= 1 )
- return;
-
- pGroup = new KivioGroupStencil();
-
- // Iterate through all items in the selection list, duplicating them, then \
adding
- // them to the group
-
- pStencil = m_lstSelection.first();
- while( pStencil )
- {
-
- debug("*GROUP* Duplicating 1");
-
- // Dup the stencil & group it
- pTake = pStencil->duplicate();
-
- pGroup->addToGroup( pDuplicate );
-
- pStencil = m_lstSelection.next();
- }
-
- // Kill the old selections
- deleteSelectedStencils();
-
-
- // Add the group as the selected stencil
- m_pCurLayer->addStencil( pGroup );
-
- selectStencil( pGroup );
+ KivioGroupCommand* cmd = new KivioGroupCommand(i18n("Group Selection"), this, \
m_pCurLayer, pGroup); + doc()->addCommand(cmd);
}
-*/
+
void KivioPage::ungroupSelectedStencils()
{
KivioStencil *pSelStencil, *pStencil;
QPtrList<KivioStencil> *pList;
QPtrList<KivioStencil> *pSelectThese = new QPtrList<KivioStencil>;
+ KMacroCommand* macro = new KMacroCommand(i18n("Ungroup"));
+ bool ungrouped = false;
pSelectThese->setAutoDelete(false);
@@ -821,50 +782,35 @@
{
// If there is a list, it is a group stencil
pList = pSelStencil->groupList();
- if( pList )
+ if(pList)
{
pList->first();
- pStencil = pList->take();
+ pStencil = pList->first();
while( pStencil )
{
- addStencil( pStencil );
+ m_pCurLayer->addStencil( pStencil );
pSelectThese->append( pStencil );
- pStencil = pList->take();
+ pStencil = pList->next();
}
- /*
- * The following is commented out because the group should be on the
- * current layer since selections must be on the current layer.
- */
- // Since this was a group, it is now an empty stencil, so we remove it
- // from the selection list, and then remove it from the layer it came
- // from, but we have to search for that.
- /*
- pSelStencil = m_lstSelection.take();
- KivioLayer *pLayer = m_lstLayers.first();
- while( pLayer )
- {
- if( pLayer->removeStencil( pSelStencil )==true )
- break;
-
- pLayer = m_lstLayers.next();
- }
- */
-
// Remove the current stencil from the selection list(the group we just \
disassembled) m_lstSelection.take();
// Remove it permanently from the layer
- if( m_pCurLayer->removeStencil( pSelStencil )==false )
+ if(!m_pCurLayer->takeStencil(pSelStencil))
{
kdDebug(43000) << "KivioPage::ungroupSelectedStencil() - Failed to locate \
the group shell for deletion" << endl;
}
+
+ KivioUnGroupCommand* cmd = new KivioUnGroupCommand(i18n("Ungroup"), this, \
m_pCurLayer, + static_cast<KivioGroupStencil*>(pSelStencil));
+ macro->addCommand(cmd);
+ ungrouped = true;
}
-
pSelStencil = m_lstSelection.next();
}
@@ -878,13 +824,17 @@
if(pStencil->type() == kstConnector) {
pStencil->searchForConnections(this, 4.0);
}
-
+
pStencil = pSelectThese->next();
}
-
-
delete pSelectThese;
+
+ if(ungrouped) {
+ doc()->addCommand(macro);
+ } else {
+ delete macro;
+ }
}
void KivioPage::bringToFront()
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic