Skip to content

Commit b32f124

Browse files
committedJan 6, 2016
[StyleManager] enable/disable appropriate buttons and menu entries
1 parent 22fb432 commit b32f124

File tree

6 files changed

+61
-10
lines changed

6 files changed

+61
-10
lines changed
 

‎python/gui/symbology-ng/qgsstylev2managerdialog.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class QgsStyleV2ManagerDialog : QDialog
5555
//! Perform symbol specific tasks when selected
5656
void symbolSelected( const QModelIndex& );
5757

58+
//! Perform tasks when the selected symbols change
59+
void selectedSymbolsChanged( const QItemSelection& selected, const QItemSelection& deselected );
60+
5861
//! Context menu for the groupTree
5962
void grouptreeContextMenu( const QPoint& );
6063

‎src/gui/symbology-ng/qgsstylev2exportimportdialog.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q
5151
QStandardItemModel* model = new QStandardItemModel( listItems );
5252

5353
listItems->setModel( model );
54+
connect( listItems->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ),
55+
this, SLOT( selectionChanged( const QItemSelection&, const QItemSelection& ) ) );
5456

5557
mTempStyle = new QgsStyleV2();
5658
// TODO validate
@@ -109,6 +111,7 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q
109111
// use Ok button for starting import and export operations
110112
disconnect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
111113
connect( buttonBox, SIGNAL( accepted() ), this, SLOT( doExportImport() ) );
114+
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
112115
}
113116

114117
void QgsStyleV2ExportImportDialog::doExportImport()
@@ -594,3 +597,11 @@ void QgsStyleV2ExportImportDialog::downloadCanceled()
594597
mTempFile->remove();
595598
mFileName = "";
596599
}
600+
601+
void QgsStyleV2ExportImportDialog::selectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
602+
{
603+
Q_UNUSED( selected );
604+
Q_UNUSED( deselected );
605+
bool nothingSelected = listItems->selectionModel()->selectedIndexes().empty();
606+
buttonBox->button( QDialogButtonBox::Ok )->setDisabled( nothingSelected );
607+
}

‎src/gui/symbology-ng/qgsstylev2exportimportdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class GUI_EXPORT QgsStyleV2ExportImportDialog : public QDialog, private Ui::QgsS
100100
void fileReadyRead();
101101
void updateProgress( qint64, qint64 );
102102
void downloadCanceled();
103+
void selectionChanged( const QItemSelection & selected, const QItemSelection & deselected );
103104

104105
private:
105106
void downloadStyleXML( const QUrl& url );

‎src/gui/symbology-ng/qgsstylev2managerdialog.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
4949
#endif
5050

5151
QSettings settings;
52-
QAction* a; // used as a temporary variable before passing ownership of a created action.
5352

5453
restoreGeometry( settings.value( "/Windows/StyleV2Manager/geometry" ).toByteArray() );
5554
mSplitter->setSizes( QList<int>() << 170 << 540 );
@@ -66,6 +65,8 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
6665
connect( btnEditItem, SIGNAL( clicked() ), this, SLOT( editItem() ) );
6766
connect( btnRemoveItem, SIGNAL( clicked() ), this, SLOT( removeItem() ) );
6867

68+
btnRemoveItem->setEnabled( false );
69+
6970
QMenu *shareMenu = new QMenu( tr( "Share menu" ), this );
7071
QAction *exportAsPNGAction = shareMenu->addAction( tr( "Export selected symbols as PNG" ) );
7172
QAction *exportAsSVGAction = shareMenu->addAction( tr( "Export selected symbols as SVG" ) );
@@ -74,7 +75,9 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
7475
QAction *importAction = new QAction( tr( "Import..." ), this );
7576
shareMenu->addAction( importAction );
7677
exportAsPNGAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingExport.svg" ) ) );
78+
exportAsPNGAction->setEnabled( false );
7779
exportAsSVGAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingExport.svg" ) ) );
80+
exportAsSVGAction->setEnabled( false );
7881
exportAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingExport.svg" ) ) );
7982
importAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingImport.svg" ) ) );
8083
connect( exportAsPNGAction, SIGNAL( triggered() ), this, SLOT( exportItemsPNG() ) );
@@ -93,6 +96,8 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
9396
connect( model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( itemChanged( QStandardItem* ) ) );
9497
connect( listItems->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
9598
this, SLOT( symbolSelected( const QModelIndex& ) ) );
99+
connect( listItems->selectionModel(), SIGNAL( selectionChanged( const QItemSelection, const QItemSelection ) ),
100+
this, SLOT( selectedSymbolsChanged( const QItemSelection&, const QItemSelection& ) ) );
96101

97102
populateTypes();
98103

