Skip to content

Commit

Permalink
fixed things in style manager and import dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Arunmozhi committed Aug 7, 2012
1 parent ca726f3 commit 9e2a58a
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 93 deletions.
72 changes: 24 additions & 48 deletions src/core/symbology-ng/qgsstylev2.cpp
Expand Up @@ -96,7 +96,6 @@ bool QgsStyleV2::addSymbol( QString name, QgsSymbolV2* symbol )
bool QgsStyleV2::saveSymbol( QString name, QgsSymbolV2* symbol, int groupid, QStringList tags )
{
// TODO add support for tags and groups
Q_UNUSED( groupid );
Q_UNUSED( tags );

QDomDocument doc( "dummy" );
Expand All @@ -111,8 +110,8 @@ bool QgsStyleV2::saveSymbol( QString name, QgsSymbolV2* symbol, int groupid, QSt
QTextStream stream( xmlArray );
symEl.save( stream, 4 );
QByteArray nameArray = name.toUtf8();
char *query = sqlite3_mprintf( "INSERT INTO symbol VALUES (NULL, '%q', '%q', NULL);",
nameArray.constData(), xmlArray->constData() );
char *query = sqlite3_mprintf( "INSERT INTO symbol VALUES (NULL, '%q', '%q', %d);",
nameArray.constData(), xmlArray->constData(), groupid );

if ( !runEmptyQuery( query ) )
{
Expand Down Expand Up @@ -189,7 +188,6 @@ bool QgsStyleV2::addColorRamp( QString name, QgsVectorColorRampV2* colorRamp )
bool QgsStyleV2::saveColorRamp( QString name, QgsVectorColorRampV2* ramp, int groupid, QStringList tags )
{
// TODO add support for groups and tags
Q_UNUSED( groupid );
Q_UNUSED( tags );

// insert it into the database
Expand All @@ -205,8 +203,8 @@ bool QgsStyleV2::saveColorRamp( QString name, QgsVectorColorRampV2* ramp, int gr
QTextStream stream( xmlArray );
rampEl.save( stream, 4 );
QByteArray nameArray = name.toUtf8();
char *query = sqlite3_mprintf( "INSERT INTO colorramp VALUES (NULL, '%q', '%q', NULL);",
nameArray.constData(), xmlArray->constData() );
char *query = sqlite3_mprintf( "INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
nameArray.constData(), xmlArray->constData(), groupid );

if ( !runEmptyQuery( query ) )
{
Expand Down Expand Up @@ -896,70 +894,48 @@ QStringList QgsStyleV2::tagsOfSymbol( StyleEntity type, QString symbol )
return tagList;
}

int QgsStyleV2::symbolId( QString name )
int QgsStyleV2::getId( QString table, QString name )
{
int symbolid = 0;
int id = 0;
char *query;
sqlite3_stmt *ppStmt;
QByteArray array = name.toUtf8();
query = sqlite3_mprintf( "SELECT id FROM symbol WHERE name='%q';", array.constData() );
QByteArray nameArray = name.toUtf8();
QByteArray tableArray = table.toUtf8();

query = sqlite3_mprintf( "SELECT id FROM %q WHERE name='%q';", tableArray.constData(), nameArray.constData() );
int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
symbolid = sqlite3_column_int( ppStmt, 0 );
id = sqlite3_column_int( ppStmt, 0 );
}
sqlite3_finalize( ppStmt );
return symbolid;
return id;
}

int QgsStyleV2::symbolId( QString name )
{
return getId( "symbol", name );
}

int QgsStyleV2::colorrampId( QString name )
{
int symbolid = 0;
char *query;
sqlite3_stmt *ppStmt;
QByteArray array = name.toUtf8();
query = sqlite3_mprintf( "SELECT id FROM colorramp WHERE name='%q';", array.constData() );
int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
symbolid = sqlite3_column_int( ppStmt, 0 );
}
sqlite3_finalize( ppStmt );
return symbolid;
return getId( "colorramp", name );
}

int QgsStyleV2::groupId( QString name )
{
int groupid = 0;
char *query;
sqlite3_stmt *ppStmt;
QByteArray array = name.toUtf8();
query = sqlite3_mprintf( "SELECT id FROM symgroup WHERE name='%q';", array.constData() );
int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
groupid = sqlite3_column_int( ppStmt, 0 );
}
sqlite3_finalize( ppStmt );
return groupid;
return getId( "symgroup", name );
}

int QgsStyleV2::tagId( QString name )
{
int tagid = 0;
char *query;
sqlite3_stmt *ppStmt;
QByteArray array = name.toUtf8();
query = sqlite3_mprintf( "SELECT id FROM tag WHERE name='%q';", array.constData() );
int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
tagid = sqlite3_column_int( ppStmt, 0 );
}
sqlite3_finalize( ppStmt );
return tagid;
return getId( "tag", name );
}

int QgsStyleV2::smartgroupId( QString name )
{
return getId( "smartgroup", name );
}

int QgsStyleV2::addSmartgroup( QString name, QString op, QgsSmartConditionMap conditions )
{
Expand Down
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgsstylev2.h
Expand Up @@ -89,6 +89,7 @@ class CORE_EXPORT QgsStyleV2
//! return the id in the style database for the given group name
int groupId( QString group );
int tagId( QString tag );
int smartgroupId( QString smartgroup );

//! return the all the groups in the style
QStringList groupNames();
Expand Down Expand Up @@ -209,6 +210,8 @@ class CORE_EXPORT QgsStyleV2
bool runEmptyQuery( char* query );
//! prepares the complex query for removing a group,so that the children are not abandoned
char* getGroupRemoveQuery( int id );
//! gets the id from the table for the given name from the database, 0 if not found
int getId( QString table, QString name );
};


Expand Down
29 changes: 23 additions & 6 deletions src/gui/symbology-ng/qgssmartgroupeditordialog.cpp
Expand Up @@ -67,6 +67,11 @@ void QgsSmartGroupCondition::setParameter( QString param )
mCondLineEdit->setText( param );
}

