Gui: refactoring: move duplicated code to DockWindowManager::activate()
This commit is contained in:
@@ -23,8 +23,6 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <QAction>
|
||||
# include <QDockWidget>
|
||||
#endif
|
||||
|
||||
#include <App/DocumentObject.h>
|
||||
@@ -169,19 +167,8 @@ void StdCmdSendToPythonConsole::activated(int iMsg)
|
||||
//show the python console if it's not already visible, and set the keyboard focus to it
|
||||
QWidget* pc = DockWindowManager::instance()->getDockWindow("Python console");
|
||||
PythonConsole *pcPython = qobject_cast<PythonConsole*>(pc);
|
||||
if (pcPython){
|
||||
QDockWidget* dw = nullptr;
|
||||
QWidget* par = pcPython->parentWidget();
|
||||
while (par){
|
||||
dw = qobject_cast<QDockWidget*>(par);
|
||||
if (dw){
|
||||
break;
|
||||
}
|
||||
par = par->parentWidget();
|
||||
}
|
||||
if (dw && !dw->toggleViewAction()->isChecked()){
|
||||
dw->toggleViewAction()->activate(QAction::Trigger);
|
||||
}
|
||||
if (pcPython) {
|
||||
DockWindowManager::instance()->activate(pcPython);
|
||||
pcPython->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,6 +239,26 @@ void DockWindowManager::removeDockWindow(QWidget* widget)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the corresponding dock widget isn't visible then activate it.
|
||||
*/
|
||||
void DockWindowManager::activate(QWidget* widget)
|
||||
{
|
||||
QDockWidget* dw = nullptr;
|
||||
QWidget* par = widget->parentWidget();
|
||||
while (par) {
|
||||
dw = qobject_cast<QDockWidget*>(par);
|
||||
if (dw) {
|
||||
break;
|
||||
}
|
||||
par = par->parentWidget();
|
||||
}
|
||||
|
||||
if (dw && !dw->toggleViewAction()->isChecked()) {
|
||||
dw->toggleViewAction()->activate(QAction::Trigger);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the window title for the dockable windows.
|
||||
*/
|
||||
|
||||
@@ -25,8 +25,11 @@
|
||||
#define GUI_DOCKWINDOWMANAGER_H
|
||||
|
||||
#include <QStringList>
|
||||
#include <QObject>
|
||||
#include <FCGlobal.h>
|
||||
|
||||
class QDockWidget;
|
||||
class QWidget;
|
||||
|
||||
namespace Gui {
|
||||
|
||||
@@ -57,7 +60,7 @@ private:
|
||||
* Class that manages the widgets inside a QDockWidget.
|
||||
* \author Werner Mayer
|
||||
*/
|
||||
class GuiExport DockWindowManager : QObject
|
||||
class GuiExport DockWindowManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -86,6 +89,8 @@ public:
|
||||
QWidget* getDockWindow(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
|
||||
void activate(QWidget* widget);
|
||||
|
||||
void saveState();
|
||||
void loadState();
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#include <Base/Interpreter.h>
|
||||
#include "ReportView.h"
|
||||
#include "DockWindowManager.h"
|
||||
#include "FileDialog.h"
|
||||
#include "PythonConsole.h"
|
||||
#include "PythonConsolePy.h"
|
||||
@@ -245,20 +246,10 @@ ReportOutputObserver::ReportOutputObserver(ReportOutput *report)
|
||||
this->reportView = report;
|
||||
}
|
||||
|
||||
void ReportOutputObserver::showReportView(){
|
||||
void ReportOutputObserver::showReportView()
|
||||
{
|
||||
// get the QDockWidget parent of the report view
|
||||
QDockWidget* dw = nullptr;
|
||||
QWidget* par = reportView->parentWidget();
|
||||
while (par) {
|
||||
dw = qobject_cast<QDockWidget*>(par);
|
||||
if (dw)
|
||||
break;
|
||||
par = par->parentWidget();
|
||||
}
|
||||
|
||||
if (dw && !dw->toggleViewAction()->isChecked()) {
|
||||
dw->toggleViewAction()->activate(QAction::Trigger);
|
||||
}
|
||||
DockWindowManager::instance()->activate(reportView);
|
||||
}
|
||||
|
||||
bool ReportOutputObserver::eventFilter(QObject *obj, QEvent *event)
|
||||
|
||||
Reference in New Issue
Block a user