-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgssavestyletodbdialog.cpp
113 lines (95 loc) · 3.66 KB
/
qgssavestyletodbdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************************************
qgssavestyletodbdialog.cpp
---------------------
begin : April 2013
copyright : (C) 2013 by Emilio Loi
email : loi at faunalia dot it
***************************************************************************
* *
* 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 "qgssettings.h"
#include <QFileDialog>
#include <QDomDocument>
#include <QMessageBox>
#include <QDateTime>
QgsSaveStyleToDbDialog::QgsSaveStyleToDbDialog( QWidget *parent )
: QDialog( parent )
{
setupUi( this );
connect( mFilePickButton, &QToolButton::clicked, this, &QgsSaveStyleToDbDialog::mFilePickButton_clicked );
setWindowTitle( QStringLiteral( "Save Style in Database" ) );
mDescriptionEdit->setTabChangesFocus( true );
setTabOrder( mNameEdit, mDescriptionEdit );
setTabOrder( mDescriptionEdit, mUseAsDefault );
setTabOrder( mUseAsDefault, buttonBox );
QgsSettings settings;
restoreGeometry( settings.value( QStringLiteral( "Windows/saveStyleToDb/geometry" ) ).toByteArray() );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsSaveStyleToDbDialog::showHelp );
}
QgsSaveStyleToDbDialog::~QgsSaveStyleToDbDialog()
{
QgsSettings settings;
settings.setValue( QStringLiteral( "Windows/saveStyleToDb/geometry" ), saveGeometry() );
}
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::mFilePickButton_clicked()
{
QgsSettings myQSettings; // where we keep last used filter in persistent state
QString myLastUsedDir = myQSettings.value( QStringLiteral( "style/lastStyleDir" ), QDir::homePath() ).toString();
QString myFileName = QFileDialog::getOpenFileName( this, tr( "Attach Qt Designer UI File" ), myLastUsedDir, tr( "Qt Designer UI file .ui" ) + " (*.ui)" );
if ( myFileName.isNull() )
{
return;
}
QFileInfo myFI( myFileName );
QFile uiFile( myFI.filePath() );
QString myPath = myFI.path();
myQSettings.setValue( QStringLiteral( "style/lastStyleDir" ), myPath );
if ( uiFile.open( QIODevice::ReadOnly ) )
{
QString content( uiFile.readAll() );
QDomDocument doc;
if ( !doc.setContent( content ) || doc.documentElement().tagName().compare( QLatin1String( "ui" ) ) )
{
QMessageBox::warning( this, tr( "Attach UI File" ),
tr( "The selected file does not appear to be a valid Qt Designer UI file." ) );
return;
}
mUIFileContent = content;
mFileNameLabel->setText( myFI.fileName() );
}
}
void QgsSaveStyleToDbDialog::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "introduction/general_tools.html#save-and-share-layer-properties" ) );
}