void QgsSmartGroupCondition::hideRemoveButton( bool hide )
{
mRemoveBtn->setVisible( !hide );
}


// ------------------------ //
// Editor Dialog Functions //
Expand All @@ -85,7 +90,6 @@ QgsSmartGroupEditorDialog::QgsSmartGroupEditorDialog( QgsStyleV2* style, QWidget
addCondition();

connect( mAddConditionBtn, SIGNAL( clicked() ), this, SLOT( addCondition() ) );

}

QgsSmartGroupEditorDialog::~QgsSmartGroupEditorDialog()
Expand All @@ -99,22 +103,35 @@ QString QgsSmartGroupEditorDialog::smartgroupName()

void QgsSmartGroupEditorDialog::addCondition()
{
// enable the remove buttons when 2nd condition is added
if ( mConditionMap.count() == 1 )
{
foreach ( QgsSmartGroupCondition *condition, mConditionMap.values() )
{
condition->hideRemoveButton( false );
}
}
QgsSmartGroupCondition *cond = new QgsSmartGroupCondition( mCondCount, this );
mLayout->addWidget( cond, mCondCount, 0, 1, 1 );

connect( cond, SIGNAL( removed( int ) ), this, SLOT( removeCondition( int ) ) );

if ( mConditionMap.count() == 0 )
{
cond->hideRemoveButton( true );
}
mConditionMap.insert( mCondCount, cond );
++mCondCount;
}

