diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-08-27 17:23:55 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-09-23 13:28:02 +0000 |
commit | 47e4ae86a8d87ec6388d9423aba86d1498b49012 (patch) | |
tree | 697a90c9e0d3e2213b054dd3a2ad21f9883d99e2 /examples/widgets/tools/settingseditor/locationdialog.cpp | |
parent | 2e02130e394083f8bc7fa04a8e0b6e0c0ed4e1b2 (diff) |
Polish the settings editor example.
- Set QtProject as organization.
- Remove unneeded member variables.
- Use member initialization in the constructor.
- Use new connection syntax in createActions()
to assemble the menu there, removing the createMenus()
function.
- Introduce a QSharedPointer to ensure settings are deleted.
Previously, the settings were parented on the tree widget,
which is a hack of sorts.
- Fix OS X macros.
Change-Id: Ibbc6bfb03eb5c7eda077b1a3aa3f1707667f7f13
Reviewed-by: Topi Reiniƶ <topi.reinio@digia.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
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() |