From a356ccd0ad521c72c5f059aeddea1b6fd9adaf78 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 1 Aug 2022 12:46:43 +0200 Subject: [PATCH] ProjectExplorer: Use LayoutBuilder for session management Change-Id: I18de9933c52b147c7c2bd1f75852531e787937d8 Reviewed-by: Alessandro Portale --- src/plugins/projectexplorer/CMakeLists.txt | 2 +- .../projectexplorer/projectexplorer.cpp | 3 + .../projectexplorer/projectexplorer.qbs | 2 +- src/plugins/projectexplorer/sessiondialog.cpp | 139 +++++++++----- src/plugins/projectexplorer/sessiondialog.h | 15 +- src/plugins/projectexplorer/sessiondialog.ui | 172 ------------------ src/plugins/projectexplorer/sessionview.h | 9 +- 7 files changed, 114 insertions(+), 228 deletions(-) delete mode 100644 src/plugins/projectexplorer/sessiondialog.ui diff --git a/src/plugins/projectexplorer/CMakeLists.txt b/src/plugins/projectexplorer/CMakeLists.txt index f3190f0688a..d574562930f 100644 --- a/src/plugins/projectexplorer/CMakeLists.txt +++ b/src/plugins/projectexplorer/CMakeLists.txt @@ -160,7 +160,7 @@ add_qtc_plugin(ProjectExplorer sanitizerparser.cpp sanitizerparser.h selectablefilesmodel.cpp selectablefilesmodel.h session.cpp session.h - sessiondialog.cpp sessiondialog.h sessiondialog.ui + sessiondialog.cpp sessiondialog.h sessionmodel.cpp sessionmodel.h sessionview.cpp sessionview.h showineditortaskhandler.cpp showineditortaskhandler.h diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 41740260f3e..363d891030b 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -129,8 +129,10 @@ #include #include #include + #include #include + #include #include #include @@ -159,6 +161,7 @@ #include #include #include +#include #include #include #include diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index e8680c9070a..02396ab18ca 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -136,7 +136,7 @@ Project { "session.cpp", "session.h", "sessionmodel.cpp", "sessionmodel.h", "sessionview.cpp", "sessionview.h", - "sessiondialog.cpp", "sessiondialog.h", "sessiondialog.ui", + "sessiondialog.cpp", "sessiondialog.h", "showineditortaskhandler.cpp", "showineditortaskhandler.h", "showoutputtaskhandler.cpp", "showoutputtaskhandler.h", "simpleprojectwizard.cpp", "simpleprojectwizard.h", diff --git a/src/plugins/projectexplorer/sessiondialog.cpp b/src/plugins/projectexplorer/sessiondialog.cpp index a7a1a6fcd4b..9ced9b509ce 100644 --- a/src/plugins/projectexplorer/sessiondialog.cpp +++ b/src/plugins/projectexplorer/sessiondialog.cpp @@ -24,18 +24,22 @@ ****************************************************************************/ #include "sessiondialog.h" + #include "session.h" +#include "sessionview.h" #include +#include +#include +#include +#include #include +#include +#include #include -using namespace ProjectExplorer; -using namespace ProjectExplorer::Internal; - -namespace ProjectExplorer { -namespace Internal { +namespace ProjectExplorer::Internal { class SessionValidator : public QValidator { @@ -83,12 +87,9 @@ void SessionValidator::fixup(QString &input) const SessionNameInputDialog::SessionNameInputDialog(QWidget *parent) : QDialog(parent) { - auto hlayout = new QVBoxLayout(this); - auto label = new QLabel(tr("Enter the name of the session:"), this); - hlayout->addWidget(label); m_newSessionLineEdit = new QLineEdit(this); m_newSessionLineEdit->setValidator(new SessionValidator(this, SessionManager::sessions())); - hlayout->addWidget(m_newSessionLineEdit); + auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); m_okButton = buttons->button(QDialogButtonBox::Ok); m_switchToButton = new QPushButton; @@ -96,10 +97,16 @@ SessionNameInputDialog::SessionNameInputDialog(QWidget *parent) connect(m_switchToButton, &QPushButton::clicked, this, [this] { m_usedSwitchTo = true; }); + + using namespace Utils::Layouting; + Column { + tr("Enter the name of the session:"), + m_newSessionLineEdit, + buttons, + }.attachTo(this); + connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); - hlayout->addWidget(buttons); - setLayout(hlayout); } void SessionNameInputDialog::setActionText(const QString &actionText, const QString &openActionText) @@ -125,58 +132,106 @@ bool SessionNameInputDialog::isSwitchToRequested() const SessionDialog::SessionDialog(QWidget *parent) : QDialog(parent) { - m_ui.setupUi(this); - m_ui.sessionView->setActivationMode(Utils::DoubleClickActivation); + resize(550, 400); + setWindowTitle(tr("Session Manager")); - connect(m_ui.btCreateNew, &QAbstractButton::clicked, - m_ui.sessionView, &SessionView::createNewSession); - connect(m_ui.btClone, &QAbstractButton::clicked, - m_ui.sessionView, &SessionView::cloneCurrentSession); - connect(m_ui.btDelete, &QAbstractButton::clicked, - m_ui.sessionView, &SessionView::deleteSelectedSessions); - connect(m_ui.btSwitch, &QAbstractButton::clicked, - m_ui.sessionView, &SessionView::switchToCurrentSession); - connect(m_ui.btRename, &QAbstractButton::clicked, - m_ui.sessionView, &SessionView::renameCurrentSession); - connect(m_ui.sessionView, &SessionView::sessionActivated, - m_ui.sessionView, &SessionView::switchToCurrentSession); - connect(m_ui.sessionView, &SessionView::sessionsSelected, - this, &SessionDialog::updateActions); - connect(m_ui.sessionView, &SessionView::sessionSwitched, - this, &QDialog::reject); + auto sessionView = new SessionView(this); + sessionView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + sessionView->setActivationMode(Utils::DoubleClickActivation); - m_ui.whatsASessionLabel->setOpenExternalLinks(true); + auto createNewButton = new QPushButton(tr("&New")); + + m_renameButton = new QPushButton(tr("&Rename")); + m_cloneButton = new QPushButton(tr("C&lone")); + m_deleteButton = new QPushButton(tr("&Delete")); + m_switchButton = new QPushButton(tr("&Switch To")); + + m_autoLoadCheckBox = new QCheckBox(tr("Restore last session on startup")); + + auto line = new QFrame(this); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + + auto buttonBox = new QDialogButtonBox(this); + buttonBox->setStandardButtons(QDialogButtonBox::Close); + + m_switchButton->setDefault(true); + + // FIXME: Simplify translator's work. + auto whatsASessionLabel = new QLabel( + tr("" + "What is a Session?")); + whatsASessionLabel->setOpenExternalLinks(true); + + using namespace Utils::Layouting; + + Column { + Row { + sessionView, + Column { + createNewButton, + m_renameButton, + m_cloneButton, + m_deleteButton, + m_switchButton, + st + } + }, + m_autoLoadCheckBox, + line, + Row { whatsASessionLabel, buttonBox }, + }.attachTo(this); + + connect(createNewButton, &QAbstractButton::clicked, + sessionView, &SessionView::createNewSession); + connect(m_cloneButton, &QAbstractButton::clicked, + sessionView, &SessionView::cloneCurrentSession); + connect(m_deleteButton, &QAbstractButton::clicked, + sessionView, &SessionView::deleteSelectedSessions); + connect(m_switchButton, &QAbstractButton::clicked, + sessionView, &SessionView::switchToCurrentSession); + connect(m_renameButton, &QAbstractButton::clicked, + sessionView, &SessionView::renameCurrentSession); + connect(sessionView, &SessionView::sessionActivated, + sessionView, &SessionView::switchToCurrentSession); + + connect(sessionView, &SessionView::sessionsSelected, + this, &SessionDialog::updateActions); + connect(sessionView, &SessionView::sessionSwitched, + this, &QDialog::reject); + + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); } void SessionDialog::setAutoLoadSession(bool check) { - m_ui.autoLoadCheckBox->setChecked(check); + m_autoLoadCheckBox->setChecked(check); } bool SessionDialog::autoLoadSession() const { - return m_ui.autoLoadCheckBox->checkState() == Qt::Checked; + return m_autoLoadCheckBox->checkState() == Qt::Checked; } void SessionDialog::updateActions(const QStringList &sessions) { if (sessions.isEmpty()) { - m_ui.btDelete->setEnabled(false); - m_ui.btRename->setEnabled(false); - m_ui.btClone->setEnabled(false); - m_ui.btSwitch->setEnabled(false); + m_deleteButton->setEnabled(false); + m_renameButton->setEnabled(false); + m_cloneButton->setEnabled(false); + m_switchButton->setEnabled(false); return; } const bool defaultIsSelected = sessions.contains("default"); const bool activeIsSelected = Utils::anyOf(sessions, [](const QString &session) { return session == SessionManager::activeSession(); }); - m_ui.btDelete->setEnabled(!defaultIsSelected && !activeIsSelected); - m_ui.btRename->setEnabled(sessions.size() == 1 && !defaultIsSelected); - m_ui.btClone->setEnabled(sessions.size() == 1); - m_ui.btSwitch->setEnabled(sessions.size() == 1); + m_deleteButton->setEnabled(!defaultIsSelected && !activeIsSelected); + m_renameButton->setEnabled(sessions.size() == 1 && !defaultIsSelected); + m_cloneButton->setEnabled(sessions.size() == 1); + m_switchButton->setEnabled(sessions.size() == 1); } -} // namespace Internal -} // namespace ProjectExplorer +} // ProjectExplorer::Internal diff --git a/src/plugins/projectexplorer/sessiondialog.h b/src/plugins/projectexplorer/sessiondialog.h index 701748b55c0..d615d47b683 100644 --- a/src/plugins/projectexplorer/sessiondialog.h +++ b/src/plugins/projectexplorer/sessiondialog.h @@ -25,18 +25,16 @@ #pragma once -#include "ui_sessiondialog.h" - #include #include QT_BEGIN_NAMESPACE +class QCheckBox; class QLineEdit; class QPushButton; QT_END_NAMESPACE -namespace ProjectExplorer { -namespace Internal { +namespace ProjectExplorer::Internal { class SessionDialog : public QDialog { @@ -51,7 +49,11 @@ public: private: void updateActions(const QStringList &sessions); - Ui::SessionDialog m_ui; + QPushButton *m_renameButton; + QPushButton *m_cloneButton; + QPushButton *m_deleteButton; + QPushButton *m_switchButton; + QCheckBox *m_autoLoadCheckBox; }; class SessionNameInputDialog : public QDialog @@ -73,5 +75,4 @@ private: bool m_usedSwitchTo = false; }; -} // namespace Internal -} // namespace ProjectExplorer +} // ProjectExplorer::Internal diff --git a/src/plugins/projectexplorer/sessiondialog.ui b/src/plugins/projectexplorer/sessiondialog.ui deleted file mode 100644 index 62e6c2f13a7..00000000000 --- a/src/plugins/projectexplorer/sessiondialog.ui +++ /dev/null @@ -1,172 +0,0 @@ - - - ProjectExplorer::Internal::SessionDialog - - - - 0 - 0 - 550 - 400 - - - - Session Manager - - - - - - - 1 - 1 - - - - - - - - 0 - - - 0 - - - - - &New - - - - - - - &Rename - - - - - - - C&lone - - - - - - - &Delete - - - - - - - &Switch To - - - true - - - - - - - Qt::Vertical - - - - 85 - 48 - - - - - - - - - - Restore last session on startup - - - - - - - Qt::Horizontal - - - - - - - <a href="qthelp://org.qt-project.qtcreator/doc/creator-project-managing-sessions.html">What is a Session?</a> - - - - - - - - 0 - 0 - - - - Qt::Vertical - - - QDialogButtonBox::Close - - - true - - - - - - - - SessionView - QTreeView -
projectexplorer/sessionview.h
-
-
- - - - buttonBox - rejected() - ProjectExplorer::Internal::SessionDialog - reject() - - - 191 - 244 - - - 114 - 237 - - - - - buttonBox - accepted() - ProjectExplorer::Internal::SessionDialog - accept() - - - 246 - 237 - - - 78 - 216 - - - - -
diff --git a/src/plugins/projectexplorer/sessionview.h b/src/plugins/projectexplorer/sessionview.h index d991dd92d55..c22d3d33647 100644 --- a/src/plugins/projectexplorer/sessionview.h +++ b/src/plugins/projectexplorer/sessionview.h @@ -31,10 +31,10 @@ #include -namespace ProjectExplorer { -namespace Internal { +namespace ProjectExplorer::Internal { -class SessionView : public Utils::TreeView { +class SessionView : public Utils::TreeView +{ Q_OBJECT public: @@ -66,5 +66,4 @@ private: SessionModel m_sessionModel; }; -} // namespace Internal -} // namespace ProjectExplorer +} // ProjectExplorer::Internal