23 #include <QPushButton> 27 #include <QDialogButtonBox> 30 const QString &caption,
const QString &directory,
31 const QString &filter,
const QString &encoding )
32 : QFileDialog( parent, caption, directory, filter )
35 mCancelAllButton =
nullptr;
36 mEncodingComboBox =
new QComboBox(
this );
37 QLabel *l =
new QLabel( tr(
"Encoding:" ),
this );
39 setOption( QFileDialog::DontUseNativeDialog );
40 layout()->addWidget( l );
41 layout()->addWidget( mEncodingComboBox );
47 if ( encoding.isEmpty() )
50 enc = settings.
value( QStringLiteral(
"UI/encoding" ),
"System" ).toString();
55 int encindex = mEncodingComboBox->findText( enc );
58 mEncodingComboBox->insertItem( 0, enc );
61 mEncodingComboBox->setCurrentIndex( encindex );
67 selectNameFilter( nameFilters().at( 0 ) );
75 return mEncodingComboBox->currentText();
87 if ( ! mCancelAllButton )
89 mCancelAllButton =
new QPushButton( tr(
"Cancel &All" ),
nullptr );
90 layout()->addWidget( mCancelAllButton );
108 : QDialog( parent, flags )
112 c = tr(
"Encoding" );
114 setWindowTitle( tr(
"Select Encoding" ) );
116 QVBoxLayout *layout =
new QVBoxLayout();
117 layout->setMargin( 6 );
119 mEncodingComboBox =
new QComboBox(
this );
120 QLabel *l =
new QLabel( c,
this );
122 QHBoxLayout *hLayout =
new QHBoxLayout();
123 hLayout->addWidget( l );
124 hLayout->addWidget( mEncodingComboBox, 1 );
125 layout->addLayout( hLayout );
127 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
128 Qt::Horizontal,
this );
129 buttonBox->button( QDialogButtonBox::Ok )->setDefault(
true );
130 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
131 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
132 layout->addWidget( buttonBox );
135 mEncodingComboBox->addItem( tr(
"System" ) );
140 if ( encoding.isEmpty() )
143 enc = settings.
value( QStringLiteral(
"UI/encoding" ),
"System" ).toString();
151 return mEncodingComboBox->currentText();
159 int encindex = mEncodingComboBox->findText( encoding );
162 mEncodingComboBox->insertItem( 0, encoding );
165 mEncodingComboBox->setCurrentIndex( encindex );
This class is a composition of two QSettings instances:
void setEncoding(const QString &encoding)
Sets the encoding selected within the dialog.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QgsEncodingSelectionDialog(QWidget *parent=nullptr, const QString &caption=QString(), const QString &encoding=QString(), Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsEncodingSelectionDialog.
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
QString encoding() const
Returns the encoding selected within the dialog.
QString encoding() const
Returns a string describing the chosen encoding.
void addCancelAll()
Adds a 'Cancel All' button for the user to click.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QgsEncodingFileDialog(QWidget *parent=nullptr, const QString &caption=QString(), const QString &directory=QString(), const QString &filter=QString(), const QString &encoding=QString())
Constructor for QgsEncodingFileDialog.
bool cancelAll()
Returns true if the user clicked 'Cancel All'.
void pbnCancelAll_clicked()
static QStringList availableEncodings()
Returns a list of available encodings.