Gui: rework ComboView

This commit is contained in:
wmayer
2022-09-16 00:56:21 +02:00
parent 23c5b330d9
commit 4fcddc71ab
7 changed files with 138 additions and 222 deletions

View File

@@ -23,15 +23,13 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QEvent>
# include <QGridLayout>
# include <QSplitter>
#endif
#include "ComboView.h"
#include "BitmapFactory.h"
#include "Document.h"
#include "PropertyView.h"
#include "Tree.h"
#include "TaskView/TaskView.h"
using namespace Gui;
@@ -40,11 +38,8 @@ using namespace Gui::DockWnd;
/* TRANSLATOR Gui::DockWnd::ComboView */
ComboView::ComboView(bool showModel, Gui::Document* pcDocument, QWidget *parent)
: DockWindow(pcDocument,parent)
, oldTabIndex(0)
, modelIndex(-1)
, taskIndex(-1)
ComboView::ComboView(Gui::Document* pcDocument, QWidget *parent)
: DockWindow(pcDocument, parent)
{
setWindowTitle(tr("Combo View"));
@@ -53,102 +48,20 @@ ComboView::ComboView(bool showModel, Gui::Document* pcDocument, QWidget *parent)
pLayout->setContentsMargins ( 0, 0, 0, 0 );
// tabs to switch between Tree/Properties and TaskPanel
tabs = new QTabWidget ();
tabs->setObjectName(QString::fromUtf8("combiTab"));
tabs->setTabPosition(QTabWidget::North);
pLayout->addWidget( tabs, 0, 0 );
auto splitter = new QSplitter();
pLayout->addWidget( splitter, 0, 0 );
connect(tabs, qOverload<int>(&QTabWidget::currentChanged),
this, &ComboView::onCurrentTabChanged);
if (showModel) {
// splitter between tree and property view
auto splitter = new QSplitter();
splitter->setOrientation(Qt::Vertical);
// splitter between tree and property view
splitter->setOrientation(Qt::Vertical);
tree = new TreePanel("ComboView", this);
splitter->addWidget(tree);
tree = new TreePanel("ComboView", this);
splitter->addWidget(tree);
// property view
prop = new PropertyView(this);
splitter->addWidget(prop);
modelIndex = tabs->addTab(splitter,tr("Model"));
}
else {
tree = nullptr;
prop = nullptr;
}
// task panel
taskPanel = new Gui::TaskView::TaskView(this);
taskIndex = tabs->addTab(taskPanel, tr("Tasks"));
// task panel
//projectView = new Gui::ProjectWidget(this);
//tabs->addTab(projectView, tr("Project"));
// property view
prop = new PropertyView(this);
splitter->addWidget(prop);
}
ComboView::~ComboView() = default;
void ComboView::showDialog(Gui::TaskView::TaskDialog *dlg)
{
static QIcon icon = Gui::BitmapFactory().pixmap("edit-edit.svg");
// switch to the TaskView tab
oldTabIndex = tabs->currentIndex();
tabs->setCurrentIndex(taskIndex);
tabs->setTabIcon(taskIndex, icon);
// set the dialog
taskPanel->showDialog(dlg);
// force to show the combo view
if (modelIndex < 0) {
if (parentWidget())
parentWidget()->raise();
}
}
void ComboView::closeDialog()
{
// close the dialog
taskPanel->removeDialog();
}
void ComboView::closedDialog()
{
static QIcon icon = QIcon();
// dialog has been closed
tabs->setCurrentIndex(oldTabIndex);
tabs->setTabIcon(taskIndex, icon);
}
void ComboView::showTreeView()
{
// switch to the tree view
tabs->setCurrentIndex(modelIndex);
}
void ComboView::showTaskView()
{
// switch to the task view
tabs->setCurrentIndex(taskIndex);
}
void ComboView::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
tabs->setTabText(modelIndex, tr("Model"));
tabs->setTabText(taskIndex, tr("Tasks"));
//tabs->setTabText(2, tr("Project"));
}
DockWindow::changeEvent(e);
}
void ComboView::onCurrentTabChanged(int index)
{
if (index != taskIndex)
oldTabIndex = index;
}
#include "moc_ComboView.cpp"

View File

