forked from qt-creator/qt-creator
AdvancedDockingSystem: WorkspaceDialog: Use Layouting
Change-Id: I998147908941b4390c810983a5676628f07b1250 Reviewed-by: Henning Gründl <henning.gruendl@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -22,7 +22,6 @@ add_qtc_library(AdvancedDockingSystem
|
||||
workspacedialog.cpp workspacedialog.h
|
||||
workspacemodel.cpp workspacemodel.h
|
||||
workspaceview.cpp workspaceview.h
|
||||
workspacedialog.ui
|
||||
)
|
||||
|
||||
extend_qtc_library(AdvancedDockingSystem
|
||||
|
@@ -34,7 +34,6 @@ QtcLibrary {
|
||||
"workspacedialog.cpp", "workspacedialog.h",
|
||||
"workspacemodel.cpp", "workspacemodel.h",
|
||||
"workspaceview.cpp", "workspaceview.h",
|
||||
"workspacedialog.ui"
|
||||
]
|
||||
}
|
||||
|
||||
|
@@ -4,10 +4,16 @@
|
||||
#include "workspacedialog.h"
|
||||
|
||||
#include "dockmanager.h"
|
||||
#include "workspaceview.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QCheckBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QRegularExpression>
|
||||
#include <QValidator>
|
||||
|
||||
@@ -59,12 +65,9 @@ WorkspaceNameInputDialog::WorkspaceNameInputDialog(DockManager *manager, QWidget
|
||||
: QDialog(parent)
|
||||
, m_manager(manager)
|
||||
{
|
||||
auto hlayout = new QVBoxLayout(this);
|
||||
auto label = new QLabel(tr("Enter the name of the workspace:"), this);
|
||||
hlayout->addWidget(label);
|
||||
m_newWorkspaceLineEdit = new QLineEdit(this);
|
||||
m_newWorkspaceLineEdit->setValidator(new WorkspaceValidator(this, m_manager->workspaces()));
|
||||
hlayout->addWidget(m_newWorkspaceLineEdit);
|
||||
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
||||
Qt::Horizontal,
|
||||
this);
|
||||
@@ -74,8 +77,14 @@ WorkspaceNameInputDialog::WorkspaceNameInputDialog(DockManager *manager, QWidget
|
||||
connect(m_switchToButton, &QPushButton::clicked, [this]() { m_usedSwitchTo = true; });
|
||||
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
hlayout->addWidget(buttons);
|
||||
setLayout(hlayout);
|
||||
|
||||
using namespace Utils::Layouting;
|
||||
|
||||
Column {
|
||||
label,
|
||||
m_newWorkspaceLineEdit,
|
||||
buttons
|
||||
}.attachTo(this);
|
||||
}
|
||||
|
||||
void WorkspaceNameInputDialog::setActionText(const QString &actionText,
|
||||
@@ -103,64 +112,90 @@ bool WorkspaceNameInputDialog::isSwitchToRequested() const
|
||||
WorkspaceDialog::WorkspaceDialog(DockManager *manager, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, m_manager(manager)
|
||||
, m_workspaceView(new WorkspaceView(manager))
|
||||
, m_btCreateNew(new QPushButton(tr("&New")))
|
||||
, m_btRename(new QPushButton(tr("&Rename")))
|
||||
, m_btClone(new QPushButton(tr("C&lone")))
|
||||
, m_btDelete(new QPushButton(tr("&Delete")))
|
||||
, m_btReset(new QPushButton(tr("Reset")))
|
||||
, m_btSwitch(new QPushButton(tr("&Switch To")))
|
||||
, m_btImport(new QPushButton(tr("Import")))
|
||||
, m_btExport(new QPushButton(tr("Export")))
|
||||
, m_autoLoadCheckBox(new QCheckBox(tr("Restore last workspace on startup")))
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
m_ui.workspaceView->setActivationMode(Utils::DoubleClickActivation);
|
||||
setWindowTitle(tr("Workspace Manager"));
|
||||
|
||||
connect(m_ui.btCreateNew,
|
||||
&QAbstractButton::clicked,
|
||||
m_ui.workspaceView,
|
||||
&WorkspaceView::createNewWorkspace);
|
||||
connect(m_ui.btClone,
|
||||
&QAbstractButton::clicked,
|
||||
m_ui.workspaceView,
|
||||
&WorkspaceView::cloneCurrentWorkspace);
|
||||
connect(m_ui.btDelete,
|
||||
&QAbstractButton::clicked,
|
||||
m_ui.workspaceView,
|
||||
&WorkspaceView::deleteSelectedWorkspaces);
|
||||
connect(m_ui.btSwitch,
|
||||
&QAbstractButton::clicked,
|
||||
m_ui.workspaceView,
|
||||
&WorkspaceView::switchToCurrentWorkspace);
|
||||
connect(m_ui.btRename,
|
||||
&QAbstractButton::clicked,
|
||||
m_ui.workspaceView,
|
||||
&WorkspaceView::renameCurrentWorkspace);
|
||||
connect(m_ui.btReset,
|
||||
&QAbstractButton::clicked,
|
||||
m_ui.workspaceView,
|
||||
&WorkspaceView::resetCurrentWorkspace);
|
||||
connect(m_ui.workspaceView,
|
||||
&WorkspaceView::workspaceActivated,
|
||||
m_ui.workspaceView,
|
||||
&WorkspaceView::switchToCurrentWorkspace);
|
||||
connect(m_ui.workspaceView,
|
||||
&WorkspaceView::workspacesSelected,
|
||||
this,
|
||||
&WorkspaceDialog::updateActions);
|
||||
connect(m_ui.btImport,
|
||||
&QAbstractButton::clicked,
|
||||
m_ui.workspaceView,
|
||||
&WorkspaceView::importWorkspace);
|
||||
connect(m_ui.btExport,
|
||||
&QAbstractButton::clicked,
|
||||
m_ui.workspaceView,
|
||||
&WorkspaceView::exportCurrentWorkspace);
|
||||
m_workspaceView->setActivationMode(Utils::DoubleClickActivation);
|
||||
|
||||
m_ui.whatsAWorkspaceLabel->setOpenExternalLinks(true);
|
||||
QLabel *whatsAWorkspaceLabel = new QLabel(tr("<a href=\"qthelp://org.qt-project.qtcreator/doc/"
|
||||
"creator-project-managing-workspaces.html\">What is a Workspace?</a>"));
|
||||
whatsAWorkspaceLabel->setOpenExternalLinks(true);
|
||||
|
||||
updateActions(m_ui.workspaceView->selectedWorkspaces());
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox;
|
||||
buttonBox->setStandardButtons(QDialogButtonBox::Close);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
|
||||
using namespace Utils::Layouting;
|
||||
|
||||
Column {
|
||||
Row {
|
||||
Column {
|
||||
m_workspaceView,
|
||||
m_autoLoadCheckBox
|
||||
},
|
||||
Column {
|
||||
m_btCreateNew,
|
||||
m_btRename,
|
||||
m_btClone,
|
||||
m_btDelete,
|
||||
m_btReset,
|
||||
m_btSwitch,
|
||||
st,
|
||||
m_btImport,
|
||||
m_btExport
|
||||
}
|
||||
},
|
||||
hr,
|
||||
Row {
|
||||
whatsAWorkspaceLabel,
|
||||
buttonBox
|
||||
}
|
||||
}.attachTo(this);
|
||||
|
||||
|
||||
connect(m_btCreateNew, &QAbstractButton::clicked,
|
||||
m_workspaceView, &WorkspaceView::createNewWorkspace);
|
||||
connect(m_btClone, &QAbstractButton::clicked,
|
||||
m_workspaceView, &WorkspaceView::cloneCurrentWorkspace);
|
||||
connect(m_btDelete, &QAbstractButton::clicked,
|
||||
m_workspaceView, &WorkspaceView::deleteSelectedWorkspaces);
|
||||
connect(m_btSwitch, &QAbstractButton::clicked,
|
||||
m_workspaceView, &WorkspaceView::switchToCurrentWorkspace);
|
||||
connect(m_btRename, &QAbstractButton::clicked,
|
||||
m_workspaceView, &WorkspaceView::renameCurrentWorkspace);
|
||||
connect(m_btReset, &QAbstractButton::clicked,
|
||||
m_workspaceView, &WorkspaceView::resetCurrentWorkspace);
|
||||
connect(m_workspaceView, &WorkspaceView::workspaceActivated,
|
||||
m_workspaceView, &WorkspaceView::switchToCurrentWorkspace);
|
||||
connect(m_workspaceView, &WorkspaceView::workspacesSelected,
|
||||
this, &WorkspaceDialog::updateActions);
|
||||
connect(m_btImport, &QAbstractButton::clicked,
|
||||
m_workspaceView, &WorkspaceView::importWorkspace);
|
||||
connect(m_btExport, &QAbstractButton::clicked,
|
||||
m_workspaceView, &WorkspaceView::exportCurrentWorkspace);
|
||||
|
||||
updateActions(m_workspaceView->selectedWorkspaces());
|
||||
}
|
||||
|
||||
void WorkspaceDialog::setAutoLoadWorkspace(bool check)
|
||||
{
|
||||
m_ui.autoLoadCheckBox->setChecked(check);
|
||||
m_autoLoadCheckBox->setChecked(check);
|
||||
}
|
||||
|
||||
bool WorkspaceDialog::autoLoadWorkspace() const
|
||||
{
|
||||
return m_ui.autoLoadCheckBox->checkState() == Qt::Checked;
|
||||
return m_autoLoadCheckBox->checkState() == Qt::Checked;
|
||||
}
|
||||
|
||||
DockManager *WorkspaceDialog::dockManager() const
|
||||
@@ -171,12 +206,12 @@ DockManager *WorkspaceDialog::dockManager() const
|
||||
void WorkspaceDialog::updateActions(const QStringList &workspaces)
|
||||
{
|
||||
if (workspaces.isEmpty()) {
|
||||
m_ui.btDelete->setEnabled(false);
|
||||
m_ui.btRename->setEnabled(false);
|
||||
m_ui.btClone->setEnabled(false);
|
||||
m_ui.btReset->setEnabled(false);
|
||||
m_ui.btSwitch->setEnabled(false);
|
||||
m_ui.btExport->setEnabled(false);
|
||||
m_btDelete->setEnabled(false);
|
||||
m_btRename->setEnabled(false);
|
||||
m_btClone->setEnabled(false);
|
||||
m_btReset->setEnabled(false);
|
||||
m_btSwitch->setEnabled(false);
|
||||
m_btExport->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
const bool presetIsSelected = Utils::anyOf(workspaces, [this](const QString &workspace) {
|
||||
@@ -185,12 +220,12 @@ void WorkspaceDialog::updateActions(const QStringList &workspaces)
|
||||
const bool activeIsSelected = Utils::anyOf(workspaces, [this](const QString &workspace) {
|
||||
return workspace == m_manager->activeWorkspace();
|
||||
});
|
||||
m_ui.btDelete->setEnabled(!activeIsSelected && !presetIsSelected);
|
||||
m_ui.btRename->setEnabled(workspaces.size() == 1 && !presetIsSelected);
|
||||
m_ui.btClone->setEnabled(workspaces.size() == 1);
|
||||
m_ui.btReset->setEnabled(presetIsSelected);
|
||||
m_ui.btSwitch->setEnabled(workspaces.size() == 1);
|
||||
m_ui.btExport->setEnabled(workspaces.size() == 1);
|
||||
m_btDelete->setEnabled(!activeIsSelected && !presetIsSelected);
|
||||
m_btRename->setEnabled(workspaces.size() == 1 && !presetIsSelected);
|
||||
m_btClone->setEnabled(workspaces.size() == 1);
|
||||
m_btReset->setEnabled(presetIsSelected);
|
||||
m_btSwitch->setEnabled(workspaces.size() == 1);
|
||||
m_btExport->setEnabled(workspaces.size() == 1);
|
||||
}
|
||||
|
||||
} // namespace ADS
|
||||
|
@@ -3,12 +3,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ui_workspacedialog.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QString>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QCheckBox;
|
||||
class QLineEdit;
|
||||
class QPushButton;
|
||||
QT_END_NAMESPACE
|
||||
@@ -16,6 +14,7 @@ QT_END_NAMESPACE
|
||||
namespace ADS {
|
||||
|
||||
class DockManager;
|
||||
class WorkspaceView;
|
||||
|
||||
class WorkspaceDialog : public QDialog
|
||||
{
|
||||
@@ -32,9 +31,18 @@ public:
|
||||
private:
|
||||
void updateActions(const QStringList &workspaces);
|
||||
|
||||
Ui::WorkspaceDialog m_ui;
|
||||
|
||||
DockManager *m_manager = nullptr;
|
||||
|
||||
WorkspaceView *m_workspaceView = nullptr;
|
||||
QPushButton *m_btCreateNew = nullptr;
|
||||
QPushButton *m_btRename = nullptr;
|
||||
QPushButton *m_btClone = nullptr;
|
||||
QPushButton *m_btDelete = nullptr;
|
||||
QPushButton *m_btReset = nullptr;
|
||||
QPushButton *m_btSwitch = nullptr;
|
||||
QPushButton *m_btImport = nullptr;
|
||||
QPushButton *m_btExport = nullptr;
|
||||
QCheckBox *m_autoLoadCheckBox = nullptr;
|
||||
};
|
||||
|
||||
class WorkspaceNameInputDialog : public QDialog
|
||||
|
@@ -1,193 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ADS::WorkspaceDialog</class>
|
||||
<widget class="QDialog" name="ADS::WorkspaceDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Workspace Manager</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="WorkspaceView" name="workspaceView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btCreateNew">
|
||||
<property name="text">
|
||||
<string>&New</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btRename">
|
||||
<property name="text">
|
||||
<string>&Rename</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btClone">
|
||||
<property name="text">
|
||||
<string>C&lone</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btDelete">
|
||||
<property name="text">
|
||||
<string>&Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btReset">
|
||||
<property name="text">
|
||||
<string>Reset</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btSwitch">
|
||||
<property name="text">
|
||||
<string>&Switch To</string>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>85</width>
|
||||
<height>48</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btImport">
|
||||
<property name="text">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btExport">
|
||||
<property name="text">
|
||||
<string>Export</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="autoLoadCheckBox">
|
||||
<property name="text">
|
||||
<string>Restore last workspace on startup</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="whatsAWorkspaceLabel">
|
||||
<property name="text">
|
||||
<string><a href="qthelp://org.qt-project.qtcreator/doc/creator-project-managing-workspaces.html">What is a Workspace?</a></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>WorkspaceView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>workspaceview.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ADS::WorkspaceDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>191</x>
|
||||
<y>244</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>114</x>
|
||||
<y>237</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ADS::WorkspaceDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>246</x>
|
||||
<y>237</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>78</x>
|
||||
<y>216</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@@ -10,7 +10,6 @@
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/stringutils.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
namespace ADS {
|
||||
|
@@ -4,7 +4,6 @@
|
||||
#include "workspaceview.h"
|
||||
|
||||
#include "dockmanager.h"
|
||||
#include "workspacedialog.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
@@ -39,17 +38,10 @@ void RemoveItemFocusDelegate::paint(QPainter *painter,
|
||||
QStyledItemDelegate::paint(painter, opt, index);
|
||||
}
|
||||
|
||||
WorkspaceDialog *WorkspaceView::castToWorkspaceDialog(QWidget *widget)
|
||||
{
|
||||
auto dialog = qobject_cast<WorkspaceDialog *>(widget);
|
||||
Q_ASSERT(dialog);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
WorkspaceView::WorkspaceView(QWidget *parent)
|
||||
WorkspaceView::WorkspaceView(DockManager *manager, QWidget *parent)
|
||||
: Utils::TreeView(parent)
|
||||
, m_manager(WorkspaceView::castToWorkspaceDialog(parent)->dockManager())
|
||||
, m_workspaceModel(m_manager)
|
||||
, m_manager(manager)
|
||||
, m_workspaceModel(manager)
|
||||
{
|
||||
setItemDelegate(new RemoveItemFocusDelegate(this));
|
||||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
|
@@ -19,7 +19,7 @@ class WorkspaceView : public Utils::TreeView
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WorkspaceView(QWidget *parent = nullptr);
|
||||
explicit WorkspaceView(DockManager *manager, QWidget *parent = nullptr);
|
||||
|
||||
void createNewWorkspace();
|
||||
void deleteSelectedWorkspaces();
|
||||
@@ -49,8 +49,6 @@ private:
|
||||
|
||||
void deleteWorkspaces(const QStringList &workspaces);
|
||||
|
||||
static WorkspaceDialog *castToWorkspaceDialog(QWidget *widget);
|
||||
|
||||
DockManager *m_manager;
|
||||
WorkspaceModel m_workspaceModel;
|
||||
};
|
||||
|
Reference in New Issue
Block a user