void QgsSmartGroupEditorDialog::removeCondition( int id )
{
if ( mConditionMap.count() == 1 )
// hide the remove button of the last condition when 2nd last is removed
if ( mConditionMap.count() == 2 )
{
QMessageBox::critical( this, tr( "Invalid Operation" ),
tr( "A Smart Group should have at least ONE condition. Cannot remove the only condition." ) );
return;
foreach( QgsSmartGroupCondition* condition, mConditionMap.values() )
{
condition->hideRemoveButton( true );
}
}

QgsSmartGroupCondition *cond = mConditionMap.take( id );
Expand Down
3 changes: 3 additions & 0 deletions src/gui/symbology-ng/qgssmartgroupeditordialog.h
Expand Up @@ -37,6 +37,9 @@ class GUI_EXPORT QgsSmartGroupCondition : public QWidget, private Ui::QgsSmartGr
//! sets the given param
void setParameter( QString param );

//! sets the remove button hidden state to 'hide'
void hideRemoveButton( bool hide );

public slots:
void destruct();

Expand Down
49 changes: 38 additions & 11 deletions src/gui/symbology-ng/qgsstylev2exportimportdialog.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgsvectorcolorrampv2.h"
#include "qgslogger.h"

#include <QDate>
#include <QCloseEvent>
#include <QFileDialog>
#include <QMessageBox>
Expand Down Expand Up @@ -59,16 +60,22 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q
{
// populate the import types
importTypeCombo->addItem( "file specified below", QVariant( "file" ) );
importTypeCombo->addItem( "official QGIS repo online", QVariant( "official" ) );
// importTypeCombo->addItem( "official QGIS repo online", QVariant( "official" ) );
importTypeCombo->addItem( "URL specified below", QVariant( "url" ) );
connect( importTypeCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( importTypeChanged( int ) ) );

QStringList groups = mQgisStyle->groupNames();
groupCombo->addItem( "New Default Group", QVariant( "default" ) );
foreach ( QString gName, groups )
{
groupCombo->addItem( gName );
}

btnBrowse->setText( "Browse" );
connect( btnBrowse, SIGNAL( clicked() ), this, SLOT( browse() ) );

label->setText( tr( "Select symbols to import" ) );
buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Import" ) );

}
else
{
Expand All @@ -78,6 +85,8 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q
importTypeCombo->setHidden( true );
locationLabel->setHidden( true );
locationLineEdit->setHidden( true );
groupLabel->setHidden( true );
groupCombo->setHidden( true );

buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Export" ) );
if ( !populateStyles( mQgisStyle ) )
Expand Down Expand Up @@ -199,6 +208,26 @@ void QgsStyleV2ExportImportDialog::moveStyles( QModelIndexList* selection, QgsSt
bool isSymbol = true;
bool prompt = true;
bool overwrite = true;
int groupid = 0;

// get the groupid when going for import
if ( mDialogMode == Import )
{
QSettings settings;
int count = settings.value( "/qgis/style/importcount", 0 ).toInt();
int index = groupCombo->currentIndex();
if ( groupCombo->itemData( index ).toString() == "default" )
{
QString groupName = "import-" + QString::number( count );
groupid = dst->addGroup( groupName );
count++;
settings.setValue( "/qgis/style/importcount", count );
}
else
{
groupid = dst->groupId( groupCombo->itemText( index ) );
}
}

for ( int i = 0; i < selection->size(); ++i )
{
Expand Down Expand Up @@ -228,7 +257,7 @@ void QgsStyleV2ExportImportDialog::moveStyles( QModelIndexList* selection, QgsSt
case QMessageBox::Yes:
dst->addSymbol( symbolName, symbol );
if ( mDialogMode == Import )
dst->saveSymbol( symbolName, symbol, 0, QStringList() );
dst->saveSymbol( symbolName, symbol, groupid, QStringList() );
continue;
case QMessageBox::YesToAll:
prompt = false;
Expand All @@ -245,7 +274,7 @@ void QgsStyleV2ExportImportDialog::moveStyles( QModelIndexList* selection, QgsSt
{
dst->addSymbol( symbolName, symbol );
if ( mDialogMode == Import )
dst->saveSymbol( symbolName, symbol, 0, QStringList() );
dst->saveSymbol( symbolName, symbol, groupid, QStringList() );
}
else if ( dst->symbolNames().contains( symbolName ) && !overwrite )
{
Expand All @@ -255,7 +284,7 @@ void QgsStyleV2ExportImportDialog::moveStyles( QModelIndexList* selection, QgsSt
{
dst->addSymbol( symbolName, symbol );
if ( mDialogMode == Import )
dst->saveSymbol( symbolName, symbol, 0, QStringList() );
dst->saveSymbol( symbolName, symbol, groupid, QStringList() );
}
}
else
Expand All @@ -275,7 +304,7 @@ void QgsStyleV2ExportImportDialog::moveStyles( QModelIndexList* selection, QgsSt
case QMessageBox::Yes:
dst->addColorRamp( symbolName, ramp );
if ( mDialogMode == Import )
dst->saveColorRamp( symbolName, ramp, 0, QStringList() );
dst->saveColorRamp( symbolName, ramp, groupid, QStringList() );
continue;
case QMessageBox::YesToAll:
prompt = false;
Expand All @@ -291,7 +320,7 @@ void QgsStyleV2ExportImportDialog::moveStyles( QModelIndexList* selection, QgsSt
{
dst->addColorRamp( symbolName, ramp );
if ( mDialogMode == Import )
dst->saveColorRamp( symbolName, ramp, 0, QStringList() );
dst->saveColorRamp( symbolName, ramp, groupid, QStringList() );
}
else if ( dst->colorRampNames().contains( symbolName ) && !overwrite )
{
Expand All @@ -301,7 +330,7 @@ void QgsStyleV2ExportImportDialog::moveStyles( QModelIndexList* selection, QgsSt
{
dst->addColorRamp( symbolName, ramp );
if ( mDialogMode == Import )
dst->saveColorRamp( symbolName, ramp, 0, QStringList() );
dst->saveColorRamp( symbolName, ramp, groupid, QStringList() );
}
}
}
Expand Down Expand Up @@ -364,8 +393,6 @@ void QgsStyleV2ExportImportDialog::browse()
{
// TODO set URL
// downloadStyleXML( QUrl( "http://...." ) );
QMessageBox::warning( this, tr( "Invalid Selection" ),
tr( "Sorry! The official QGIS repository has not been implemented. You cannot use this feature now." ) );
}
else
{
Expand All @@ -375,7 +402,7 @@ void QgsStyleV2ExportImportDialog::browse()

void QgsStyleV2ExportImportDialog::downloadStyleXML( QUrl url )
{
// TODO Try to move this code to some core Network interface,
// XXX Try to move this code to some core Network interface,
// HTTP downloading is a generic functionality that might be used elsewhere

mTempFile = new QTemporaryFile();
Expand Down

0 comments on commit 9e2a58a

Please sign in to comment.