@@ -115,8 +120,6 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
115120
connect( btnAddGroup, SIGNAL( clicked() ), this, SLOT( addGroup() ) );
116121
connect( btnRemoveGroup, SIGNAL( clicked() ), this, SLOT( removeGroup() ) );
117122

118-
on_tabItemType_currentChanged( 0 );
119-
120123
connect( searchBox, SIGNAL( textChanged( QString ) ), this, SLOT( filterSymbols( QString ) ) );
121124
tagsLineEdit->installEventFilter( this );
122125

@@ -144,10 +147,12 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
144147
mGroupMenu = new QMenu( this );
145148
mGroupListMenu = new QMenu( mGroupMenu );
146149
mGroupListMenu->setTitle( tr( "Apply Group" ) );
150+
mGroupListMenu->setEnabled( false );
147151
mGroupMenu->addMenu( mGroupListMenu );
148-
a = new QAction( tr( "Un-group" ), mGroupMenu );
149-
a->setData( 0 );
150-
mGroupMenu->addAction( a );
152+
actnUngroup->setData( 0 );
153+
mGroupMenu->addAction( actnUngroup );
154+
155+
on_tabItemType_currentChanged( 0 );
151156
}
152157

153158
void QgsStyleV2ManagerDialog::onFinished()
@@ -260,6 +265,8 @@ void QgsStyleV2ManagerDialog::populateSymbols( const QStringList& symbolNames, b
260265
}
261266
delete symbol;
262267
}
268+
selectedSymbolsChanged( QItemSelection(), QItemSelection() );
269+
symbolSelected( listItems->currentIndex() );
263270
}
264271

265272

@@ -1219,10 +1226,25 @@ void QgsStyleV2ManagerDialog::symbolSelected( const QModelIndex& index )
12191226
{
12201227
// Populate the tags for the symbol
12211228
tagsLineEdit->clear();
1222-
QStandardItem *item = static_cast<QStandardItemModel*>( listItems->model() )->itemFromIndex( index );
1223-
QgsStyleV2::StyleEntity type = ( currentItemType() < 3 ) ? QgsStyleV2::SymbolEntity : QgsStyleV2::ColorrampEntity;
1224-
mTagList = mStyle->tagsOfSymbol( type, item->data().toString() );
1225-
tagsLineEdit->setText( mTagList.join( "," ) );
1229+
if ( index.isValid() )
1230+
{
1231+
QStandardItem *item = static_cast<QStandardItemModel*>( listItems->model() )->itemFromIndex( index );
1232+
QgsStyleV2::StyleEntity type = ( currentItemType() < 3 ) ? QgsStyleV2::SymbolEntity : QgsStyleV2::ColorrampEntity;
1233+
mTagList = mStyle->tagsOfSymbol( type, item->data().toString() );
1234+
tagsLineEdit->setText( mTagList.join( "," ) );
1235+
}
1236+
}
1237+
1238+
void QgsStyleV2ManagerDialog::selectedSymbolsChanged( const QItemSelection& selected, const QItemSelection& deselected )
1239+
{
1240+
Q_UNUSED( selected );
1241+
Q_UNUSED( deselected );
1242+
bool nothingSelected = listItems->selectionModel()->selectedIndexes().empty();
1243+
btnRemoveItem->setDisabled( nothingSelected );
1244+
mGroupListMenu->setDisabled( nothingSelected );
1245+
actnUngroup->setDisabled( nothingSelected );
1246+
btnShare->menu()->actions().at( 0 )->setDisabled( nothingSelected );
1247+
btnShare->menu()->actions().at( 1 )->setDisabled( nothingSelected );
12261248
}
12271249

12281250
void QgsStyleV2ManagerDialog::enableSymbolInputs( bool enable )

‎src/gui/symbology-ng/qgsstylev2managerdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
8181
//! Perform symbol specific tasks when selected
8282
void symbolSelected( const QModelIndex& );
8383

84+
//! Perform tasks when the selected symbols change
85+
void selectedSymbolsChanged( const QItemSelection& selected, const QItemSelection& deselected );
86+
8487
//! Context menu for the groupTree
8588
void grouptreeContextMenu( const QPoint& );
8689

‎src/ui/qgsstylev2managerdialogbase.ui

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,17 @@ QMenu::item:selected { background-color: gray; } */
420420
</widget>
421421
</item>
422422
</layout>
423+
<action name="actnUngroup">
424+
<property name="enabled">
425+
<bool>false</bool>
426+
</property>
427+
<property name="text">
428+
<string>Ungroup</string>
429+
</property>
430+
<property name="toolTip">
431+
<string>Ungroup</string>
432+
</property>
433+
</action>
423434
</widget>
424435
<customwidgets>
425436
<customwidget>

0 commit comments

Comments
 (0)
Please sign in to comment.