Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #545 from el1073/styles_to_db
[FEATURE] Styles to db - this was approved for late submission prior to the feature freeze
- Loading branch information
Showing
17 changed files
with
1,336 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() ); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.