Skip to content

Commit

Permalink
Initial implementation of composer undo / redo
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14786 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 29, 2010
1 parent 8529eec commit a0a21f5
Show file tree
Hide file tree
Showing 40 changed files with 963 additions and 100 deletions.
4 changes: 2 additions & 2 deletions python/gui/qgscomposerview.sip
Expand Up @@ -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*/
Expand Down
15 changes: 10 additions & 5 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -1330,6 +1330,11 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
mComposition->sortZList();
mView->setComposition( mComposition );

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

setSelectionTool();
}

Expand Down Expand Up @@ -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() );
}
Expand Down
5 changes: 4 additions & 1 deletion src/app/composer/qgscomposer.h
Expand Up @@ -42,6 +42,7 @@ class QMoveEvent;
class QResizeEvent;
class QFile;
class QSizeGrip;
class QUndoView;

/** \ingroup MapComposer
* \brief A gui for composing a printable map.
Expand Down Expand Up @@ -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*/
Expand Down Expand Up @@ -306,6 +307,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

//! Page & Printer Setup
QPrinter mPrinter;

QUndoView* mUndoView;
};

#endif
29 changes: 27 additions & 2 deletions src/app/composer/qgscomposerarrowwidget.cpp
Expand Up @@ -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()
Expand All @@ -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 )
Expand All @@ -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()
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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() )
{
Expand All @@ -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() )
{
Expand All @@ -198,6 +218,7 @@ void QgsComposerArrowWidget::on_mEndMarkerLineEdit_textChanged( const QString &
mArrow->setEndMarker( "" );
}
mArrow->update();
mArrow->endCommand();
}
}

Expand All @@ -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();
}
}

Expand All @@ -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();
}
}
8 changes: 5 additions & 3 deletions src/app/composer/qgscomposerarrowwidget.h
Expand Up @@ -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*/
Expand All @@ -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
20 changes: 19 additions & 1 deletion src/app/composer/qgscomposeritemwidget.cpp
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -83,6 +86,7 @@ void QgsComposerItemWidget::on_mBackgroundColorButton_clicked()
cm->cache();
}
mItem->update();
mItem->endCommand();
}

void QgsComposerItemWidget::on_mOpacitySlider_sliderReleased()
Expand All @@ -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 )
Expand All @@ -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 )
Expand All @@ -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 );
Expand All @@ -128,6 +137,7 @@ void QgsComposerItemWidget::on_mFrameCheckBox_stateChanged( int state )
mItem->setFrame( false );
}
mItem->update();
mItem->endCommand();
}

void QgsComposerItemWidget::setValuesForGuiElements()
Expand Down Expand Up @@ -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 a0a21f5

Please sign in to comment.