[StyleManager] enable/disable appropriate buttons and menu entries

This commit is contained in:
Sebastian Dietrich 2016-01-02 16:25:51 +01:00
parent 22fb4321bc
commit b32f124488
6 changed files with 61 additions and 10 deletions

View File

@ -55,6 +55,9 @@ class QgsStyleV2ManagerDialog : QDialog
//! Perform symbol specific tasks when selected
void symbolSelected( const QModelIndex& );
//! Perform tasks when the selected symbols change
void selectedSymbolsChanged( const QItemSelection& selected, const QItemSelection& deselected );
//! Context menu for the groupTree
void grouptreeContextMenu( const QPoint& );

View File

@ -51,6 +51,8 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q
QStandardItemModel* model = new QStandardItemModel( listItems );
listItems->setModel( model );
connect( listItems->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ),
this, SLOT( selectionChanged( const QItemSelection&, const QItemSelection& ) ) );
mTempStyle = new QgsStyleV2();
// TODO validate
@ -109,6 +111,7 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q
// use Ok button for starting import and export operations
disconnect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
connect( buttonBox, SIGNAL( accepted() ), this, SLOT( doExportImport() ) );
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
}
void QgsStyleV2ExportImportDialog::doExportImport()
@ -594,3 +597,11 @@ void QgsStyleV2ExportImportDialog::downloadCanceled()
mTempFile->remove();
mFileName = "";
}
void QgsStyleV2ExportImportDialog::selectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
{
Q_UNUSED( selected );
Q_UNUSED( deselected );
bool nothingSelected = listItems->selectionModel()->selectedIndexes().empty();
buttonBox->button( QDialogButtonBox::Ok )->setDisabled( nothingSelected );
}

View File

@ -100,6 +100,7 @@ class GUI_EXPORT QgsStyleV2ExportImportDialog : public QDialog, private Ui::QgsS
void fileReadyRead();
void updateProgress( qint64, qint64 );
void downloadCanceled();
void selectionChanged( const QItemSelection & selected, const QItemSelection & deselected );
private:
void downloadStyleXML( const QUrl& url );

View File

