Skip to content

Commit

Permalink
Merge pull request #2638 from SebDieBln/FixStyleManagerUI
Browse files Browse the repository at this point in the history
Fix some UI issues in style manager
  • Loading branch information
nyalldawson committed Jan 7, 2016
2 parents 34bc4ad + 2031ce0 commit 9d63022
Show file tree
Hide file tree
Showing 9 changed files with 386 additions and 107 deletions.
8 changes: 8 additions & 0 deletions python/core/symbology-ng/qgsstylev2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class QgsStyleV2 : QObject
int symbolId( const QString& name );
//! return the DB id for the given group name
int groupId( const QString& group );
//! return the group name for the given DB id
QString groupName( int groupId ) const;
//! return the DB id for the given tag name
int tagId( const QString& tag );
//! return the DB id for the given smartgroup name
Expand All @@ -135,6 +137,9 @@ class QgsStyleV2 : QObject
//! return the all the groups in the style
QStringList groupNames();

//! return the ids of all the groups in the style
QList<int> groupIds() const;

//! returns the symbolnames of a given groupid
/*!
* \param type is either SymbolEntity or ColorampEntity
Expand Down Expand Up @@ -270,6 +275,9 @@ class QgsStyleV2 : QObject
//! gets the id from the table for the given name from the database, 0 if not found
int getId( const QString& table, const QString& name );

//! gets the name from the table for the given id from the database, empty if not found
QString getName( const QString& table, int id ) const;

//! updates the properties of an existing symbol/colorramp
/*!
* \note This should not be called separately, only called through addSymbol or addColorRamp
Expand Down
4 changes: 4 additions & 0 deletions python/gui/symbology-ng/qgsstylev2managerdialog.sip
Original file line number Diff line number Diff line change
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 All @@ -63,6 +66,7 @@ class QgsStyleV2ManagerDialog : QDialog

protected slots:
bool addColorRamp( QAction* action );
void groupSelectedSymbols();

protected:

Expand Down
37 changes: 37 additions & 0 deletions src/core/symbology-ng/qgsstylev2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,20 @@ QStringList QgsStyleV2::groupNames()
return groupNames;
}

QList<int> QgsStyleV2::groupIds() const
{
QList<int> groupIds;
sqlite3_stmt *ppStmt;
const char *query = "SELECT * FROM symgroup";
int nError = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, nullptr );
while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
groupIds << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, SymgroupId ) ) ).toInt();
}
sqlite3_finalize( ppStmt );
return groupIds;
}

QgsSymbolGroupMap QgsStyleV2::childGroupNames( const QString& parent )
{
// get the name list from the sqlite database and return as a QStringList
Expand Down Expand Up @@ -947,6 +961,24 @@ int QgsStyleV2::getId( const QString& table, const QString& name )
return id;
}

QString QgsStyleV2::getName( const QString& table, int id ) const
{
char *query = sqlite3_mprintf( "SELECT name FROM %q WHERE id='%q'", table.toUtf8().constData(), QString::number( id ).toUtf8().constData() );

sqlite3_stmt *ppStmt;
int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, nullptr );

QString name;
if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
name = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 0 ) ) );
}

sqlite3_finalize( ppStmt );

return name;
}

int QgsStyleV2::symbolId( const QString& name )
{
return getId( "symbol", name );
Expand All @@ -962,6 +994,11 @@ int QgsStyleV2::groupId( const QString& name )
return getId( "symgroup", name );
}

QString QgsStyleV2::groupName( int groupId ) const
{
return getName( "symgroup", groupId );
}

int QgsStyleV2::tagId( const QString& name )
{
return getId( "tag", name );
Expand Down
8 changes: 8 additions & 0 deletions src/core/symbology-ng/qgsstylev2.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ class CORE_EXPORT QgsStyleV2 : public QObject
int symbolId( const QString& name );
//! return the DB id for the given group name
int groupId( const QString& group );
//! return the group name for the given DB id
QString groupName( int groupId ) const;
//! return the DB id for the given tag name
int tagId( const QString& tag );
//! return the DB id for the given smartgroup name
Expand All @@ -198,6 +200,9 @@ class CORE_EXPORT QgsStyleV2 : public QObject
//! return the all the groups in the style
QStringList groupNames();

//! return the ids of all the groups in the style
QList<int> groupIds() const;

//! returns the symbolnames of a given groupid
/*!
* \param type is either SymbolEntity or ColorampEntity
Expand Down Expand Up @@ -344,6 +349,9 @@ class CORE_EXPORT QgsStyleV2 : public QObject
//! gets the id from the table for the given name from the database, 0 if not found
int getId( const QString& table, const QString& name );

//! gets the name from the table for the given id from the database, empty if not found
QString getName( const QString& table, int id ) const;

//! updates the properties of an existing symbol/colorramp
/*!
* \note This should not be called separately, only called through addSymbol or addColorRamp
Expand Down
15 changes: 13 additions & 2 deletions src/gui/symbology-ng/qgsstylev2exportimportdialog.cpp
Original file line number Diff line number Diff line change
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 All @@ -63,7 +65,7 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q

if ( mDialogMode == Import )
{
setWindowTitle( tr( "Import style(s)" ) );
setWindowTitle( tr( "Import symbol(s)" ) );
// populate the import types
importTypeCombo->addItem( tr( "file specified below" ), QVariant( "file" ) );
// importTypeCombo->addItem( "official QGIS repo online", QVariant( "official" ) );
Expand All @@ -85,7 +87,7 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q
}
else
{
setWindowTitle( tr( "Export style(s)" ) );
setWindowTitle( tr( "Export symbol(s)" ) );
// hide import specific controls when exporting
btnBrowse->setHidden( true );
fromLabel->setHidden( true );
Expand All @@ -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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 9d63022

Please sign in to comment.