Skip to content
Permalink
Browse files

Initial implementation of composer undo / redo

git-svn-id: http://svn.osgeo.org/qgis/trunk@14786 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Nov 29, 2010
1 parent f404e0f commit 2fe5d1d6047a89ea7218d0ad29879be27bc0ffe3
Showing with 963 additions and 100 deletions.
  1. +2 −2 python/gui/qgscomposerview.sip
  2. +10 −5 src/app/composer/qgscomposer.cpp
  3. +4 −1 src/app/composer/qgscomposer.h
  4. +27 −2 src/app/composer/qgscomposerarrowwidget.cpp
  5. +5 −3 src/app/composer/qgscomposerarrowwidget.h
  6. +19 −1 src/app/composer/qgscomposeritemwidget.cpp
  7. +48 −8 src/app/composer/qgscomposerlabelwidget.cpp
  8. +5 −0 src/app/composer/qgscomposerlabelwidget.h
  9. +69 −18 src/app/composer/qgscomposerlegendwidget.cpp
  10. +5 −2 src/app/composer/qgscomposerlegendwidget.h
  11. +48 −2 src/app/composer/qgscomposermapwidget.cpp
  12. +4 −2 src/app/composer/qgscomposermapwidget.h
  13. +18 −1 src/app/composer/qgscomposerpicturewidget.cpp
  14. +1 −0 src/app/composer/qgscomposerpicturewidget.h
  15. +26 −2 src/app/composer/qgscomposerscalebarwidget.cpp
  16. +17 −0 src/app/composer/qgscomposershapewidget.cpp
  17. +3 −2 src/app/composer/qgscomposershapewidget.h
  18. +24 −0 src/app/composer/qgscomposertablewidget.cpp
  19. +3 −2 src/app/composer/qgscomposertablewidget.h
  20. +3 −0 src/core/CMakeLists.txt
  21. +74 −0 src/core/composer/qgsaddremoveitemcommand.cpp
  22. +58 −0 src/core/composer/qgsaddremoveitemcommand.h
  23. +1 −0 src/core/composer/qgscomposerarrow.cpp
  24. +3 −1 src/core/composer/qgscomposerattributetable.cpp
  25. +26 −0 src/core/composer/qgscomposeritem.cpp
  26. +10 −0 src/core/composer/qgscomposeritem.h
  27. +98 −0 src/core/composer/qgscomposeritemcommand.cpp
  28. +121 −0 src/core/composer/qgscomposeritemcommand.h
  29. +0 −1 src/core/composer/qgscomposeritemgroup.cpp
  30. +1 −0 src/core/composer/qgscomposerlabel.cpp
  31. +1 −0 src/core/composer/qgscomposerlegend.cpp
  32. +5 −0 src/core/composer/qgscomposermap.cpp
  33. +3 −4 src/core/composer/qgscomposermap.h
  34. +3 −2 src/core/composer/qgscomposerpicture.cpp
  35. +0 −4 src/core/composer/qgscomposerpicture.h
  36. +1 −0 src/core/composer/qgscomposershape.cpp
  37. +86 −24 src/core/composer/qgscomposition.cpp
  38. +21 −0 src/core/composer/qgscomposition.h
  39. +100 −9 src/gui/qgscomposerview.cpp
  40. +10 −2 src/gui/qgscomposerview.h
@@ -80,8 +80,8 @@ class QgsComposerView: QGraphicsView


public slots:
/**For QgsComposerItemGroup to send its signals to QgsComposer (or other classes that keep track of input widgets)*/
void sendItemRemovedSignal( QgsComposerItem* item );
/**Casts object to the proper subclass type and calls corresponding itemAdded signal*/
void sendItemAddedSignal( QgsComposerItem* item );

signals:
/**Is emitted when selected item changed. If 0, no item is selected*/
@@ -65,13 +65,13 @@
#include <QSvgGenerator>
#include <QToolBar>
#include <QToolButton>
//#include <QUndoView>
#include <QUndoView>





QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(), mTitle( title )
QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(), mTitle( title ), mUndoView( 0 )
{
setupUi( this );
setWindowTitle( mTitle );
@@ -217,8 +217,8 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
mCompositionNameComboBox->insertItem( 0, tr( "Map 1" ) );

//undo widget
/*QUndoView* undoWidget = new QUndoView( mComposition->undoStack(), this );
mOptionsTabWidget->addTab( undoWidget, tr( "Command history" ) );*/
mUndoView = new QUndoView( mComposition->undoStack(), this );
mOptionsTabWidget->addTab( mUndoView, tr( "Command history" ) );

// Create size grip (needed by Mac OS X for QMainWindow if QStatusBar is not visible)
mSizeGrip = new QSizeGrip( this );
@@ -1330,6 +1330,11 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
mComposition->sortZList();
mView->setComposition( mComposition );

if ( mUndoView )
{
mUndoView->setStack( mComposition->undoStack() );
}

setSelectionTool();
}

@@ -1446,7 +1451,7 @@ void QgsComposer::deleteItem( QgsComposerItem* item )
return;
}

delete( it.key() );
//the item itself is not deleted here (usually, this is done in the destructor of QgsAddRemoveItemCommand)
delete( it.value() );
mItemWidgetMap.remove( it.key() );
}
@@ -42,6 +42,7 @@ class QMoveEvent;
class QResizeEvent;
class QFile;
class QSizeGrip;
class QUndoView;

/** \ingroup MapComposer
* \brief A gui for composing a printable map.
@@ -229,7 +230,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
/**Adds a composer table to the item/widget map and creates a configuration widget*/
void addComposerTable( QgsComposerAttributeTable* table );

/**Removes item from the item/widget map and deletes the configuration widget*/
/**Removes item from the item/widget map and deletes the configuration widget. Does not delete the item itself*/
void deleteItem( QgsComposerItem* item );

/**Shows the configuration widget for a composer item*/
@@ -306,6 +307,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

//! Page & Printer Setup
QPrinter mPrinter;

QUndoView* mUndoView;
};

#endif
@@ -39,6 +39,11 @@ QgsComposerArrowWidget::QgsComposerArrowWidget( QgsComposerArrow* arrow ): QWidg
toolBox->addItem( itemPropertiesWidget, tr( "General options" ) );

setGuiElementValues();

if ( arrow )
{
connect( arrow, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
}
}

QgsComposerArrowWidget::~QgsComposerArrowWidget()
@@ -53,8 +58,10 @@ void QgsComposerArrowWidget::on_mOutlineWidthSpinBox_valueChanged( double d )
return;
}

mArrow->beginCommand( tr( "Arrow outline width" ), QgsComposerMergeCommand::ArrowOutlineWidth );
mArrow->setOutlineWidth( d );
mArrow->update();
mArrow->endCommand();
}

void QgsComposerArrowWidget::on_mArrowHeadWidthSpinBox_valueChanged( double d )
@@ -64,8 +71,10 @@ void QgsComposerArrowWidget::on_mArrowHeadWidthSpinBox_valueChanged( double d )
return;
}

mArrow->beginCommand( tr( "Arrowhead width" ), QgsComposerMergeCommand::ArrowHeadWidth );
mArrow->setArrowHeadWidth( d );
mArrow->update();
mArrow->endCommand();
}

void QgsComposerArrowWidget::on_mArrowColorButton_clicked()
@@ -82,8 +91,10 @@ void QgsComposerArrowWidget::on_mArrowColorButton_clicked()
#endif
if ( newColor.isValid() )
{
mArrow->beginCommand( tr( "Arrow color changed" ) );
mArrow->setArrowColor( newColor );
mArrow->update();
mArrow->endCommand();
}
}