@@ -56,7 +56,7 @@ namespace Gui {
namespace DockWnd {
/** Combo View
* is a combination of a tree, property and TaskPanel for
* is a combination of a tree and property view for
* integrated user action.
*/
class GuiExport ComboView : public Gui::DockWindow
@@ -68,7 +68,7 @@ public:
* A constructor.
* A more elaborate description of the constructor.
*/
ComboView(bool showModel, Gui::Document* pcDocument, QWidget *parent=nullptr);
ComboView(Gui::Document* pcDocument, QWidget *parent=nullptr);
/**
* A destructor.
@@ -76,33 +76,11 @@ public:
*/
~ComboView() override;
Gui::TaskView::TaskView *getTaskPanel(){return taskPanel;}
QTabWidget* getTabPanel() const { return tabs;}
friend class Gui::ControlSingleton;
void showTreeView();
void showTaskView();
private Q_SLOTS:
void onCurrentTabChanged(int index);
protected:
void showDialog(Gui::TaskView::TaskDialog *dlg);
void closeDialog();
void closedDialog();
void changeEvent(QEvent *e) override;
private:
int oldTabIndex;
int modelIndex;
int taskIndex;
QTabWidget * tabs;
Gui::PropertyView * prop;
Gui::TreePanel * tree;
Gui::TaskView::TaskView * taskPanel;
//Gui::ProjectWidget * projectView;
};
} // namespace DockWnd

View File

