Skip to content

Commit

Permalink
Merge pull request #2405 from elpaso/symbol-export-select-by-group
Browse files Browse the repository at this point in the history
Interactive selection by group of exported symbols
  • Loading branch information
elpaso committed Oct 28, 2015
2 parents 6a4544f + a141ffb commit feab3ad
Show file tree
Hide file tree
Showing 9 changed files with 537 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/gui/gui.sip
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions python/gui/symbology-ng/qgsstylev2exportimportdialog.sip
Expand Up @@ -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();
Expand Down
47 changes: 47 additions & 0 deletions 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 <qgsstylev2groupselectiondialog.h>
%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( );

};



2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
85 changes: 85 additions & 0 deletions src/gui/symbology-ng/qgsstylev2exportimportdialog.cpp
Expand Up @@ -13,7 +13,9 @@
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsstylev2exportimportdialog.h"
#include "ui_qgsstylev2exportimportdialogbase.h"

#include "qgsstylev2.h"
#include "qgssymbolv2.h"
Expand All @@ -28,6 +30,7 @@
#include <QPushButton>
#include <QStandardItemModel>


QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, QWidget *parent, Mode mode )
: QDialog( parent )
, mDialogMode( mode )
Expand All @@ -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;
Expand Down Expand Up @@ -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 );

Expand All @@ -95,6 +104,7 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q
{
QApplication::postEvent( this, new QCloseEvent() );
}

}

// use Ok button for starting import and export operations
Expand Down Expand Up @@ -370,6 +380,7 @@ QgsStyleV2ExportImportDialog::~QgsStyleV2ExportImportDialog()
{
delete mTempFile;
delete mTempStyle;
delete mGroupSelectionDlg;
}

void QgsStyleV2ExportImportDialog::selectAll()
Expand All @@ -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();
Expand Down
44 changes: 44 additions & 0 deletions src/gui/symbology-ng/qgsstylev2exportimportdialog.h
Expand Up @@ -23,6 +23,9 @@
#include <QTemporaryFile>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QStandardItem>

#include "qgsstylev2groupselectiondialog.h"

#include "ui_qgsstylev2exportimportdialogbase.h"

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

0 comments on commit feab3ad

Please sign in to comment.