Skip to content

Commit

Permalink
Merge pull request #545 from el1073/styles_to_db
Browse files Browse the repository at this point in the history
[FEATURE] Styles to db - this was approved for late submission prior to the feature freeze
  • Loading branch information
timlinux committed May 2, 2013
2 parents 3e1f3a0 + 1dfcf53 commit 550825a
Show file tree
Hide file tree
Showing 17 changed files with 1,336 additions and 109 deletions.
2 changes: 1 addition & 1 deletion doc/INSTALL.html
Expand Up @@ -883,7 +883,7 @@ <H3>4.1.1. Visual C++ Express Edition</H3>
Visual Studio 2008 will also be downloaded and installed.
</P>
<P>
You also need the Microsoft Windows Server® 2003 R2 Platform SDK (for setupapi):
You also need the Microsoft Windows Server® 2003 R2 Platform SDK (for setupapi):
</P>
<BLOCKQUOTE>
<A HREF="http://download.microsoft.com/download/f/a/d/fad9efde-8627-4e7a-8812-c351ba099151/PSDK-x86.exe">http://download.microsoft.com/download/f/a/d/fad9efde-8627-4e7a-8812-c351ba099151/PSDK-x86.exe</A>
Expand Down
4 changes: 4 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -42,6 +42,8 @@ SET(QGIS_APP_SRCS
qgslabelengineconfigdialog.cpp
qgslabelinggui.cpp
qgslabelpreview.cpp
qgsloadstylefromdbdialog.cpp
qgssavestyletodbdialog.cpp

qgsmaptooladdfeature.cpp
qgsmaptooladdvertex.cpp
Expand Down Expand Up @@ -195,6 +197,8 @@ SET (QGIS_APP_MOC_HDRS
qgslabelengineconfigdialog.h
qgslabelinggui.h
qgslabelpropertydialog.h
qgsloadstylefromdbdialog.h
qgssavestyletodbdialog.h
qgsshortcutsmanager.h

qgsmaptooladdfeature.h
Expand Down
100 changes: 100 additions & 0 deletions src/app/qgsloadstylefromdbdialog.cpp
@@ -0,0 +1,100 @@
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#include "qgsloadstylefromdbdialog.h"
#include "qgslogger.h"

#include <QMessageBox>
#include <QVector>

QgsLoadStyleFromDBDialog::QgsLoadStyleFromDBDialog( QWidget *parent )
: QDialog( parent )
{
setupUi( this );
setWindowTitle( "Load style from database" );
mSelectedStyleId = tr( "" );

mLoadButton->setDisabled( true );
mRelatedTable->setEditTriggers( QTableWidget::NoEditTriggers );
mRelatedTable->horizontalHeader()->setStretchLastSection( true );
mRelatedTable->setSelectionBehavior( QTableWidget::SelectRows );
mRelatedTable->verticalHeader()->setVisible( false );

mOthersTable->setEditTriggers( QTableWidget::NoEditTriggers );
mOthersTable->horizontalHeader()->setStretchLastSection( true );
mOthersTable->setSelectionBehavior( QTableWidget::SelectRows );
mOthersTable->verticalHeader()->setVisible( false );

connect(mRelatedTable, SIGNAL( cellClicked( int,int ) ), this, SLOT( cellSelectedRelatedTable( int ) ) );
connect(mOthersTable, SIGNAL( cellClicked( int,int ) ), this, SLOT( cellSelectedOthersTable( int ) ) );
connect(mRelatedTable, SIGNAL( doubleClicked( QModelIndex ) ),
this, SLOT( accept() ) );
connect(mOthersTable, SIGNAL( doubleClicked( QModelIndex ) ),
this, SLOT( accept() ) );
connect(mCancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
connect(mLoadButton, SIGNAL( clicked() ), this, SLOT( accept() ) );

setTabOrder( mRelatedTable, mOthersTable );
setTabOrder( mOthersTable, mCancelButton );
setTabOrder( mCancelButton, mLoadButton );

}

void QgsLoadStyleFromDBDialog::initializeLists( QVector<QString> ids, QVector<QString> names,
QVector<QString> descriptions, int sectionLimit )
{
mIds = ids;
mNames = names;
mDescriptions = descriptions;
mSectionLimit = sectionLimit;
int relatedTableNOfCols = ( sectionLimit > 0 ) ? 2 : 1;
int othersTableNOfCols = ( ids.count() - sectionLimit > 0 ) ? 2 : 1;
QString twoColsHeader( "Name;Description" );
QString oneColsHeader( "No styles found in the database" );
QString relatedTableHeader = ( relatedTableNOfCols == 1 ) ? oneColsHeader : twoColsHeader;
QString othersTableHeader = ( othersTableNOfCols == 1 ) ? oneColsHeader : twoColsHeader;

mRelatedTable->setColumnCount( relatedTableNOfCols );
mOthersTable->setColumnCount( othersTableNOfCols );
mRelatedTable->setHorizontalHeaderLabels( relatedTableHeader.split( ";" ) );
mOthersTable->setHorizontalHeaderLabels( othersTableHeader.split( ";" ) );
mRelatedTable->setRowCount( sectionLimit );
mOthersTable->setRowCount( ids.count() - sectionLimit );
mRelatedTable->setDisabled( ( relatedTableNOfCols == 1 ) );
mOthersTable->setDisabled( ( othersTableNOfCols == 1 ) );

for( int i=0; i<sectionLimit; i++ )
{
mRelatedTable->setItem(i, 0, new QTableWidgetItem( names.value( i, "" ) ) );
mRelatedTable->setItem(i, 1, new QTableWidgetItem( descriptions.value( i, "" ) ) );
}
for( int i=sectionLimit; i<ids.count(); i++ )
{
int j = i-sectionLimit;
mOthersTable->setItem(j, 0, new QTableWidgetItem( names.value( i, "" ) ) );
mOthersTable->setItem(j, 1, new QTableWidgetItem( descriptions.value( i, "" ) ) );
}
}

QString QgsLoadStyleFromDBDialog::getSelectedStyleId()
{
return mSelectedStyleId;
}

void QgsLoadStyleFromDBDialog::cellSelectedRelatedTable( int r )
{
mLoadButton->setEnabled( true );
mSelectedStyleId = mIds.value( r );
}

void QgsLoadStyleFromDBDialog::cellSelectedOthersTable( int r )
{
mLoadButton->setEnabled( true );
mSelectedStyleId = mIds.value( r + mSectionLimit );
}
40 changes: 40 additions & 0 deletions src/app/qgsloadstylefromdbdialog.h
@@ -0,0 +1,40 @@
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#ifndef QGSLOADFILEFROMDBDIALOG_H
#define QGSLOADFILEFROMDBDIALOG_H

#include <QVector>

#include "ui_qgsloadstylefromdbdialog.h"
#include "qgisgui.h"
#include "qgsfield.h"

class QgsLoadStyleFromDBDialog: public QDialog, private Ui::QgsLoadStyleFromDBDialogLayout
{
QString mSelectedStyleId;
int mSectionLimit;
QVector<QString> mIds, mNames, mDescriptions;
QString qmlStyle;
Q_OBJECT
public:
explicit QgsLoadStyleFromDBDialog( QWidget *parent = 0 );

void initializeLists( QVector<QString> ids, QVector<QString> names, QVector<QString> descriptions, int sectionLimit);
QString getSelectedStyleId();

public slots:
void cellSelectedRelatedTable( int r );
void cellSelectedOthersTable( int r );

private:

};

#endif //QGSLOADFILEFROMDBDIALOG_H
90 changes: 90 additions & 0 deletions src/app/qgssavestyletodbdialog.cpp
@@ -0,0 +1,90 @@
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#include "qgssavestyletodbdialog.h"

#include <QFileDialog>
#include <QSettings>
#include <QDomDocument>
#include <QMessageBox>
#include <QDateTime>

QgsSaveStyleToDbDialog::QgsSaveStyleToDbDialog( QWidget *parent ) :
QDialog( parent )
{
setupUi( this );
setWindowTitle( "Save style in database" );
mDescriptionEdit->setTabChangesFocus( true );
setTabOrder( mNameEdit, mDescriptionEdit );
setTabOrder( mDescriptionEdit, mUseAsDefault );
setTabOrder( mUseAsDefault, buttonBox );

}
QString QgsSaveStyleToDbDialog::getName()
{
return mNameEdit->text();
}
QString QgsSaveStyleToDbDialog::getDescription()
{
return mDescriptionEdit->toPlainText();
}
bool QgsSaveStyleToDbDialog::isDefault()
{
return mUseAsDefault->isChecked();
}
QString QgsSaveStyleToDbDialog::getUIFileContent()
{
return mUIFileContent;
}

void QgsSaveStyleToDbDialog::accept()
{
if( getName().isEmpty() ){
QMessageBox::information( this, tr( "Save style in database" ), tr( "A name is mandatory" ) );
return;
}
QDialog::accept();
}

void QgsSaveStyleToDbDialog::on_mFilePickButton_clicked()
{
QSettings myQSettings; // where we keep last used filter in persistent state
QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", "." ).toString();

QString myFileName = QFileDialog::getOpenFileName( this, tr( "Attach Qt Creator UI file" ), myLastUsedDir, tr( "Qt Creator UI file .ui" ) + " (*.ui)" );
if ( myFileName.isNull() )
{
return;
}


QFileInfo myFI( myFileName );

QFile uiFile( myFI.filePath() );

QString myPath = myFI.path();
myQSettings.setValue( "style/lastStyleDir", myPath );

if(uiFile.open( QIODevice::ReadOnly ) )
{
QString content( uiFile.readAll() );
QDomDocument doc;

if( !doc.setContent(content) || doc.documentElement().tagName().compare( "ui" ) )
{
QMessageBox::warning(this, tr( "Wrong file" ),
tr( "The selected file does not appear to be a valid Qt Creator UI file."));
return;
}
mUIFileContent = content;
mFileNameLabel->setText( myFI.fileName() );
}

}

35 changes: 35 additions & 0 deletions src/app/qgssavestyletodbdialog.h
@@ -0,0 +1,35 @@
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#ifndef QGSSAVESTYLETODBDIALOG_H
#define QGSSAVESTYLETODBDIALOG_H

#include "ui_qgssavetodbdialog.h"
#include "qgisgui.h"
#include "qgsfield.h"

class QgsSaveStyleToDbDialog : public QDialog, private Ui::QgsSaveToDBDialog
{
QString mUIFileContent;
Q_OBJECT
public:
explicit QgsSaveStyleToDbDialog(QWidget *parent = 0);

signals:

public slots:
QString getUIFileContent();
QString getName();
QString getDescription();
bool isDefault();
void on_mFilePickButton_clicked();
void accept();
};

#endif // QGSSAVESTYLETODBDIALOG_H

0 comments on commit 550825a

Please sign in to comment.