Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use a message bar in Style Manager dialog to avoid annoying
success message boxes after performing import actions
  • Loading branch information
nyalldawson committed May 10, 2019
1 parent 85ff9ae commit 2a457f0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/gui/symbology/qgsstylemanagerdialog.cpp
Expand Up @@ -30,6 +30,7 @@
#include "qgssmartgroupeditordialog.h"
#include "qgssettings.h"
#include "qgsstylemodel.h"
#include "qgsmessagebar.h"

#include <QAction>
#include <QFile>
Expand Down Expand Up @@ -154,6 +155,10 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent,
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsStyleManagerDialog::showHelp );
connect( buttonBox, &QDialogButtonBox::rejected, this, &QgsStyleManagerDialog::onClose );

mMessageBar = new QgsMessageBar();
mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
mVerticalLayout->insertWidget( 0, mMessageBar );

#ifdef Q_OS_MAC
setWindowModality( Qt::WindowModal );
#endif
Expand Down Expand Up @@ -484,9 +489,7 @@ void QgsStyleManagerDialog::copyItemsToDefault()
cursorOverride.reset();
if ( count > 0 )
{
QMessageBox::information( this, tr( "Import Items" ),
count > 1 ? tr( "Successfully imported %1 items." ).arg( count )
: tr( "Successfully imported item." ) );
mMessageBar->pushSuccess( tr( "Import Items" ), count > 1 ? tr( "Successfully imported %1 items." ).arg( count ) : tr( "Successfully imported item." ) );
}
}
}
Expand Down Expand Up @@ -1424,8 +1427,7 @@ int QgsStyleManagerDialog::addTag()
int check = mStyle->tagId( itemName );
if ( check > 0 )
{
QMessageBox::critical( this, tr( "Add Tag" ),
tr( "Tag name already exists in your symbol database." ) );
mMessageBar->pushCritical( tr( "Add Tag" ), tr( "The tag “%1” already exists." ).arg( itemName ) );
return 0;
}

Expand All @@ -1437,9 +1439,7 @@ int QgsStyleManagerDialog::addTag()

if ( !id )
{
QMessageBox::critical( this, tr( "Add Tag" ),
tr( "New tag could not be created.\n"
"There was a problem with your symbol database." ) );
mMessageBar->pushCritical( tr( "Add Tag" ), tr( "New tag could not be created — There was a problem with the symbol database." ) );
return 0;
}

Expand Down Expand Up @@ -1498,6 +1498,7 @@ void QgsStyleManagerDialog::removeGroup()
QString data = index.data( Qt::UserRole + 1 ).toString();
if ( data == QLatin1String( "all" ) || data == QLatin1String( "favorite" ) || data == QLatin1String( "tags" ) || index.data() == "smartgroups" )
{
// should never appear -- blocked by GUI
int err = QMessageBox::critical( this, tr( "Remove Group" ),
tr( "Invalid selection. Cannot delete system defined categories.\n"
"Kindly select a group or smart group you might want to delete." ) );
Expand Down Expand Up @@ -1801,6 +1802,7 @@ void QgsStyleManagerDialog::editSmartgroupAction()
QModelIndex present = groupTree->currentIndex();
if ( present.parent().data( Qt::UserRole + 1 ) != "smartgroups" )
{
// should never appear - blocked by GUI logic
QMessageBox::critical( this, tr( "Edit Smart Group" ),
tr( "You have not selected a Smart Group. Kindly select a Smart Group to edit." ) );
return;
Expand All @@ -1822,8 +1824,7 @@ void QgsStyleManagerDialog::editSmartgroupAction()
mBlockGroupUpdates--;
if ( !id )
{
QMessageBox::critical( this, tr( "Edit Smart Group" ),
tr( "There was some error while editing the smart group." ) );
mMessageBar->pushCritical( tr( "Edit Smart Group" ), tr( "There was an error while editing the smart group." ) );
return;
}
item->setText( dlg.smartgroupName() );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology/qgsstylemanagerdialog.h
Expand Up @@ -28,6 +28,7 @@

class QgsStyle;
class QgsTemporaryCursorOverride;
class QgsMessageBar;

#ifndef SIP_RUN
///@cond PRIVATE
Expand Down Expand Up @@ -354,6 +355,7 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan
QWidget *parentWidget, std::unique_ptr<QgsTemporaryCursorOverride> &cursorOverride,
bool isImport, const QStringList &importTags, bool addToFavorites, bool ignoreSourceTags );

QgsMessageBar *mMessageBar = nullptr;

QgsStyle *mStyle = nullptr;

Expand Down
6 changes: 3 additions & 3 deletions src/ui/qgsstylemanagerdialogbase.ui
Expand Up @@ -13,7 +13,7 @@
<property name="windowTitle">
<string>Style Manager</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QVBoxLayout" name="mVerticalLayout">
<property name="leftMargin">
<number>6</number>
</property>
Expand All @@ -26,7 +26,7 @@
<property name="bottomMargin">
<number>6</number>
</property>
<item row="3" column="0">
<item>
<widget class="QSplitter" name="mSplitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand Down Expand Up @@ -445,7 +445,7 @@
</widget>
</widget>
</item>
<item row="4" column="0">
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand Down

0 comments on commit 2a457f0

Please sign in to comment.