diff options
Diffstat (limited to 'examples/widgets/tools/settingseditor/locationdialog.cpp')
-rw-r--r-- | examples/widgets/tools/settingseditor/locationdialog.cpp | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/examples/widgets/tools/settingseditor/locationdialog.cpp b/examples/widgets/tools/settingseditor/locationdialog.cpp index 31c221f5d9..ad7f7e2ce5 100644 --- a/examples/widgets/tools/settingseditor/locationdialog.cpp +++ b/examples/widgets/tools/settingseditor/locationdialog.cpp @@ -54,17 +54,18 @@ LocationDialog::LocationDialog(QWidget *parent) scopeComboBox->addItem(tr("System")); organizationComboBox = new QComboBox; - organizationComboBox->addItem(tr("Qt")); + organizationComboBox->addItem(tr("QtProject")); organizationComboBox->setEditable(true); applicationComboBox = new QComboBox; applicationComboBox->addItem(tr("Any")); + applicationComboBox->addItem(tr("Qt Creator")); applicationComboBox->addItem(tr("Application Example")); applicationComboBox->addItem(tr("Assistant")); applicationComboBox->addItem(tr("Designer")); applicationComboBox->addItem(tr("Linguist")); applicationComboBox->setEditable(true); - applicationComboBox->setCurrentIndex(3); + applicationComboBox->setCurrentIndex(1); formatLabel = new QLabel(tr("&Format:")); formatLabel->setBuddy(formatComboBox); @@ -91,28 +92,30 @@ LocationDialog::LocationDialog(QWidget *parent) locationsTable->setHorizontalHeaderLabels(labels); locationsTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); locationsTable->horizontalHeader()->resizeSection(1, 180); + connect(locationsTable, &QTableWidget::itemActivated, this, &LocationDialog::itemActivated); - buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok - | QDialogButtonBox::Cancel); + buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - connect(formatComboBox, SIGNAL(activated(int)), - this, SLOT(updateLocationsTable())); - connect(scopeComboBox, SIGNAL(activated(int)), - this, SLOT(updateLocationsTable())); + typedef void (QComboBox::*QComboIntSignal)(int); + connect(formatComboBox, static_cast<QComboIntSignal>(&QComboBox::activated), + this, &LocationDialog::updateLocationsTable); + connect(scopeComboBox, static_cast<QComboIntSignal>(&QComboBox::activated), + this, &LocationDialog::updateLocationsTable); connect(organizationComboBox->lineEdit(), - SIGNAL(editingFinished()), - this, SLOT(updateLocationsTable())); + &QLineEdit::editingFinished, + this, &LocationDialog::updateLocationsTable); connect(applicationComboBox->lineEdit(), - SIGNAL(editingFinished()), - this, SLOT(updateLocationsTable())); - connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); - connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); - - QVBoxLayout *locationsLayout = new QVBoxLayout; + &QLineEdit::editingFinished, + this, &LocationDialog::updateLocationsTable); + connect(applicationComboBox, static_cast<QComboIntSignal>(&QComboBox::activated), + this, &LocationDialog::updateLocationsTable); + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + + QVBoxLayout *locationsLayout = new QVBoxLayout(locationsGroupBox); locationsLayout->addWidget(locationsTable); - locationsGroupBox->setLayout(locationsLayout); - QGridLayout *mainLayout = new QGridLayout; + QGridLayout *mainLayout = new QGridLayout(this); mainLayout->addWidget(formatLabel, 0, 0); mainLayout->addWidget(formatComboBox, 0, 1); mainLayout->addWidget(scopeLabel, 1, 0); @@ -123,7 +126,6 @@ LocationDialog::LocationDialog(QWidget *parent) mainLayout->addWidget(applicationComboBox, 3, 1); mainLayout->addWidget(locationsGroupBox, 4, 0, 1, 2); mainLayout->addWidget(buttonBox, 5, 0, 1, 2); - setLayout(mainLayout); updateLocationsTable(); @@ -155,11 +157,16 @@ QString LocationDialog::organization() const QString LocationDialog::application() const { if (applicationComboBox->currentText() == tr("Any")) - return ""; + return QString(); else return applicationComboBox->currentText(); } +void LocationDialog::itemActivated(QTableWidgetItem *) +{ + buttonBox->button(QDialogButtonBox::Ok)->animateClick(); +} + void LocationDialog::updateLocationsTable() { locationsTable->setUpdatesEnabled(false); @@ -184,8 +191,7 @@ void LocationDialog::updateLocationsTable() int row = locationsTable->rowCount(); locationsTable->setRowCount(row + 1); - QTableWidgetItem *item0 = new QTableWidgetItem; - item0->setText(settings.fileName()); + QTableWidgetItem *item0 = new QTableWidgetItem(QDir::toNativeSeparators(settings.fileName())); QTableWidgetItem *item1 = new QTableWidgetItem; bool disable = (settings.childKeys().isEmpty() |