@ -49,7 +49,6 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
#endif
QSettings settings;
QAction* a; // used as a temporary variable before passing ownership of a created action.
restoreGeometry( settings.value( "/Windows/StyleV2Manager/geometry" ).toByteArray() );
mSplitter->setSizes( QList<int>() << 170 << 540 );
@ -66,6 +65,8 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
connect( btnEditItem, SIGNAL( clicked() ), this, SLOT( editItem() ) );
connect( btnRemoveItem, SIGNAL( clicked() ), this, SLOT( removeItem() ) );
btnRemoveItem->setEnabled( false );
QMenu *shareMenu = new QMenu( tr( "Share menu" ), this );
QAction *exportAsPNGAction = shareMenu->addAction( tr( "Export selected symbols as PNG" ) );
QAction *exportAsSVGAction = shareMenu->addAction( tr( "Export selected symbols as SVG" ) );
@ -74,7 +75,9 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
QAction *importAction = new QAction( tr( "Import..." ), this );
shareMenu->addAction( importAction );
exportAsPNGAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingExport.svg" ) ) );
exportAsPNGAction->setEnabled( false );
exportAsSVGAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingExport.svg" ) ) );
exportAsSVGAction->setEnabled( false );
exportAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingExport.svg" ) ) );
importAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingImport.svg" ) ) );
connect( exportAsPNGAction, SIGNAL( triggered() ), this, SLOT( exportItemsPNG() ) );
@ -93,6 +96,8 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
connect( model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( itemChanged( QStandardItem* ) ) );
connect( listItems->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
this, SLOT( symbolSelected( const QModelIndex& ) ) );
connect( listItems->selectionModel(), SIGNAL( selectionChanged( const QItemSelection, const QItemSelection ) ),
this, SLOT( selectedSymbolsChanged( const QItemSelection&, const QItemSelection& ) ) );
populateTypes();
@ -115,8 +120,6 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
connect( btnAddGroup, SIGNAL( clicked() ), this, SLOT( addGroup() ) );
connect( btnRemoveGroup, SIGNAL( clicked() ), this, SLOT( removeGroup() ) );
on_tabItemType_currentChanged( 0 );
connect( searchBox, SIGNAL( textChanged( QString ) ), this, SLOT( filterSymbols( QString ) ) );
tagsLineEdit->installEventFilter( this );
@ -144,10 +147,12 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
mGroupMenu = new QMenu( this );
mGroupListMenu = new QMenu( mGroupMenu );
mGroupListMenu->setTitle( tr( "Apply Group" ) );
mGroupListMenu->setEnabled( false );
mGroupMenu->addMenu( mGroupListMenu );
a = new QAction( tr( "Un-group" ), mGroupMenu );
a->setData( 0 );
mGroupMenu->addAction( a );
actnUngroup->setData( 0 );
mGroupMenu->addAction( actnUngroup );
on_tabItemType_currentChanged( 0 );
}
void QgsStyleV2ManagerDialog::onFinished()
@ -260,6 +265,8 @@ void QgsStyleV2ManagerDialog::populateSymbols( const QStringList& symbolNames, b
}
delete symbol;
}
selectedSymbolsChanged( QItemSelection(), QItemSelection() );
symbolSelected( listItems->currentIndex() );
}
@ -1219,10 +1226,25 @@ void QgsStyleV2ManagerDialog::symbolSelected( const QModelIndex& index )
{
// Populate the tags for the symbol
tagsLineEdit->clear();
QStandardItem *item = static_cast<QStandardItemModel*>( listItems->model() )->itemFromIndex( index );
QgsStyleV2::StyleEntity type = ( currentItemType() < 3 ) ? QgsStyleV2::SymbolEntity : QgsStyleV2::ColorrampEntity;
mTagList = mStyle->tagsOfSymbol( type, item->data().toString() );
tagsLineEdit->setText( mTagList.join( "," ) );
if ( index.isValid() )
{
QStandardItem *item = static_cast<QStandardItemModel*>( listItems->model() )->itemFromIndex( index );
QgsStyleV2::StyleEntity type = ( currentItemType() < 3 ) ? QgsStyleV2::SymbolEntity : QgsStyleV2::ColorrampEntity;
mTagList = mStyle->tagsOfSymbol( type, item->data().toString() );
tagsLineEdit->setText( mTagList.join( "," ) );
}
}
void QgsStyleV2ManagerDialog::selectedSymbolsChanged( const QItemSelection& selected, const QItemSelection& deselected )
{
Q_UNUSED( selected );
Q_UNUSED( deselected );
bool nothingSelected = listItems->selectionModel()->selectedIndexes().empty();
btnRemoveItem->setDisabled( nothingSelected );
mGroupListMenu->setDisabled( nothingSelected );
actnUngroup->setDisabled( nothingSelected );
btnShare->menu()->actions().at( 0 )->setDisabled( nothingSelected );
btnShare->menu()->actions().at( 1 )->setDisabled( nothingSelected );
}
void QgsStyleV2ManagerDialog::enableSymbolInputs( bool enable )

View File

@ -81,6 +81,9 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
//! Perform symbol specific tasks when selected
void symbolSelected( const QModelIndex& );
//! Perform tasks when the selected symbols change
void selectedSymbolsChanged( const QItemSelection& selected, const QItemSelection& deselected );
//! Context menu for the groupTree
void grouptreeContextMenu( const QPoint& );

View File

@ -420,6 +420,17 @@ QMenu::item:selected { background-color: gray; } */
</widget>
</item>
</layout>
<action name="actnUngroup">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Ungroup</string>
</property>
<property name="toolTip">
<string>Ungroup</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>