Skip to content

Commit

Permalink
[StyleManager] enable/disable appropriate buttons and menu entries
Browse files Browse the repository at this point in the history
  • Loading branch information
SebDieBln committed Jan 6, 2016
1 parent 22fb432 commit b32f124
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 10 deletions.
3 changes: 3 additions & 0 deletions python/gui/symbology-ng/qgsstylev2managerdialog.sip
Expand Up @@ -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& );

Expand Down
11 changes: 11 additions & 0 deletions src/gui/symbology-ng/qgsstylev2exportimportdialog.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 );
}
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgsstylev2exportimportdialog.h
Expand Up @@ -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 );
Expand Down
42 changes: 32 additions & 10 deletions src/gui/symbology-ng/qgsstylev2managerdialog.cpp
Expand Up @@ -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 );
Expand All @@ -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" ) );
Expand All @@ -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() ) );
Expand All @@ -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();

Expand All @@ -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 );

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -260,6 +265,8 @@ void QgsStyleV2ManagerDialog::populateSymbols( const QStringList& symbolNames, b
}
delete symbol;
}
selectedSymbolsChanged( QItemSelection(), QItemSelection() );
symbolSelected( listItems->currentIndex() );
}


Expand Down Expand Up @@ -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 )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/symbology-ng/qgsstylev2managerdialog.h
Expand Up @@ -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& );

Expand Down
11 changes: 11 additions & 0 deletions src/ui/qgsstylev2managerdialogbase.ui
Expand Up @@ -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>
Expand Down

0 comments on commit b32f124

Please sign in to comment.