Skip to content
Permalink
Browse files

Merge pull request #2638 from SebDieBln/FixStyleManagerUI

Fix some UI issues in style manager
  • Loading branch information
nyalldawson committed Jan 7, 2016
2 parents 34bc4ad + 2031ce0 commit 9d63022e4e2e82062af658d3c8e9987c7d49b7fd
@@ -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
@@ -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
@@ -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
@@ -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& );

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

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

protected:

@@ -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
@@ -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 );
@@ -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 );
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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" ) );
@@ -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 );
@@ -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()
@@ -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 );
}
@@ -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 );

0 comments on commit 9d63022

Please sign in to comment.
You can’t perform that action at this time.