QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgsencodingfiledialog.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsencodingfiledialog.cpp - File dialog which queries the encoding type
3
--------------------------------------
4
Date : 16-Feb-2005
5
Copyright : (C) 2005 by Marco Hugentobler
6
email : marco.hugentobler@autoform.ch
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#include "
qgsencodingfiledialog.h
"
17
18
#include "
qgslogger.h
"
19
#include "
qgsproject.h
"
20
#include "
qgssettings.h
"
21
#include "
qgsvectordataprovider.h
"
22
23
#include <QComboBox>
24
#include <QDialogButtonBox>
25
#include <QLabel>
26
#include <QLayout>
27
#include <QPushButton>
28
#include <QString>
29
#include <QTextCodec>
30
31
#include "moc_qgsencodingfiledialog.cpp"
32
33
using namespace
Qt::StringLiterals;
34
35
QgsEncodingFileDialog::QgsEncodingFileDialog
( QWidget *parent,
const
QString &caption,
const
QString &directory,
const
QString &filter,
const
QString &
encoding
)
36
: QFileDialog( parent, caption, directory, filter )
37
{
38
mCancelAll =
false
;
39
mCancelAllButton =
nullptr
;
40
mEncodingComboBox =
new
QComboBox(
this
);
41
QLabel *l =
new
QLabel( tr(
"Encoding:"
),
this
);
42
43
setOption( QFileDialog::DontUseNativeDialog );
44
layout()->addWidget( l );
45
layout()->addWidget( mEncodingComboBox );
46
47
mEncodingComboBox->addItems(
QgsVectorDataProvider::availableEncodings
() );
48
49
// Use default encoding if none supplied
50
QString enc =
encoding
;
51
if
(
encoding
.isEmpty() )
52
{
53
const
QgsSettings
settings;
54
enc = settings.
value
( u
"UI/encoding"
_s,
"System"
).toString();
55
}
56
57
// The specified decoding is added if not existing already, and then set current.
58
// This should select it.
59
int
encindex = mEncodingComboBox->findText( enc );
60
if
( encindex < 0 )
61
{
62
mEncodingComboBox->insertItem( 0, enc );
63
encindex = 0;
64
}
65
mEncodingComboBox->setCurrentIndex( encindex );
66
67
// if this dialog is being invoked from QgisApp::findFiles_(), then we
68
// need to force selection of the first filter since that corresponds to
69
// the file name we're looking for; even if we're not here from
70
// findFiles_(), it won't hurt to force selection of the first file filter
71
selectNameFilter( nameFilters().at( 0 ) );
72
73
// Connect our slot to get a signal when the user is done with the file dialog
74
connect(
this
, &QDialog::accepted,
this
, &
QgsEncodingFileDialog::saveUsedEncoding
);
75
}
76
77
QString
QgsEncodingFileDialog::encoding
()
const
78
{
79
return
mEncodingComboBox->currentText();
80
}
81
82
void
QgsEncodingFileDialog::saveUsedEncoding
()
83
{
84
QgsSettings
settings;
85
settings.
setValue
( u
"UI/encoding"
_s,
encoding
() );
86
QgsDebugMsgLevel
( u
"Set encoding %1 as default."
_s.arg(
encoding
() ), 2 );
87
}
88
89
void
QgsEncodingFileDialog::addCancelAll
()
90
{
91
if
( !mCancelAllButton )
92
{
93
mCancelAllButton =
new
QPushButton( tr(
"Cancel &All"
),
nullptr
);
94
layout()->addWidget( mCancelAllButton );
// Ownership transferred, no need to delete later on
95
connect( mCancelAllButton, &QAbstractButton::clicked,
this
, &
QgsEncodingFileDialog::pbnCancelAll_clicked
);
96
}
97
}
98
99
bool
QgsEncodingFileDialog::cancelAll
()
const
100
{
101
return
mCancelAll;
102
}
103
104
void
QgsEncodingFileDialog::pbnCancelAll_clicked
()
105
{
106
mCancelAll =
true
;
107
// Now, continue as the user clicked the cancel button
108
reject();
109
}
110
111
QgsEncodingSelectionDialog::QgsEncodingSelectionDialog
( QWidget *parent,
const
QString &caption,
const
QString &
encoding
, Qt::WindowFlags flags )
112
: QDialog( parent, flags )
113
{
114
QString
c
= caption;
115
if
(
c
.isEmpty() )
116
c
= tr(
"Encoding"
);
117
118
setWindowTitle( tr(
"Select Encoding"
) );
119
120
QVBoxLayout *layout =
new
QVBoxLayout();
121
layout->setContentsMargins( 6, 6, 6, 6 );
122
123
mEncodingComboBox =
new
QComboBox(
this
);
124
QLabel *l =
new
QLabel(
c
,
this
);
125
126
QHBoxLayout *hLayout =
new
QHBoxLayout();
127
hLayout->addWidget( l );
128
hLayout->addWidget( mEncodingComboBox, 1 );
129
layout->addLayout( hLayout );
130
131
QDialogButtonBox *buttonBox =
new
QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal,
this
);
132
buttonBox->button( QDialogButtonBox::Ok )->setDefault(
true
);
133
connect( buttonBox, &QDialogButtonBox::rejected,
this
, &QDialog::reject );
134
connect( buttonBox, &QDialogButtonBox::accepted,
this
, &QDialog::accept );
135
layout->addWidget( buttonBox );
136
setLayout( layout );
137
138
mEncodingComboBox->addItem( tr(
"System"
) );
139
mEncodingComboBox->addItems(
QgsVectorDataProvider::availableEncodings
() );
140
141
// Use default encoding if none supplied
142
QString enc =
encoding
;
143
if
(
encoding
.isEmpty() )
144
{
145
const
QgsSettings
settings;
146
enc = settings.
value
( u
"UI/encoding"
_s,
"System"
).toString();
147
}
148
149
setEncoding
( enc );
150
}
151
152
QString
QgsEncodingSelectionDialog::encoding
()
const
153
{
154
return
mEncodingComboBox->currentText();
155
}
156
157
void
QgsEncodingSelectionDialog::setEncoding
(
const
QString &
encoding
)
158
{
159
// The specified decoding is added if not existing already, and then set current.
160
// This should select it.
161
162
int
encindex = mEncodingComboBox->findText(
encoding
);
163
if
( encindex < 0 )
164
{
165
mEncodingComboBox->insertItem( 0,
encoding
);
166
encindex = 0;
167
}
168
mEncodingComboBox->setCurrentIndex( encindex );
169
}
QgsEncodingFileDialog::pbnCancelAll_clicked
void pbnCancelAll_clicked()
Definition
qgsencodingfiledialog.cpp:104
QgsEncodingFileDialog::saveUsedEncoding
void saveUsedEncoding()
Definition
qgsencodingfiledialog.cpp:82
QgsEncodingFileDialog::encoding
QString encoding() const
Returns a string describing the chosen encoding.
Definition
qgsencodingfiledialog.cpp:77
QgsEncodingFileDialog::addCancelAll
void addCancelAll()
Adds a 'Cancel All' button for the user to click.
Definition
qgsencodingfiledialog.cpp:89
QgsEncodingFileDialog::QgsEncodingFileDialog
QgsEncodingFileDialog(QWidget *parent=nullptr, const QString &caption=QString(), const QString &directory=QString(), const QString &filter=QString(), const QString &encoding=QString())
Constructor for QgsEncodingFileDialog.
Definition
qgsencodingfiledialog.cpp:35
QgsEncodingFileDialog::cancelAll
bool cancelAll() const
Returns true if the user clicked 'Cancel All'.
Definition
qgsencodingfiledialog.cpp:99
QgsEncodingSelectionDialog::encoding
QString encoding() const
Returns the encoding selected within the dialog.
Definition
qgsencodingfiledialog.cpp:152
QgsEncodingSelectionDialog::QgsEncodingSelectionDialog
QgsEncodingSelectionDialog(QWidget *parent=nullptr, const QString &caption=QString(), const QString &encoding=QString(), Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsEncodingSelectionDialog.
Definition
qgsencodingfiledialog.cpp:111
QgsEncodingSelectionDialog::setEncoding
void setEncoding(const QString &encoding)
Sets the encoding selected within the dialog.
Definition
qgsencodingfiledialog.cpp:157
QgsSettings
Stores settings for use within QGIS.
Definition
qgssettings.h:68
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition
qgssettings.cpp:169
QgsSettings::setValue
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Definition
qgssettings.cpp:300
QgsVectorDataProvider::availableEncodings
static QStringList availableEncodings()
Returns a list of available encodings.
Definition
qgsvectordataprovider.cpp:781
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition
porting_processing.dox:1
qgsencodingfiledialog.h
qgslogger.h
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition
qgslogger.h:80
qgsproject.h
qgssettings.h
qgsvectordataprovider.h
Generated on
for QGIS API Documentation by
1.17.0