-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to undo/redo composer grouping/ungrouping
Fixes #11371 (crash on ungrouping after moving the group) and more undo/redo related issues. Enable pending test for the crash (now passing) and add many more undo/redo related ones (including signals testing). Includes a new QgsGroupUngroupItemsCommand class and its SIP bindings.
- Loading branch information
Showing
11 changed files
with
533 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** A composer command class for grouping / ungrouping composer items. | ||
* | ||
* If mState == Ungrouped, the command owns the group item | ||
*/ | ||
class QgsGroupUngroupItemsCommand: QObject, QUndoCommand | ||
{ | ||
%TypeHeaderCode | ||
#include "qgsgroupungroupitemscommand.h" | ||
%End | ||
|
||
public: | ||
|
||
/** Command kind, and state */ | ||
enum State | ||
{ | ||
Grouped = 0, | ||
Ungrouped | ||
}; | ||
|
||
/** Create a group or ungroup command | ||
* | ||
* @param s command kind (@see State) | ||
* @param item the group item being created or ungrouped | ||
* @param c the composition including this group | ||
* @param text command label | ||
* @param parent parent command, if any | ||
* | ||
*/ | ||
QgsGroupUngroupItemsCommand( State s, QgsComposerItemGroup* item, QgsComposition* c, const QString& text, QUndoCommand* parent = nullptr ); | ||
~QgsGroupUngroupItemsCommand(); | ||
|
||
void redo(); | ||
void undo(); | ||
|
||
signals: | ||
/** Signals addition of an item (the group) */ | ||
void itemAdded( QgsComposerItem* item ); | ||
/** Signals removal of an item (the group) */ | ||
void itemRemoved( QgsComposerItem* item ); | ||
|
||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/*************************************************************************** | ||
qgsgroupungroupitemscommand.cpp | ||
--------------------------- | ||
begin : 2016-06-09 | ||
copyright : (C) 2016 by Sandro Santilli | ||
email : strk at kbt dot io | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsgroupungroupitemscommand.h" | ||
#include "qgscomposeritem.h" | ||
#include "qgscomposeritemgroup.h" | ||
#include "qgscomposition.h" | ||
#include "qgsproject.h" | ||
#include "qgscomposermodel.h" | ||
#include "qgslogger.h" | ||
|
||
QgsGroupUngroupItemsCommand::QgsGroupUngroupItemsCommand( State s, QgsComposerItemGroup* item, QgsComposition* c, const QString& text, QUndoCommand* parent ): | ||
QUndoCommand( text, parent ), mGroup( item ), mComposition( c ), mState( s ), mFirstRun( true ) | ||
{ | ||
mItems = mGroup->items(); | ||
} | ||
|
||
QgsGroupUngroupItemsCommand::~QgsGroupUngroupItemsCommand() | ||
{ | ||
if ( mState == Ungrouped ) | ||
{ | ||
//command class stores the item if ungrouped from the composition | ||
delete mGroup; | ||
} | ||
} | ||
|
||
void QgsGroupUngroupItemsCommand::redo() | ||
{ | ||
if ( mFirstRun ) | ||
{ | ||
mFirstRun = false; | ||
return; | ||
} | ||
switchState(); | ||
} | ||
|
||
void QgsGroupUngroupItemsCommand::undo() | ||
{ | ||
if ( mFirstRun ) | ||
{ | ||
mFirstRun = false; | ||
return; | ||
} | ||
switchState(); | ||
} | ||
|
||
void QgsGroupUngroupItemsCommand::switchState() | ||
{ | ||
if ( mState == Grouped ) | ||
{ | ||
// ungroup | ||
if ( mComposition ) | ||
{ | ||
// This is probably redundant | ||
mComposition->itemsModel()->setItemRemoved( mGroup ); | ||
mComposition->removeItem( mGroup ); | ||
} | ||
mGroup->removeItems(); | ||
emit itemRemoved( mGroup ); | ||
mState = Ungrouped; | ||
} | ||
else //Ungrouped | ||
{ | ||
// group | ||
if ( mComposition ) | ||
{ | ||
//delete mGroup; mGroup = new QgsComposerItemGroup( mCompoiser ); | ||
QSet<QgsComposerItem*>::iterator itemIter = mItems.begin(); | ||
for ( ; itemIter != mItems.end(); ++itemIter ) | ||
{ | ||
mGroup->addItem( *itemIter ); | ||
QgsDebugMsg( QString( "itemgroup now has %1" ) .arg( mGroup->items().size() ) ); | ||
} | ||
// Add the group | ||
mComposition->itemsModel()->setItemRestored( mGroup ); | ||
mComposition->addItem( mGroup ); | ||
} | ||
mState = Grouped; | ||
emit itemAdded( mGroup ); | ||
} | ||
QgsProject::instance()->setDirty( true ); | ||
} |
Oops, something went wrong.