From ba0cd9ba655c6543d2f9c2a46a3ecf0b6da98f1d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 26 Jul 2018 17:15:55 +0200 Subject: Cleanup code style (C++11, casts, etc) --- src/dialog.cpp | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'src/dialog.cpp') diff --git a/src/dialog.cpp b/src/dialog.cpp index 6250114..8399e62 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -100,12 +100,8 @@ Dialog::~Dialog() { void Dialog::changeEvent(QEvent *e) { QDialog::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: + if (e->type() == QEvent::LanguageChange) { ui->retranslateUi(this); - break; - default: - break; } } @@ -117,11 +113,11 @@ void Dialog::on_treeView_doubleClicked(const QModelIndex& index) SessionTreeItem* item = static_cast(index.internalPointer()); - if (item == NULL) + if (item == nullptr) return; // do nothing if cast failed const Session* s(item->session()); - if (s == NULL) // no valid session has been selected, do nothing + if (s == nullptr) // no valid session has been selected, do nothing return; // These two are up here in case run-virt cares... @@ -173,13 +169,13 @@ void Dialog::on_treeView_doubleClicked(const QModelIndex& index) if (pid == 0) { // At this point we are executing as the 2nd child process // Replace this clone with the process we'd like to start - char const * const args[] = {VMCHOOSER_SESSION_START_SCRIPT, NULL}; - execv(VMCHOOSER_SESSION_START_SCRIPT, (char**)args); + char * const args[] = { strdup(VMCHOOSER_SESSION_START_SCRIPT), nullptr }; + execv(VMCHOOSER_SESSION_START_SCRIPT, args); } _exit(0); // Dont use exit hooks } // Wait and cleanup the intermediate process - waitpid(pid, NULL, 0); + waitpid(pid, nullptr, 0); } ChooserSettings::setSetting("last-session", (s->shortDescription())); ChooserSettings::setSetting("last-tab", QString::number(activeTab_)); @@ -195,7 +191,7 @@ void Dialog::on_treeView_doubleClicked(const QModelIndex& index) void Dialog::on_treeView_expanded(const QModelIndex& index) { SessionTreeItem* item = static_cast(index.internalPointer()); - if (item->session() == NULL && item->sectionType() != SECTION_FOR_LOCATION) { + if (item->session() == nullptr && item->sectionType() != SECTION_FOR_LOCATION) { genericExpandedOnce_ = true; } } @@ -262,7 +258,7 @@ bool Dialog::selectSession(const QString& name) { continue; SessionTreeItem* item = static_cast(index.internalPointer()); const Session* s = item->session(); - if (s == NULL) { + if (s == nullptr) { continue; } if (s->shortDescription() == name) { @@ -296,7 +292,7 @@ bool Dialog::selectSessionByUuid(const QString& name) { QModelIndex index(model_[tab]->index(j, 0, section)); SessionTreeItem* item = static_cast(index.internalPointer()); const Session* s(item->session()); - if (s == NULL) { + if (s == nullptr) { continue; } /* TODO: implement this here */ @@ -457,7 +453,7 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) { // TODO: Filter user's classes and add to tab[TAB_MY_COURSES] bool showEdit = false; for (QList::const_iterator it = sessions.begin(); it != sessions.end(); ++it) { - if (((VSession*)(*it))->canEdit()) { + if (reinterpret_cast(*it)->canEdit()) { showEdit = true; break; } @@ -485,7 +481,7 @@ void Dialog::mousePressEvent(QMouseEvent * event) { void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelIndex&) { SessionTreeItem* item = static_cast(current.internalPointer()); - if (item == NULL) { + if (item == nullptr) { ui->chkAdminMode->setEnabled(false); return; } @@ -500,7 +496,7 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI QString description; if (s->type() == Session::VSESSION) { - const VSession* vs = (VSession*) s; + const VSession* vs = reinterpret_cast(s); ui->label_creator->setText(vs->getAttribute("creator", "param")); ui->label_creator->setToolTip(vs->getAttribute("creator", "param")); @@ -582,25 +578,25 @@ void Dialog::on_filterEdit_textEdited() { void Dialog::on_filterEdit_textChanged() { if (activeTab_ < 0 || activeTab_ >= TAB_COUNT) return; - SessionTreeModel *newModel = NULL; + SessionTreeModel *newModel = nullptr; // filter the current model if (!ui->filterEdit->text().isEmpty() && ui->filterEdit->text().replace(" ", "").length() > 2) { - if (model_[activeTab_] != NULL) { + if (model_[activeTab_] != nullptr) { newModel = new SessionTreeModel(this); newModel->addItems(this->model_[activeTab_]->lookForItem(ui->filterEdit->text())); } } - if (newModel == NULL) { + if (newModel == nullptr) { newModel = model_[activeTab_]; } - if (newModel != NULL) { + if (newModel != nullptr) { setListModel(newModel); } } void Dialog::setListModel(SessionTreeModel *model) { - QAbstractItemModel *old = NULL; + QAbstractItemModel *old = nullptr; if (ui->treeView->model() == model_[0] || ui->treeView->model() == model_[1] || ui->treeView->model() == model_[2]) { } else { old = ui->treeView->model(); @@ -617,7 +613,7 @@ void Dialog::setListModel(SessionTreeModel *model) { ui->treeView->collapse(index); } } - if (old != NULL) { + if (old != nullptr) { old->deleteLater(); } @@ -674,7 +670,7 @@ void Dialog::addNewsAfterDownload(QNetworkReply* reply) { QDomElement timeNode = newsNode.firstChildElement("date"); QDomElement infoNode = newsNode.firstChildElement("info"); QDateTime timestamp; - timestamp.setTime_t(timeNode.text().toInt()); + timestamp.setTime_t(timeNode.text().toUInt()); if (timeNode.isNull() || infoNode.isNull()) { ui->newsTextBrowser->setText(QCoreApplication::instance()->translate("Dialog", "Could not get news. (//news/date or //news/info missing)")); @@ -778,6 +774,7 @@ void Dialog::keyPressEvent(QKeyEvent* event) { case Qt::Key_Return: this->on_pushButtonStart_clicked(); break; case Qt::Key_Escape: this->on_pushButtonAbort_clicked(); break; case Qt::Key_H: this->on_helpNewsButton_clicked(); break; + default: break; } QDialog::keyPressEvent(event); } -- cgit v1.2.3-55-g7522