@@ -143,17 +154,21 @@ void QgsComposerArrowWidget::on_mDefaultMarkerRadioButton_toggled( bool toggled
{
if ( mArrow && toggled )
{
mArrow->beginCommand( tr( "Arrow marker changed" ) );
mArrow->setMarkerMode( QgsComposerArrow::DefaultMarker );
mArrow->update();
mArrow->endCommand();
}
}

void QgsComposerArrowWidget::on_mNoMarkerRadioButton_toggled( bool toggled )
{
if ( mArrow && toggled )
{
mArrow->beginCommand( tr( "Arrow marker changed" ) );
mArrow->setMarkerMode( QgsComposerArrow::NoMarker );
mArrow->update();
mArrow->endCommand();
}
}

@@ -162,15 +177,18 @@ void QgsComposerArrowWidget::on_mSvgMarkerRadioButton_toggled( bool toggled )
enableSvgInputElements( toggled );
if ( mArrow && toggled )
{
mArrow->beginCommand( tr( "Arrow marker changed" ) );
mArrow->setMarkerMode( QgsComposerArrow::SVGMarker );
mArrow->update();
mArrow->endCommand();
}
}

void QgsComposerArrowWidget::on_mStartMarkerLineEdit_textChanged( const QString & text )
void QgsComposerArrowWidget::on_mStartMarkerLineEdit_editingFinished( const QString & text )
{
if ( mArrow )
{
mArrow->beginCommand( tr( "Arrow start marker" ) );
QFileInfo fi( text );
if ( fi.exists() )
{
@@ -181,13 +199,15 @@ void QgsComposerArrowWidget::on_mStartMarkerLineEdit_textChanged( const QString
mArrow->setStartMarker( "" );
}
mArrow->update();
mArrow->endCommand();
}
}

void QgsComposerArrowWidget::on_mEndMarkerLineEdit_textChanged( const QString & text )
void QgsComposerArrowWidget::on_mEndMarkerLineEdit_editingFinished( const QString & text )
{
if ( mArrow )
{
mArrow->beginCommand( tr( "Arrow start marker" ) );
QFileInfo fi( text );
if ( fi.exists() )
{
@@ -198,6 +218,7 @@ void QgsComposerArrowWidget::on_mEndMarkerLineEdit_textChanged( const QString &
mArrow->setEndMarker( "" );
}
mArrow->update();
mArrow->endCommand();
}
}

@@ -207,7 +228,9 @@ void QgsComposerArrowWidget::on_mStartMarkerToolButton_clicked()
QString svgFileName = QFileDialog::getOpenFileName( 0, tr( "Start marker svg file" ), fi.dir().absolutePath() );
if ( !svgFileName.isNull() )
{
mArrow->beginCommand( tr( "Arrow start marker" ) );
mStartMarkerLineEdit->setText( svgFileName );
mArrow->endCommand();
}
}

@@ -217,6 +240,8 @@ void QgsComposerArrowWidget::on_mEndMarkerToolButton_clicked()
QString svgFileName = QFileDialog::getOpenFileName( 0, tr( "End marker svg file" ), fi.dir().absolutePath() );
if ( !svgFileName.isNull() )
{
mArrow->beginCommand( tr( "Arrow end marker" ) );
mEndMarkerLineEdit ->setText( svgFileName );
mArrow->endCommand();
}
}
@@ -33,7 +33,7 @@ class QgsComposerArrowWidget: public QWidget, private Ui::QgsComposerArrowWidget
QgsComposerArrow* mArrow;

void blockAllSignals( bool block );
void setGuiElementValues();

QButtonGroup* mRadioButtonGroup;

