Skip to content

Commit e0fc641

Browse files
committedOct 18, 2016
Show commit errors in transaction mode
1 parent 70ae301 commit e0fc641

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed
 

‎python/core/qgsproject.sip‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,15 @@ class QgsProject : QObject
467467
*/
468468
void variablesChanged();
469469

470-
public slots:
470+
/**
471+
* Emitted whenever a new transaction group has been created or a
472+
* transaction group has been removed.
473+
*
474+
* @note Added in QGIS 3.0
475+
*/
476+
void transactionGroupsChanged();
471477

478+
public slots:
472479
/**
473480
* Flag the project as dirty (modified). If this flag is set, the user will
474481
* be asked to save changes to the project before closing the current project.

‎src/app/qgisapp.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,6 +2773,8 @@ void QgisApp::setupConnections()
27732773
connect( this, SIGNAL( projectRead() ),
27742774
this, SLOT( fileOpenedOKAfterLaunch() ) );
27752775

2776+
connect( QgsProject::instance(), &QgsProject::transactionGroupsChanged, this, &QgisApp::onTransactionGroupsChanged );
2777+
27762778
// connect preview modes actions
27772779
connect( mActionPreviewModeOff, SIGNAL( triggered() ), this, SLOT( disablePreviewMode() ) );
27782780
connect( mActionPreviewModeGrayscale, SIGNAL( triggered() ), this, SLOT( activateGrayscalePreview() ) );
@@ -11201,6 +11203,14 @@ void QgisApp::keyPressEvent( QKeyEvent * e )
1120111203
}
1120211204
}
1120311205

11206+
void QgisApp::onTransactionGroupsChanged()
11207+
{
11208+
Q_FOREACH ( QgsTransactionGroup* tg, QgsProject::instance()->transactionGroups().values() )
11209+
{
11210+
connect( tg, SIGNAL( commitError( QString ) ), this, SLOT( displayMessage( QString, QString, QgsMessageBar::MessageLevel ) ), Qt::UniqueConnection );
11211+
}
11212+
}
11213+
1120411214
void QgisApp::startProfile( const QString& name )
1120511215
{
1120611216
mProfiler->start( name );

‎src/app/qgisapp.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
726726
#endif
727727

728728
private slots:
729+
void onTransactionGroupsChanged();
730+
729731
//! validate a SRS
730732
void validateCrs( QgsCoordinateReferenceSystem &crs );
731733

‎src/core/qgsproject.cpp‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,8 @@ void QgsProject::onMapLayersAdded( const QList<QgsMapLayer*>& layers )
995995
{
996996
QMap<QString, QgsMapLayer*> existingMaps = QgsMapLayerRegistry::instance()->mapLayers();
997997

998+
bool tgChanged = false;
999+
9981000
Q_FOREACH ( QgsMapLayer* layer, layers )
9991001
{
10001002
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( layer );
@@ -1013,15 +1015,17 @@ void QgsProject::onMapLayersAdded( const QList<QgsMapLayer*>& layers )
10131015
{
10141016
tg = new QgsTransactionGroup();
10151017
mTransactionGroups.insert( qMakePair( key, connString ), tg );
1016-
1017-
connect( tg, SIGNAL( commitError( QString ) ), this, SLOT( displayMapToolMessage( QString ) ) );
1018+
tgChanged = true;
10181019
}
10191020
tg->addLayer( vlayer );
10201021
}
10211022
}
10221023
vlayer->dataProvider()->setProviderProperty( QgsVectorDataProvider::EvaluateDefaultValues, evaluateDefaultValues() );
10231024
}
10241025

1026+
if ( tgChanged )
1027+
emit transactionGroupsChanged();
1028+
10251029
connect( layer, SIGNAL( configChanged() ), this, SLOT( setDirty() ) );
10261030

10271031
// check if we have to update connections for layers with dependencies
@@ -1039,18 +1043,22 @@ void QgsProject::onMapLayersAdded( const QList<QgsMapLayer*>& layers )
10391043

10401044
void QgsProject::cleanTransactionGroups( bool force )
10411045
{
1046+
bool changed = false;
10421047
for ( QMap< QPair< QString, QString>, QgsTransactionGroup*>::Iterator tg = mTransactionGroups.begin(); tg != mTransactionGroups.end(); )
10431048
{
10441049
if ( tg.value()->isEmpty() || force )
10451050
{
10461051
delete tg.value();
10471052
tg = mTransactionGroups.erase( tg );
1053+
changed = true;
10481054
}
10491055
else
10501056
{
10511057
++tg;
10521058
}
10531059
}
1060+
if ( changed )
1061+
emit transactionGroupsChanged();
10541062
}
10551063

10561064
bool QgsProject::read( QDomNode &layerNode )

‎src/core/qgsproject.h‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,11 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
513513
//! emitted when an old project file is read.
514514
void oldProjectVersionWarning( const QString& );
515515

516-
//! emitted when a layer from a projects was read
517-
// @param i current layer
518-
// @param n number of layers
516+
/**
517+
* Emitted when a layer from a projects was read.
518+
* @param i current layer
519+
* @param n number of layers
520+
*/
519521
void layerLoaded( int i, int n );
520522

521523
void loadingLayer( const QString& );
@@ -536,8 +538,15 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
536538
*/
537539
void variablesChanged();
538540

539-
public slots:
541+
/**
542+
* Emitted whenever a new transaction group has been created or a
543+
* transaction group has been removed.
544+
*
545+
* @note Added in QGIS 3.0
546+
*/
547+
void transactionGroupsChanged();
540548

549+
public slots:
541550
/**
542551
* Flag the project as dirty (modified). If this flag is set, the user will
543552
* be asked to save changes to the project before closing the current project.

0 commit comments

Comments
 (0)
Please sign in to comment.