Skip to content

Commit

Permalink
Show commit errors in transaction mode
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 18, 2016
1 parent 70ae301 commit e0fc641
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
9 changes: 8 additions & 1 deletion python/core/qgsproject.sip
Expand Up @@ -467,8 +467,15 @@ class QgsProject : QObject
*/
void variablesChanged();

public slots:
/**
* Emitted whenever a new transaction group has been created or a
* transaction group has been removed.
*
* @note Added in QGIS 3.0
*/
void transactionGroupsChanged();

public slots:
/**
* Flag the project as dirty (modified). If this flag is set, the user will
* be asked to save changes to the project before closing the current project.
Expand Down
10 changes: 10 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -2773,6 +2773,8 @@ void QgisApp::setupConnections()
connect( this, SIGNAL( projectRead() ),
this, SLOT( fileOpenedOKAfterLaunch() ) );

connect( QgsProject::instance(), &QgsProject::transactionGroupsChanged, this, &QgisApp::onTransactionGroupsChanged );

// connect preview modes actions
connect( mActionPreviewModeOff, SIGNAL( triggered() ), this, SLOT( disablePreviewMode() ) );
connect( mActionPreviewModeGrayscale, SIGNAL( triggered() ), this, SLOT( activateGrayscalePreview() ) );
Expand Down Expand Up @@ -11201,6 +11203,14 @@ void QgisApp::keyPressEvent( QKeyEvent * e )
}
}

void QgisApp::onTransactionGroupsChanged()
{
Q_FOREACH ( QgsTransactionGroup* tg, QgsProject::instance()->transactionGroups().values() )
{
connect( tg, SIGNAL( commitError( QString ) ), this, SLOT( displayMessage( QString, QString, QgsMessageBar::MessageLevel ) ), Qt::UniqueConnection );
}
}

void QgisApp::startProfile( const QString& name )
{
mProfiler->start( name );
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -726,6 +726,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
#endif

private slots:
void onTransactionGroupsChanged();

//! validate a SRS
void validateCrs( QgsCoordinateReferenceSystem &crs );

Expand Down
12 changes: 10 additions & 2 deletions src/core/qgsproject.cpp
Expand Up @@ -995,6 +995,8 @@ void QgsProject::onMapLayersAdded( const QList<QgsMapLayer*>& layers )
{
QMap<QString, QgsMapLayer*> existingMaps = QgsMapLayerRegistry::instance()->mapLayers();

bool tgChanged = false;

Q_FOREACH ( QgsMapLayer* layer, layers )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( layer );
Expand All @@ -1013,15 +1015,17 @@ void QgsProject::onMapLayersAdded( const QList<QgsMapLayer*>& layers )
{
tg = new QgsTransactionGroup();
mTransactionGroups.insert( qMakePair( key, connString ), tg );

connect( tg, SIGNAL( commitError( QString ) ), this, SLOT( displayMapToolMessage( QString ) ) );
tgChanged = true;
}
tg->addLayer( vlayer );
}
}
vlayer->dataProvider()->setProviderProperty( QgsVectorDataProvider::EvaluateDefaultValues, evaluateDefaultValues() );
}

if ( tgChanged )
emit transactionGroupsChanged();

connect( layer, SIGNAL( configChanged() ), this, SLOT( setDirty() ) );

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

void QgsProject::cleanTransactionGroups( bool force )
{
bool changed = false;
for ( QMap< QPair< QString, QString>, QgsTransactionGroup*>::Iterator tg = mTransactionGroups.begin(); tg != mTransactionGroups.end(); )
{
if ( tg.value()->isEmpty() || force )
{
delete tg.value();
tg = mTransactionGroups.erase( tg );
changed = true;
}
else
{
++tg;
}
}
if ( changed )
emit transactionGroupsChanged();
}

bool QgsProject::read( QDomNode &layerNode )
Expand Down
17 changes: 13 additions & 4 deletions src/core/qgsproject.h
Expand Up @@ -513,9 +513,11 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
//! emitted when an old project file is read.
void oldProjectVersionWarning( const QString& );

//! emitted when a layer from a projects was read
// @param i current layer
// @param n number of layers
/**
* Emitted when a layer from a projects was read.
* @param i current layer
* @param n number of layers
*/
void layerLoaded( int i, int n );

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

public slots:
/**
* Emitted whenever a new transaction group has been created or a
* transaction group has been removed.
*
* @note Added in QGIS 3.0
*/
void transactionGroupsChanged();

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

0 comments on commit e0fc641

Please sign in to comment.