@@ -37,6 +37,8 @@
#include <Gui/MainWindow.h>
#include "Control.h"
#include "BitmapFactory.h"
#include "Tree.h"
#include "TaskView/TaskView.h"
@@ -46,10 +48,10 @@ using namespace std;
/* TRANSLATOR Gui::ControlSingleton */
ControlSingleton* ControlSingleton::_pcSingleton = nullptr;
static QPointer<Gui::TaskView::TaskView> _taskPanel = nullptr;
ControlSingleton::ControlSingleton()
: ActiveDialog(nullptr)
, oldTabIndex(-1)
{
}
@@ -58,37 +60,86 @@ ControlSingleton::~ControlSingleton() = default;
Gui::TaskView::TaskView* ControlSingleton::taskPanel() const
{
auto pcComboView = qobject_cast<Gui::DockWnd::ComboView*>
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
// should return the pointer to combo view
if (pcComboView)
return pcComboView->getTaskPanel();
// not all workbenches have the combo view enabled
else if (_taskPanel)
return _taskPanel;
// no task panel available
else
return nullptr;
auto taskView = qobject_cast<Gui::TaskView::TaskView*>
(Gui::DockWindowManager::instance()->getDockWindow("Tasks"));
return taskView;
}
void ControlSingleton::showDockWidget(QWidget* widget)
{
QWidget* parent = widget->parentWidget();
if (parent) {
parent->show();
parent->raise();
}
}
QTabBar* ControlSingleton::findTabBar(QDockWidget* widget) const
{
int count = getMainWindow()->tabifiedDockWidgets(widget).size() + 1;
if (count > 1) {
QList<QTabBar*> bars = getMainWindow()->findChildren<QTabBar*>();
for (auto it : bars) {
if (it->count() == count) {
for (int i = 0; i < count; i++) {
if (it->tabText(i) == widget->windowTitle()) {
return it;
}
}
}
}
}
return nullptr;
}
void ControlSingleton::aboutToShowDialog(QDockWidget* widget)
{
static QIcon icon = Gui::BitmapFactory().pixmap("edit-edit.svg");
QTabBar* bar = findTabBar(widget);
if (bar) {
oldTabIndex = bar->currentIndex();
for (int i = 0; i < bar->count(); i++) {
if (bar->tabText(i) == widget->windowTitle()) {
bar->setTabIcon(i, icon);
break;
}
}
}
widget->show();
widget->raise();
}
void ControlSingleton::aboutToHideDialog(QDockWidget* widget)
{
QTabBar* bar = findTabBar(widget);
if (bar) {
bar->setCurrentIndex(oldTabIndex);
for (int i = 0; i < bar->count(); i++) {
if (bar->tabText(i) == widget->windowTitle()) {
bar->setTabIcon(i, QIcon());
break;
}
}
}
}
void ControlSingleton::showTaskView()
{
auto pcComboView = qobject_cast<Gui::DockWnd::ComboView*>
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
if (pcComboView)
pcComboView->showTaskView();
else if (_taskPanel)
_taskPanel->raise();
Gui::TaskView::TaskView* taskView = taskPanel();
if (taskView) {
showDockWidget(taskView);
}
}
void ControlSingleton::showModelView()
{
auto pcComboView = qobject_cast<Gui::DockWnd::ComboView*>
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
if (pcComboView)
pcComboView->showTreeView();
else if (_taskPanel)
_taskPanel->raise();
auto treeView = qobject_cast<Gui::TreeDockWidget*>
(Gui::DockWindowManager::instance()->getDockWindow("Tree view"));
if (treeView) {
showDockWidget(treeView);
}
}
void ControlSingleton::showDialog(Gui::TaskView::TaskDialog *dlg)
@@ -113,14 +164,15 @@ void ControlSingleton::showDialog(Gui::TaskView::TaskDialog *dlg)
// which may open a transaction but fails when auto transaction is still active.
App::AutoTransaction::setEnable(false);
auto pcComboView = qobject_cast<Gui::DockWnd::ComboView*>
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
Gui::TaskView::TaskView* taskView = taskPanel();
// should return the pointer to combo view
if (pcComboView) {
pcComboView->showDialog(dlg);
if (taskView) {
taskView->showDialog(dlg);
// make sure that the combo view is shown
auto dw = qobject_cast<QDockWidget*>(pcComboView->parentWidget());
auto dw = qobject_cast<QDockWidget*>(taskView->parentWidget());
if (dw) {
aboutToShowDialog(dw);
dw->setVisible(true);
dw->toggleViewAction()->setVisible(true);
dw->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
@@ -132,37 +184,6 @@ void ControlSingleton::showDialog(Gui::TaskView::TaskDialog *dlg)
connect(dlg, &TaskView::TaskDialog::aboutToBeDestroyed,
this, &ControlSingleton::closedDialog);
}
// not all workbenches have the combo view enabled
else if (!_taskPanel) {
auto dw = new QDockWidget();
dw->setWindowTitle(tr("Task panel"));
dw->setFeatures(QDockWidget::DockWidgetMovable);
_taskPanel = new Gui::TaskView::TaskView(dw);
dw->setWidget(_taskPanel);
_taskPanel->showDialog(dlg);
getMainWindow()->addDockWidget(Qt::LeftDockWidgetArea, dw);
connect(dlg, &TaskView::TaskDialog::destroyed, dw, &ControlSingleton::deleteLater);
// if we have the normal tree view available then just tabify with it
QWidget* treeView = Gui::DockWindowManager::instance()->getDockWindow("Tree view");
QDockWidget* par = treeView ? qobject_cast<QDockWidget*>(treeView->parent()) : 0;
if (par && par->isVisible()) {
getMainWindow()->tabifyDockWidget(par, dw);
qApp->processEvents(); // make sure that the task panel is tabified now
dw->show();
dw->raise();
}
}
}
QTabWidget* ControlSingleton::tabPanel() const
{
Gui::DockWnd::ComboView* pcComboView = qobject_cast<Gui::DockWnd::ComboView*>
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
// should return the pointer to combo view
if (pcComboView)
return pcComboView->getTabPanel();
return nullptr;
}
Gui::TaskView::TaskDialog* ControlSingleton::activeDialog() const
@@ -170,22 +191,11 @@ Gui::TaskView::TaskDialog* ControlSingleton::activeDialog() const
return ActiveDialog;
}
Gui::TaskView::TaskView* ControlSingleton::getTaskPanel()
{
// should return the pointer to combo view
auto pcComboView = qobject_cast<Gui::DockWnd::ComboView*>
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
if (pcComboView)
return pcComboView->getTaskPanel();
else
return _taskPanel;
}
void ControlSingleton::accept()
{
Gui::TaskView::TaskView* taskPanel = getTaskPanel();
if (taskPanel) {
taskPanel->accept();
Gui::TaskView::TaskView* taskView = taskPanel();
if (taskView) {
taskView->accept();
qApp->processEvents(QEventLoop::ExcludeUserInputEvents |
QEventLoop::ExcludeSocketNotifiers);
}
@@ -193,9 +203,9 @@ void ControlSingleton::accept()
void ControlSingleton::reject()
{
Gui::TaskView::TaskView* taskPanel = getTaskPanel();
if (taskPanel) {
taskPanel->reject();
Gui::TaskView::TaskView* taskView = taskPanel();
if (taskView) {
taskView->reject();
qApp->processEvents(QEventLoop::ExcludeUserInputEvents |
QEventLoop::ExcludeSocketNotifiers);
}
@@ -203,29 +213,25 @@ void ControlSingleton::reject()
void ControlSingleton::closeDialog()
{
auto pcComboView = qobject_cast<Gui::DockWnd::ComboView*>
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
// should return the pointer to combo view
if (pcComboView)
pcComboView->closeDialog();
else if (_taskPanel)
_taskPanel->removeDialog();
Gui::TaskView::TaskView* taskView = taskPanel();
if (taskView)
taskView->removeDialog();
}
void ControlSingleton::closedDialog()
{
ActiveDialog = nullptr;
auto pcComboView = qobject_cast<Gui::DockWnd::ComboView*>
(Gui::DockWindowManager::instance()->getDockWindow("Combo View"));
// should return the pointer to combo view
assert(pcComboView);
pcComboView->closedDialog();
Gui::TaskView::TaskView* taskView = taskPanel();
assert(taskView);
// make sure that the combo view is shown
auto dw = qobject_cast<QDockWidget*>(pcComboView->parentWidget());
if (dw)
auto dw = qobject_cast<QDockWidget*>(taskView->parentWidget());
if (dw) {
aboutToHideDialog(dw);
dw->setFeatures(QDockWidget::DockWidgetClosable
| QDockWidget::DockWidgetMovable
| QDockWidget::DockWidgetFloatable);
}
}
bool ControlSingleton::isAllowedAlterDocument() const

View File

@@ -32,7 +32,8 @@
#include <Gui/TaskView/TaskDialog.h>
class QTabWidget;
class QDockWidget;
class QTabBar;
namespace App
{
@@ -75,8 +76,6 @@ public:
Gui::TaskView::TaskView* taskPanel() const;
/// raising the model view
void showModelView();
/// get the tab panel
QTabWidget* tabPanel() const;
//@}
/*!
@@ -106,9 +105,6 @@ private Q_SLOTS:
/// This get called by the TaskView when the Dialog is finished
void closedDialog();
private:
Gui::TaskView::TaskView *getTaskPanel();
private:
struct status {
std::bitset<32> StatusBits;
@@ -117,12 +113,17 @@ private:
std::stack<status> StatusStack;
Gui::TaskView::TaskDialog *ActiveDialog;
int oldTabIndex;
private:
/// Construction
ControlSingleton();
/// Destruction
~ControlSingleton() override;
void showDockWidget(QWidget*);
QTabBar* findTabBar(QDockWidget*) const;
void aboutToShowDialog(QDockWidget* widget);
void aboutToHideDialog(QDockWidget* widget);
static ControlSingleton* _pcSingleton;
};

View File

@@ -175,6 +175,20 @@ QWidget* DockWindowManager::getDockWindow(const char* name) const
return nullptr;
}
/**
* Returns the dock widget by name.
* If it does not exist 0 is returned.
*/
QDockWidget* DockWindowManager::getDockContainer(const char* name) const
{
for (QList<QDockWidget*>::Iterator it = d->_dockedWindows.begin(); it != d->_dockedWindows.end(); ++it) {
if ((*it)->objectName() == QLatin1String(name))
return (*it);
}
return nullptr;
}
/**
* Returns a list of all widgets inside the dock windows.
*/

View File

@@ -86,6 +86,8 @@ public:
/// returned from @ref addDockWindow. If you want to access the QDockWidget
/// you get it with parentWidget() of the returned widget.
QWidget* getDockWindow(const char* name) const;
/// Returns the QDockWidget container
QDockWidget* getDockContainer(const char* name) const;
/// Returns a list of all widgets which set to a QDockWidget.
QList<QWidget*> getDockWindows() const;
/// If the corresponding dock widget isn't visible then activate it

View File

@@ -479,6 +479,8 @@ void MainWindow::setupDockWindows()
setupReportView(hiddenDockWindows);
setupPythonConsole(hiddenDockWindows);
setupDAGView(hiddenDockWindows);
this->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
}
bool MainWindow::setupTreeView(const std::string& hiddenDockWindows)
@@ -580,8 +582,8 @@ bool MainWindow::setupComboView(const std::string& hiddenDockWindows, bool enabl
enable = group->GetBool("Enabled", true);
}
auto pcComboView = new ComboView(enable, nullptr, this);
pcComboView->setObjectName(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Combo View")));
auto pcComboView = new ComboView(nullptr, this);
pcComboView->setObjectName(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget", "Model")));
pcComboView->setMinimumWidth(150);
DockWindowManager* pDockMgr = DockWindowManager::instance();