Skip to content

Commit 9d63022

Browse files
committed
Merge pull request #2638 from SebDieBln/FixStyleManagerUI
Fix some UI issues in style manager
2 parents 34bc4ad + 2031ce0 commit 9d63022

9 files changed

+386
-107
lines changed

python/core/symbology-ng/qgsstylev2.sip

+8
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ class QgsStyleV2 : QObject
127127
int symbolId( const QString& name );
128128
//! return the DB id for the given group name
129129
int groupId( const QString& group );
130+
//! return the group name for the given DB id
131+
QString groupName( int groupId ) const;
130132
//! return the DB id for the given tag name
131133
int tagId( const QString& tag );
132134
//! return the DB id for the given smartgroup name
@@ -135,6 +137,9 @@ class QgsStyleV2 : QObject
135137
//! return the all the groups in the style
136138
QStringList groupNames();
137139

140+
//! return the ids of all the groups in the style
141+
QList<int> groupIds() const;
142+
138143
//! returns the symbolnames of a given groupid
139144
/*!
140145
* \param type is either SymbolEntity or ColorampEntity
@@ -270,6 +275,9 @@ class QgsStyleV2 : QObject
270275
//! gets the id from the table for the given name from the database, 0 if not found
271276
int getId( const QString& table, const QString& name );
272277

278+
//! gets the name from the table for the given id from the database, empty if not found
279+
QString getName( const QString& table, int id ) const;
280+
273281
//! updates the properties of an existing symbol/colorramp
274282
/*!
275283
* \note This should not be called separately, only called through addSymbol or addColorRamp

python/gui/symbology-ng/qgsstylev2managerdialog.sip

+4
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

@@ -63,6 +66,7 @@ class QgsStyleV2ManagerDialog : QDialog
6366

6467
protected slots:
6568
bool addColorRamp( QAction* action );
69+
void groupSelectedSymbols();
6670

6771
protected:
6872

src/core/symbology-ng/qgsstylev2.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,20 @@ QStringList QgsStyleV2::groupNames()
475475
return groupNames;
476476
}
477477

478+
QList<int> QgsStyleV2::groupIds() const
479+
{
480+
QList<int> groupIds;
481+
sqlite3_stmt *ppStmt;
482+
const char *query = "SELECT * FROM symgroup";
483+
int nError = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, nullptr );
484+
while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
485+
{
486+
groupIds << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, SymgroupId ) ) ).toInt();
487+
}
488+
sqlite3_finalize( ppStmt );
489+
return groupIds;
490+
}
491+
478492
QgsSymbolGroupMap QgsStyleV2::childGroupNames( const QString& parent )
479493
{
480494
// get the name list from the sqlite database and return as a QStringList
@@ -947,6 +961,24 @@ int QgsStyleV2::getId( const QString& table, const QString& name )
947961
return id;
948962
}
949963

964+
QString QgsStyleV2::getName( const QString& table, int id ) const
965+
{
966+
char *query = sqlite3_mprintf( "SELECT name FROM %q WHERE id='%q'", table.toUtf8().constData(), QString::number( id ).toUtf8().constData() );
967+
968+
sqlite3_stmt *ppStmt;
969+
int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, nullptr );
970+
971+
QString name;
972+
if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
973+
{
974+
name = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 0 ) ) );
975+
}
976+
977+
sqlite3_finalize( ppStmt );
978+
979+
return name;
980+
}
981+
950982
int QgsStyleV2::symbolId( const QString& name )
951983
{
952984
return getId( "symbol", name );
@@ -962,6 +994,11 @@ int QgsStyleV2::groupId( const QString& name )
962994
return getId( "symgroup", name );
963995
}
964996

997+
QString QgsStyleV2::groupName( int groupId ) const
998+
{
999+
return getName( "symgroup", groupId );
1000+
}
1001+
9651002
int QgsStyleV2::tagId( const QString& name )
9661003
{
9671004
return getId( "tag", name );

src/core/symbology-ng/qgsstylev2.h

+8
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ class CORE_EXPORT QgsStyleV2 : public QObject
190190
int symbolId( const QString& name );
191191
//! return the DB id for the given group name
192192
int groupId( const QString& group );
193+
//! return the group name for the given DB id
194+
QString groupName( int groupId ) const;
193195
//! return the DB id for the given tag name
194196
int tagId( const QString& tag );
195197
//! return the DB id for the given smartgroup name
@@ -198,6 +200,9 @@ class CORE_EXPORT QgsStyleV2 : public QObject
198200
//! return the all the groups in the style
199201
QStringList groupNames();
200202

203+
//! return the ids of all the groups in the style
204+
QList<int> groupIds() const;
205+
201206
//! returns the symbolnames of a given groupid
202207
/*!
203208
* \param type is either SymbolEntity or ColorampEntity
@@ -344,6 +349,9 @@ class CORE_EXPORT QgsStyleV2 : public QObject
344349
//! gets the id from the table for the given name from the database, 0 if not found
345350
int getId( const QString& table, const QString& name );
346351

352+
//! gets the name from the table for the given id from the database, empty if not found
353+
QString getName( const QString& table, int id ) const;
354+
347355
//! updates the properties of an existing symbol/colorramp
348356
/*!
349357
* \note This should not be called separately, only called through addSymbol or addColorRamp

src/gui/symbology-ng/qgsstylev2exportimportdialog.cpp

+13-2
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
@@ -63,7 +65,7 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q
6365

6466
if ( mDialogMode == Import )
6567
{
66-
setWindowTitle( tr( "Import style(s)" ) );
68+
setWindowTitle( tr( "Import symbol(s)" ) );
6769
// populate the import types
6870
importTypeCombo->addItem( tr( "file specified below" ), QVariant( "file" ) );
6971
// importTypeCombo->addItem( "official QGIS repo online", QVariant( "official" ) );
@@ -85,7 +87,7 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q
8587
}
8688
else
8789
{
88-
setWindowTitle( tr( "Export style(s)" ) );
90+
setWindowTitle( tr( "Export symbol(s)" ) );
8991
// hide import specific controls when exporting
9092
btnBrowse->setHidden( true );
9193
fromLabel->setHidden( true );
@@ -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

+1
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 );

0 commit comments

Comments
 (0)