diff --git a/python/gui/gui.sip b/python/gui/gui.sip index e9b194a508b..c612bf8a680 100644 --- a/python/gui/gui.sip +++ b/python/gui/gui.sip @@ -188,6 +188,7 @@ %Include symbology-ng/qgssinglesymbolrendererv2widget.sip %Include symbology-ng/qgssmartgroupeditordialog.sip %Include symbology-ng/qgsstylev2managerdialog.sip +%Include symbology-ng/qgsstylev2groupselectiondialog.sip %Include symbology-ng/qgssymbollayerv2widget.sip %Include symbology-ng/qgssymbollevelsv2dialog.sip %Include symbology-ng/qgssymbolslistwidget.sip diff --git a/python/gui/symbology-ng/qgsstylev2exportimportdialog.sip b/python/gui/symbology-ng/qgsstylev2exportimportdialog.sip index aaa41d46e58..52455a315dd 100644 --- a/python/gui/symbology-ng/qgsstylev2exportimportdialog.sip +++ b/python/gui/symbology-ng/qgsstylev2exportimportdialog.sip @@ -15,10 +15,51 @@ class QgsStyleV2ExportImportDialog : QDialog QgsStyleV2ExportImportDialog( QgsStyleV2* style, QWidget *parent /TransferThis/ = NULL, Mode mode = Export ); ~QgsStyleV2ExportImportDialog(); + /** + * @brief selectSymbols select symbols by name + * @param symbolNames list of symbol names + */ + void selectSymbols(const QStringList symbolNames); + /** + * @brief deselectSymbols deselect symbols by name + * @param symbolNames list of symbol names + */ + void deselectSymbols(const QStringList symbolNames); + public slots: void doExportImport(); + /** + * @brief selectByGroup open select by group dialog + */ + void selectByGroup(); + /** + * @brief selectAll selects all symbols + */ void selectAll(); + /** + * @brief clearSelection deselects all symbols + */ void clearSelection(); + /** + * Select the symbols belonging to the given group + * @param groupName the name of the group to be selected + */ + void selectGroup( const QString groupName ); + /** + * Unselect the symbols belonging to the given group + * @param groupName the name of the group to be deselected + */ + void deselectGroup(const QString groupName); + /** + * @brief selectSmartgroup selects all symbols from a smart group + * @param groupName + */ + void selectSmartgroup(const QString groupName); + /** + * @brief deselectSmartgroup deselects all symbols from a smart group + * @param groupName + */ + void deselectSmartgroup(const QString groupName); void importTypeChanged( int ); void browse(); diff --git a/python/gui/symbology-ng/qgsstylev2groupselectiondialog.sip b/python/gui/symbology-ng/qgsstylev2groupselectiondialog.sip new file mode 100644 index 00000000000..bfee1c4cf9f --- /dev/null +++ b/python/gui/symbology-ng/qgsstylev2groupselectiondialog.sip @@ -0,0 +1,47 @@ +/*************************************************************************** + qgsstylev2groupselectiondialog.h + --------------------- + begin : Oct 2015 + copyright : (C) 2015 by Alessandro Pasotti + email : elpaso at itopen dot it + + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + + +class QgsStyleV2GroupSelectionDialog : public QDialog, private Ui::SymbolsV2GroupSelectionDialogBase +{ +%TypeHeaderCode +#include +%End + + public: + QgsStyleV2GroupSelectionDialog(QgsStyleV2* style, QWidget *parent = 0); + ~QgsStyleV2GroupSelectionDialog(); + //! Set bold font for item + void setBold(QStandardItem *item); + + signals: + //! group with groupName has been selected + void groupSelected( const QString groupName ); + //! group with groupName has been deselected + void groupDeselected( const QString groupName ); + //! smartgroup with groupName has been selected + void smartgroupSelected( const QString groupName); + //! smart group with groupName has been deselected + void smartgroupDeselected( const QString groupName ); + //! all deselected + void allDeselected( ); + //! all selected + void allSelected( ); + +}; + + + diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index a43833dd7a6..5a8cdf4deb5 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -24,6 +24,7 @@ SET(QGIS_GUI_SRCS symbology-ng/qgsinvertedpolygonrendererwidget.cpp symbology-ng/qgsrendererv2propertiesdialog.cpp symbology-ng/qgsstylev2managerdialog.cpp + symbology-ng/qgsstylev2groupselectiondialog.cpp symbology-ng/qgssymbollevelsv2dialog.cpp symbology-ng/qgssymbolv2selectordialog.cpp symbology-ng/qgsvectorgradientcolorrampv2dialog.cpp @@ -419,6 +420,7 @@ SET(QGIS_GUI_MOC_HDRS symbology-ng/qgssinglesymbolrendererv2widget.h symbology-ng/qgssmartgroupeditordialog.h symbology-ng/qgsstylev2exportimportdialog.h + symbology-ng/qgsstylev2groupselectiondialog.h symbology-ng/qgsstylev2managerdialog.h symbology-ng/qgssvgselectorwidget.h symbology-ng/qgssymbollayerv2widget.h diff --git a/src/gui/symbology-ng/qgsstylev2exportimportdialog.cpp b/src/gui/symbology-ng/qgsstylev2exportimportdialog.cpp index 304b1e3a611..b0615bf3dea 100644 --- a/src/gui/symbology-ng/qgsstylev2exportimportdialog.cpp +++ b/src/gui/symbology-ng/qgsstylev2exportimportdialog.cpp @@ -13,7 +13,9 @@ * (at your option) any later version. * * * ***************************************************************************/ + #include "qgsstylev2exportimportdialog.h" +#include "ui_qgsstylev2exportimportdialogbase.h" #include "qgsstylev2.h" #include "qgssymbolv2.h" @@ -28,6 +30,7 @@ #include #include + QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, QWidget *parent, Mode mode ) : QDialog( parent ) , mDialogMode( mode ) @@ -46,12 +49,14 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q connect( pb, SIGNAL( clicked() ), this, SLOT( clearSelection() ) ); QStandardItemModel* model = new QStandardItemModel( listItems ); + listItems->setModel( model ); mTempStyle = new QgsStyleV2(); // TODO validate mFileName = ""; mProgressDlg = NULL; + mGroupSelectionDlg = NULL; mTempFile = NULL; mNetManager = new QNetworkAccessManager( this ); mNetReply = NULL; @@ -87,6 +92,10 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q importTypeCombo->setHidden( true ); locationLabel->setHidden( true ); locationLineEdit->setHidden( true ); + + pb = new QPushButton( tr( "Select by group" ) ); + buttonBox->addButton( pb, QDialogButtonBox::ActionRole ); + connect( pb, SIGNAL( clicked() ), this, SLOT( selectByGroup() ) ); groupLabel->setHidden( true ); groupCombo->setHidden( true ); @@ -95,6 +104,7 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q { QApplication::postEvent( this, new QCloseEvent() ); } + } // use Ok button for starting import and export operations @@ -370,6 +380,7 @@ QgsStyleV2ExportImportDialog::~QgsStyleV2ExportImportDialog() { delete mTempFile; delete mTempStyle; + delete mGroupSelectionDlg; } void QgsStyleV2ExportImportDialog::selectAll() @@ -382,6 +393,80 @@ void QgsStyleV2ExportImportDialog::clearSelection() listItems->clearSelection(); } + +void QgsStyleV2ExportImportDialog::selectSymbols( const QStringList symbolNames ) +{ + foreach ( QString symbolName, symbolNames ) + { + QModelIndexList indexes = listItems->model()->match( listItems->model()->index( 0, 0 ), Qt::DisplayRole, symbolName , 1, Qt::MatchFixedString | Qt::MatchCaseSensitive ); + foreach ( QModelIndex index, indexes ) + { + listItems->selectionModel()->select( index, QItemSelectionModel::Select ); + } + } +} + + +void QgsStyleV2ExportImportDialog::deselectSymbols( const QStringList symbolNames ) +{ + foreach ( QString symbolName, symbolNames ) + { + QModelIndexList indexes = listItems->model()->match( listItems->model()->index( 0, 0 ), Qt::DisplayRole, symbolName , 1, Qt::MatchFixedString | Qt::MatchCaseSensitive ); + foreach ( QModelIndex index, indexes ) + { + QItemSelection deselection( index, index ); + listItems->selectionModel()->select( deselection, QItemSelectionModel::Deselect ); + } + } +} + +void QgsStyleV2ExportImportDialog::selectGroup( const QString groupName ) +{ + QStringList symbolNames = mQgisStyle->symbolsOfGroup( QgsStyleV2::StyleEntity::SymbolEntity, mQgisStyle->groupId( groupName ) ); + selectSymbols( symbolNames ); +} + + +void QgsStyleV2ExportImportDialog::deselectGroup( const QString groupName ) +{ + QStringList symbolNames = mQgisStyle->symbolsOfGroup( QgsStyleV2::StyleEntity::SymbolEntity, mQgisStyle->groupId( groupName ) ); + deselectSymbols( symbolNames ); +} + + +void QgsStyleV2ExportImportDialog::selectSmartgroup( const QString groupName ) +{ + QStringList symbolNames = mQgisStyle->symbolsOfSmartgroup( QgsStyleV2::StyleEntity::SymbolEntity, mQgisStyle->smartgroupId( groupName ) ); + selectSymbols( symbolNames ); +} + + +void QgsStyleV2ExportImportDialog::deselectSmartgroup( const QString groupName ) +{ + QStringList symbolNames = mQgisStyle->symbolsOfSmartgroup( QgsStyleV2::StyleEntity::SymbolEntity, mQgisStyle->smartgroupId( groupName ) ); + deselectSymbols( symbolNames ); +} + + +void QgsStyleV2ExportImportDialog::selectByGroup( ) +{ + if ( ! mGroupSelectionDlg ) + { + mGroupSelectionDlg = new QgsStyleV2GroupSelectionDialog( mQgisStyle, this ); + mGroupSelectionDlg->setWindowTitle( tr( "Select symbols by group" ) ); + connect( mGroupSelectionDlg, SIGNAL( groupSelected( const QString ) ), this, SLOT( selectGroup( const QString ) ) ); + connect( mGroupSelectionDlg, SIGNAL( groupDeselected( const QString ) ), this, SLOT( deselectGroup( const QString ) ) ); + connect( mGroupSelectionDlg, SIGNAL( allSelected( ) ), this, SLOT( selectAll( ) ) ); + connect( mGroupSelectionDlg, SIGNAL( allDeselected( ) ), this, SLOT( clearSelection( ) ) ); + connect( mGroupSelectionDlg, SIGNAL( smartgroupSelected( const QString ) ), this, SLOT( selectSmartgroup( const QString ) ) ); + connect( mGroupSelectionDlg, SIGNAL( smartgroupDeselected( const QString ) ), this, SLOT( deselectSmartgroup( const QString ) ) ); + } + mGroupSelectionDlg->show(); + mGroupSelectionDlg->raise(); + mGroupSelectionDlg->activateWindow(); +} + + void QgsStyleV2ExportImportDialog::importTypeChanged( int index ) { QString type = importTypeCombo->itemData( index ).toString(); diff --git a/src/gui/symbology-ng/qgsstylev2exportimportdialog.h b/src/gui/symbology-ng/qgsstylev2exportimportdialog.h index fa920bc7b07..7082826bb6e 100644 --- a/src/gui/symbology-ng/qgsstylev2exportimportdialog.h +++ b/src/gui/symbology-ng/qgsstylev2exportimportdialog.h @@ -23,6 +23,9 @@ #include #include #include +#include + +#include "qgsstylev2groupselectiondialog.h" #include "ui_qgsstylev2exportimportdialogbase.h" @@ -43,11 +46,51 @@ class GUI_EXPORT QgsStyleV2ExportImportDialog : public QDialog, private Ui::QgsS // mode argument must be 0 for saving and 1 for loading QgsStyleV2ExportImportDialog( QgsStyleV2* style, QWidget *parent = NULL, Mode mode = Export ); ~QgsStyleV2ExportImportDialog(); + /** + * @brief selectSymbols select symbols by name + * @param symbolNames list of symbol names + */ + void selectSymbols( const QStringList symbolNames ); + /** + * @brief deselectSymbols deselect symbols by name + * @param symbolNames list of symbol names + */ + void deselectSymbols( const QStringList symbolNames ); public slots: void doExportImport(); + /** + * @brief selectByGroup open select by group dialog + */ + void selectByGroup(); + /** + * @brief selectAll selects all symbols + */ void selectAll(); + /** + * @brief clearSelection deselects all symbols + */ void clearSelection(); + /** + * Select the symbols belonging to the given group + * @param groupName the name of the group to be selected + */ + void selectGroup( const QString groupName ); + /** + * Unselect the symbols belonging to the given group + * @param groupName the name of the group to be deselected + */ + void deselectGroup( const QString groupName ); + /** + * @brief selectSmartgroup selects all symbols from a smart group + * @param groupName + */ + void selectSmartgroup( const QString groupName ); + /** + * @brief deselectSmartgroup deselects all symbols from a smart group + * @param groupName + */ + void deselectSmartgroup( const QString groupName ); void importTypeChanged( int ); void browse(); @@ -64,6 +107,7 @@ class GUI_EXPORT QgsStyleV2ExportImportDialog : public QDialog, private Ui::QgsS void moveStyles( QModelIndexList* selection, QgsStyleV2* src, QgsStyleV2* dst ); QProgressDialog *mProgressDlg; + QgsStyleV2GroupSelectionDialog *mGroupSelectionDlg; QTemporaryFile *mTempFile; QNetworkAccessManager *mNetManager; QNetworkReply *mNetReply; diff --git a/src/gui/symbology-ng/qgsstylev2groupselectiondialog.cpp b/src/gui/symbology-ng/qgsstylev2groupselectiondialog.cpp new file mode 100644 index 00000000000..ab57cc45257 --- /dev/null +++ b/src/gui/symbology-ng/qgsstylev2groupselectiondialog.cpp @@ -0,0 +1,165 @@ +/*************************************************************************** + qgsstylev2groupselectiondialog.h + --------------------- + begin : Oct 2015 + copyright : (C) 2015 by Alessandro Pasotti + email : elpaso at itopen dot it + + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + + +#include "qgsstylev2groupselectiondialog.h" +#include "qgsstylev2.h" + +#include +#include + + +QgsStyleV2GroupSelectionDialog::QgsStyleV2GroupSelectionDialog( QgsStyleV2 *style, QWidget *parent ) : + QDialog( parent ) + , mStyle( style ) +{ + setupUi( this ); + + QStandardItemModel* model = new QStandardItemModel( groupTree ); + groupTree->setModel( model ); + + QStandardItem *allSymbols = new QStandardItem( tr( "All Symbols" ) ); + allSymbols->setData( "all", Qt::UserRole + 2 ); + allSymbols->setEditable( false ); + setBold( allSymbols ); + model->appendRow( allSymbols ); + + QStandardItem *group = new QStandardItem( "" ); //require empty name to get first order groups + group->setData( "groupsheader", Qt::UserRole + 2 ); + group->setEditable( false ); + group->setFlags( group->flags() & ~Qt::ItemIsSelectable ); + buildGroupTree( group ); + group->setText( tr( "Groups" ) );//set title later + QStandardItem *ungrouped = new QStandardItem( tr( "Ungrouped" ) ); + ungrouped->setData( 0 ); + ungrouped->setData( "group", Qt::UserRole + 2 ); + setBold( ungrouped ); + setBold( group ); + group->appendRow( ungrouped ); + model->appendRow( group ); + + QStandardItem *tag = new QStandardItem( tr( "Smart Groups" ) ); + tag->setData( "smartgroupsheader" , Qt::UserRole + 2 ); + tag->setEditable( false ); + tag->setFlags( group->flags() & ~Qt::ItemIsSelectable ); + setBold( tag ); + QgsSymbolGroupMap sgMap = mStyle->smartgroupsListMap(); + QgsSymbolGroupMap::const_iterator i = sgMap.constBegin(); + while ( i != sgMap.constEnd() ) + { + QStandardItem *item = new QStandardItem( i.value() ); + item->setEditable( false ); + item->setData( i.key() ); + item->setData( "smartgroup" , Qt::UserRole + 2 ); + tag->appendRow( item ); + ++i; + } + model->appendRow( tag ); + + // expand things in the group tree + int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) ); + for ( int i = 0; i < rows; i++ ) + { + groupTree->setExpanded( model->indexFromItem( model->item( i ) ), true ); + } + connect( groupTree->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( groupTreeSelectionChanged( const QItemSelection&, const QItemSelection& ) ) ); +} + + +QgsStyleV2GroupSelectionDialog::~QgsStyleV2GroupSelectionDialog() +{ +} + + +void QgsStyleV2GroupSelectionDialog::setBold( QStandardItem* item ) +{ + QFont font = item->font(); + font.setBold( true ); + item->setFont( font ); +} + + +void QgsStyleV2GroupSelectionDialog::groupTreeSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected ) +{ + QModelIndex index; + QModelIndexList selectedItems = selected.indexes(); + QModelIndexList deselectedItems = deselected.indexes(); + + foreach ( index, deselectedItems ) + { + if ( index.data( Qt::UserRole + 2 ).toString() == "groupsheader" ) + { + // Ignore: it's the group header + } + else if ( index.data( Qt::UserRole + 2 ).toString() == "all" ) + { + emit allDeselected( ); + } + else if ( index.data( Qt::UserRole + 2 ).toString() == "smartgroupsheader" ) + { + // Ignore: it's the smartgroups header + } + else if ( index.data( Qt::UserRole + 2 ).toString() == "smartgroup" ) + { + emit smartgroupDeselected( index.data( ).toString() ); + } + else if ( index.data( Qt::UserRole + 2 ).toString() == "group" ) + { // It's a group + emit groupDeselected( index.data( ).toString() ); + } + } + foreach ( index, selectedItems ) + { + if ( index.data( Qt::UserRole + 2 ).toString( ) == "groupsheader" ) + { + // Ignore: it's the group header + } + else if ( index.data( Qt::UserRole + 2 ).toString() == "all" ) + { + emit allSelected( ); + } + else if ( index.data( Qt::UserRole + 2 ).toString() == "smartgroupsheader" ) + { + // Ignore: it's the smartgroups header + } + else if ( index.data( Qt::UserRole + 2 ).toString() == "smartgroup" ) + { + emit smartgroupSelected( index.data( ).toString() ); + } + else if ( index.data( Qt::UserRole + 2 ).toString() == "group" ) + { // It's a group + emit groupSelected( index.data( ).toString() ); + } + } +} + + +void QgsStyleV2GroupSelectionDialog::buildGroupTree( QStandardItem* &parent ) +{ + QgsSymbolGroupMap groups = mStyle->childGroupNames( parent->text() ); + QgsSymbolGroupMap::const_iterator i = groups.constBegin(); + while ( i != groups.constEnd() ) + { + QStandardItem *item = new QStandardItem( i.value() ); + item->setData( i.key() ); + item->setData( "group" , Qt::UserRole + 2 ); + item->setEditable( false ); + parent->appendRow( item ); + buildGroupTree( item ); + ++i; + } +} + diff --git a/src/gui/symbology-ng/qgsstylev2groupselectiondialog.h b/src/gui/symbology-ng/qgsstylev2groupselectiondialog.h new file mode 100644 index 00000000000..1c978004369 --- /dev/null +++ b/src/gui/symbology-ng/qgsstylev2groupselectiondialog.h @@ -0,0 +1,64 @@ +/*************************************************************************** + qgsstylev2groupselectiondialog.h + --------------------- + begin : Oct 2015 + copyright : (C) 2015 by Alessandro Pasotti + email : elpaso at itopen dot it + + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSSTYLEV2GROUPSELECTIONDIALOG_H +#define QGSSTYLEV2GROUPSELECTIONDIALOG_H + +#include +#include +#include "ui_qgsstylev2groupselectiondialogbase.h" + + +class QgsStyleV2; + +class GUI_EXPORT QgsStyleV2GroupSelectionDialog : public QDialog, private Ui::SymbolsV2GroupSelectionDialogBase +{ + Q_OBJECT + + public: + QgsStyleV2GroupSelectionDialog( QgsStyleV2* style, QWidget *parent = 0 ); + ~QgsStyleV2GroupSelectionDialog(); + //! Set bold font for item + void setBold( QStandardItem *item ); + + signals: + //! group with groupName has been selected + void groupSelected( const QString groupName ); + //! group with groupName has been deselected + void groupDeselected( const QString groupName ); + //! smartgroup with groupName has been selected + void smartgroupSelected( const QString groupName ); + //! smart group with groupName has been deselected + void smartgroupDeselected( const QString groupName ); + //! all deselected + void allDeselected( ); + //! all selected + void allSelected( ); + + private slots: + void groupTreeSelectionChanged( const QItemSelection&selected, const QItemSelection& deselected ); + + private: + /** + * @brief build group tree + * @param parent + */ + void buildGroupTree( QStandardItem *&parent ); + QgsStyleV2* mStyle; + +}; + +#endif // QGSSTYLEV2GROUPSELECTIONDIALOG_H diff --git a/src/ui/qgsstylev2groupselectiondialogbase.ui b/src/ui/qgsstylev2groupselectiondialogbase.ui new file mode 100644 index 00000000000..97dce71ffca --- /dev/null +++ b/src/ui/qgsstylev2groupselectiondialogbase.ui @@ -0,0 +1,88 @@ + + + SymbolsV2GroupSelectionDialogBase + + + + 0 + 0 + 287 + 348 + + + + Group Selection Dialog + + + + + + QAbstractItemView::ExtendedSelection + + + true + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Close + + + + + + + + + + + okButton + clicked() + SymbolsV2GroupSelectionDialogBase + accept() + + + 391 + 322 + + + 226 + 173 + + + + + SymbolsV2GroupSelectionDialogBase + destroyed() + SymbolsV2GroupSelectionDialogBase + accept() + + + 226 + 173 + + + 226 + 173 + + + + +