/**Enables / disables the SVG line inputs*/
@@ -46,10 +46,12 @@ class QgsComposerArrowWidget: public QWidget, private Ui::QgsComposerArrowWidget
void on_mDefaultMarkerRadioButton_toggled( bool toggled );
void on_mNoMarkerRadioButton_toggled( bool toggled );
void on_mSvgMarkerRadioButton_toggled( bool toggled );
void on_mStartMarkerLineEdit_textChanged( const QString & text );
void on_mEndMarkerLineEdit_textChanged( const QString & text );
void on_mStartMarkerLineEdit_editingFinished( const QString & text );
void on_mEndMarkerLineEdit_editingFinished( const QString & text );
void on_mStartMarkerToolButton_clicked();
void on_mEndMarkerToolButton_clicked();

void setGuiElementValues();
};

#endif // QGSCOMPOSERARROWWIDGET_H
@@ -52,12 +52,14 @@ void QgsComposerItemWidget::on_mFrameColorButton_clicked()
return; //dialog canceled
}

mItem->beginCommand( tr( "Frame color changed" ) );
QPen thePen;
thePen.setColor( newFrameColor );
thePen.setWidthF( mOutlineWidthSpinBox->value() );

mItem->setPen( thePen );
mItem->update();
mItem->endCommand();
}

void QgsComposerItemWidget::on_mBackgroundColorButton_clicked()
@@ -73,6 +75,7 @@ void QgsComposerItemWidget::on_mBackgroundColorButton_clicked()
return; //dialog canceled
}

mItem->beginCommand( tr( "Background color changed" ) );
newBackgroundColor.setAlpha( mOpacitySlider->value() );
mItem->setBrush( QBrush( QColor( newBackgroundColor ), Qt::SolidPattern ) );
//if the item is a composer map, we need to regenerate the map image
@@ -83,6 +86,7 @@ void QgsComposerItemWidget::on_mBackgroundColorButton_clicked()
cm->cache();
}
mItem->update();
mItem->endCommand();
}

void QgsComposerItemWidget::on_mOpacitySlider_sliderReleased()
@@ -93,11 +97,13 @@ void QgsComposerItemWidget::on_mOpacitySlider_sliderReleased()
}
int value = mOpacitySlider->value();

mItem->beginCommand( tr( "Item opacity changed" ) );
QBrush itemBrush = mItem->brush();
QColor brushColor = itemBrush.color();
brushColor.setAlpha( value );
mItem->setBrush( QBrush( brushColor ) );
mItem->update();
mItem->endCommand();
}

void QgsComposerItemWidget::on_mOutlineWidthSpinBox_valueChanged( double d )
@@ -107,9 +113,11 @@ void QgsComposerItemWidget::on_mOutlineWidthSpinBox_valueChanged( double d )
return;
}

mItem->beginCommand( tr( "Item outline width" ), QgsComposerMergeCommand::ItemOutlineWidth );
QPen itemPen = mItem->pen();
itemPen.setWidthF( d );
mItem->setPen( itemPen );
mItem->endCommand();
}

void QgsComposerItemWidget::on_mFrameCheckBox_stateChanged( int state )
@@ -119,6 +127,7 @@ void QgsComposerItemWidget::on_mFrameCheckBox_stateChanged( int state )
return;
}

mItem->beginCommand( tr( "Item frame toggled" ) );
if ( state == Qt::Checked )
{
mItem->setFrame( true );
@@ -128,6 +137,7 @@ void QgsComposerItemWidget::on_mFrameCheckBox_stateChanged( int state )
mItem->setFrame( false );
}
mItem->update();
mItem->endCommand();
}

void QgsComposerItemWidget::setValuesForGuiElements()
@@ -165,6 +175,14 @@ void QgsComposerItemWidget::on_mPositionButton_clicked()
return;
}

mItem->beginCommand( tr( "Item position changed" ) );
QgsItemPositionDialog d( mItem, 0 );
d.exec();
if ( d.exec() == QDialog::Accepted )
{
mItem->endCommand();
}
else
{
mItem->cancelCommand();
}
}

0 comments on commit 2fe5d1d

Please sign in to comment.
You can’t perform that action at this time.