Skip to content

Commit 31f193e

Browse files
committedJul 14, 2013
QGisApp: show commit errors as message bar first
1 parent f298484 commit 31f193e

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4241,6 +4241,40 @@ void QgisApp::labelingFontNotFound( QgsVectorLayer* vlayer, const QString& fontf
42414241
messageBar()->pushWidget( fontMsg, QgsMessageBar::WARNING );
42424242
}
42434243

4244+
void QgisApp::commitError( QgsVectorLayer* vlayer )
4245+
{
4246+
QWidget *errorMsg = QgsMessageBar::createMessage(
4247+
tr( "Commit errors" ),
4248+
tr( "Could not commit changes to layer %1" ).arg( vlayer->name() ),
4249+
QgsApplication::getThemeIcon( "/mIconWarn.png" ),
4250+
messageBar() );
4251+
4252+
QgsMessageViewer *mv = new QgsMessageViewer( errorMsg );
4253+
mv->setWindowTitle( tr( "Commit errors" ) );
4254+
mv->setMessageAsPlainText( tr( "Could not commit changes to layer %1" ).arg( vlayer->name() )
4255+
+ "\n\n"
4256+
+ tr( "Errors: %1\n" ).arg( vlayer->commitErrors().join( "\n " ) )
4257+
);
4258+
4259+
// store pointer to vlayer in data of QAction
4260+
QAction *act = new QAction( errorMsg );
4261+
act->setData( QVariant( QMetaType::QObjectStar, &vlayer ) );
4262+
act->setText( tr( "Show more" ) );
4263+
4264+
QToolButton *showMore = new QToolButton( errorMsg );
4265+
showMore->setStyleSheet( "background-color: rgba(255, 255, 255, 0); color: black; text-decoration: underline;" );
4266+
showMore->setCursor( Qt::PointingHandCursor );
4267+
showMore->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
4268+
showMore->addAction( act );
4269+
showMore->setDefaultAction( act );
4270+
4271+
connect( showMore, SIGNAL( triggered( QAction* ) ), mv, SLOT( exec() ) );
4272+
errorMsg->layout()->addWidget( showMore );
4273+
4274+
// no timeout set, since notice needs attention and is only shown first time layer is labeled
4275+
messageBar()->pushWidget( errorMsg, QgsMessageBar::WARNING );
4276+
}
4277+
42444278
void QgisApp::labelingDialogFontNotFound( QAction* act )
42454279
{
42464280
if ( !act )
@@ -5635,14 +5669,7 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
56355669
case QMessageBox::Save:
56365670
if ( !vlayer->commitChanges() )
56375671
{
5638-
QgsMessageViewer *mv = new QgsMessageViewer( this );
5639-
mv->setWindowTitle( tr( "Error" ) );
5640-
mv->setMessageAsPlainText( tr( "Could not commit changes to layer %1\n\nErrors: %2\n" )
5641-
.arg( vlayer->name() )
5642-
.arg( vlayer->commitErrors().join( "\n " ) )
5643-
);
5644-
mv->exec();
5645-
5672+
commitError( vlayer );
56465673
// Leave the in-memory editing state alone,
56475674
// to give the user a chance to enter different values
56485675
// and try the commit again later
@@ -5707,13 +5734,7 @@ void QgisApp::saveEdits( QgsMapLayer *layer, bool leaveEditable, bool triggerRep
57075734
if ( !vlayer->commitChanges() )
57085735
{
57095736
mSaveRollbackInProgress = false;
5710-
QgsMessageViewer * mv = new QgsMessageViewer( this );
5711-
mv->setWindowTitle( tr( "Error" ) );
5712-
mv->setMessageAsPlainText( tr( "Could not commit changes to layer %1\n\nErrors: %2\n" )
5713-
.arg( vlayer->name() )
5714-
.arg( vlayer->commitErrors().join( "\n " ) )
5715-
);
5716-
mv->exec();
5737+
commitError( vlayer );
57175738
}
57185739

57195740
if ( leaveEditable )
@@ -6243,7 +6264,6 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
62436264
{
62446265
mInfoBar->pushWidget( msgBar, QgsMessageBar::WARNING );
62456266
}
6246-
62476267
}
62486268

62496269
void QgisApp::setLayerCRS()

‎src/app/qgisapp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,11 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
10251025
*/
10261026
void labelingFontNotFound( QgsVectorLayer* vlayer, const QString& fontfamily );
10271027

1028+
/** Alerts user when commit errors occured
1029+
* @note added in 2.0
1030+
*/
1031+
void commitError( QgsVectorLayer* vlayer );
1032+
10281033
/** Opens the labeling dialog for a layer when called from labelingFontNotFound alert
10291034
* @note added in 1.9
10301035
*/

0 commit comments

Comments
 (0)
Please sign in to comment.