QGIS API Documentation
2.18.21-Las Palmas (9fba24a)
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 :
[email protected]
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
#include "
qgsproject.h
"
18
#include "
qgslogger.h
"
19
#include "
qgsvectordataprovider.h
"
20
21
#include <QSettings>
22
#include <QComboBox>
23
#include <QPushButton>
24
#include <QLabel>
25
#include <QLayout>
26
#include <QTextCodec>
27
28
QgsEncodingFileDialog::QgsEncodingFileDialog
(
QWidget
* parent,
29
const
QString
& caption,
const
QString
& directory,
30
const
QString
& filter,
const
QString
& encoding )
31
:
QFileDialog
( parent, caption, directory, filter )
32
{
33
mCancelAll =
false
;
34
mCancelAllButton =
nullptr
;
35
mEncodingComboBox =
new
QComboBox
(
this
);
36
QLabel
* l =
new
QLabel
(
tr
(
"Encoding:"
),
this
);
37
layout
()->
addWidget
( l );
38
layout
()->
addWidget
( mEncodingComboBox );
39
40
mEncodingComboBox->
addItems
(
QgsVectorDataProvider::availableEncodings
() );
41
42
// Use default encoding if none supplied
43
QString
enc =
encoding
;
44
if
( encoding.
isEmpty
() )
45
{
46
QSettings
settings;
47
enc = settings.
value
(
"/UI/encoding"
,
"System"
).
toString
();
48
}
49
50
// The specified decoding is added if not existing alread, and then set current.
51
// This should select it.
52
int
encindex = mEncodingComboBox->
findText
( enc );
53
if
( encindex < 0 )
54
{
55
mEncodingComboBox->
insertItem
( 0, enc );
56
encindex = 0;
57
}
58
mEncodingComboBox->
setCurrentIndex
( encindex );
59
60
// if this dialog is being invoked from QgisApp::findFiles_(), then we
61
// need to force selection of the first filter since that corresponds to
62
// the file name we're looking for; even if we're not here from
63
// findFiles_(), it won't hurt to force selection of the first file filter
64
selectNameFilter
(
nameFilters
().at( 0 ) );
65
66
// Connect our slot to get a signal when the user is done with the file dialog
67
connect
(
this
, SIGNAL(
accepted
() ),
this
, SLOT(
saveUsedEncoding
() ) );
68
69
70
}
71
72
QgsEncodingFileDialog::~QgsEncodingFileDialog
()
73
{
74
75
}
76
77
QString
QgsEncodingFileDialog::encoding
()
const
78
{
79
return
mEncodingComboBox->
currentText
();
80
}
81
82
void
QgsEncodingFileDialog::saveUsedEncoding
()
83
{
84
QSettings
settings;
85
settings.
setValue
(
"/UI/encoding"
,
encoding
() );
86
QgsDebugMsg
(
QString
(
"Set encoding "
+
encoding
() +
" as default."
) );
87
}
88
89
void
QgsEncodingFileDialog::addCancelAll
()
90
{
91
if
( ! mCancelAllButton )
92
{
93
mCancelAllButton =
new
QPushButton
(
tr
(
"Cancel &All"
),
nullptr
);
94
layout
()->
addWidget
( mCancelAllButton );
// Ownership transfered, no need to delete later on
95
connect
( mCancelAllButton, SIGNAL( clicked() ),
this
, SLOT(
pbnCancelAll_clicked
() ) );
96
}
97
}
98
99
bool
QgsEncodingFileDialog::cancelAll
()
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
}
QWidget::layout
QLayout * layout() const
QgsEncodingFileDialog::encoding
QString encoding() const
Returns a string describing the chosen encoding.
Definition:
qgsencodingfiledialog.cpp:77
QWidget
qgsproject.h
qgsencodingfiledialog.h
QDialog::reject
virtual void reject()
QgsDebugMsg
#define QgsDebugMsg(str)
Definition:
qgslogger.h:33
QDialog::accepted
void accepted()
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
QComboBox::insertItem
void insertItem(int index, const QString &text, const QVariant &userData)
qgsvectordataprovider.h
QgsVectorDataProvider::availableEncodings
static const QStringList & availableEncodings()
Returns a list of available encodings.
Definition:
qgsvectordataprovider.cpp:535
QSettings::setValue
void setValue(const QString &key, const QVariant &value)
QComboBox::findText
int findText(const QString &text, QFlags< Qt::MatchFlag > flags) const
QFileDialog
QString::isEmpty
bool isEmpty() const
QString
QLayout::addWidget
void addWidget(QWidget *w)
QgsEncodingFileDialog::~QgsEncodingFileDialog
~QgsEncodingFileDialog()
Definition:
qgsencodingfiledialog.cpp:72
QSettings
QgsEncodingFileDialog::addCancelAll
void addCancelAll()
Adds a 'Cancel All' button for the user to click.
Definition:
qgsencodingfiledialog.cpp:89
QFileDialog::nameFilters
QStringList nameFilters() const
QSettings::value
QVariant value(const QString &key, const QVariant &defaultValue) const
QgsEncodingFileDialog::QgsEncodingFileDialog
QgsEncodingFileDialog(QWidget *parent=nullptr, const QString &caption=QString(), const QString &directory=QString(), const QString &filter=QString(), const QString &encoding=QString())
Definition:
qgsencodingfiledialog.cpp:28
QComboBox::setCurrentIndex
void setCurrentIndex(int index)
QgsEncodingFileDialog::saveUsedEncoding
void saveUsedEncoding()
Definition:
qgsencodingfiledialog.cpp:82
QPushButton
QComboBox::addItems
void addItems(const QStringList &texts)
QFileDialog::selectNameFilter
void selectNameFilter(const QString &filter)
QgsEncodingFileDialog::cancelAll
bool cancelAll()
Returns true if the user clicked 'Cancel All'.
Definition:
qgsencodingfiledialog.cpp:99
QComboBox::currentText
currentText
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
QVariant::toString
QString toString() const
QgsEncodingFileDialog::pbnCancelAll_clicked
void pbnCancelAll_clicked()
Definition:
qgsencodingfiledialog.cpp:104
qgslogger.h
QComboBox
Generated on Sun Jun 24 2018 11:42:48 for QGIS API Documentation by
1.8.13