Improve source code layout

This commit is contained in:
Magne Sjaastad 2017-11-29 13:10:46 +01:00
parent c9ae3821e2
commit 6d9891da09

View File

@ -59,18 +59,14 @@
/// ///
//================================================================================================== //==================================================================================================
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RiuMainPlotWindow::RiuMainPlotWindow() RiuMainPlotWindow::RiuMainPlotWindow() : m_activePlotViewWindow(nullptr), m_windowMenu(NULL), m_blockSlotSubWindowActivated(false)
: m_activePlotViewWindow(nullptr),
m_windowMenu(NULL),
m_blockSlotSubWindowActivated(false)
{ {
m_mdiArea = new QMdiArea; m_mdiArea = new QMdiArea;
m_mdiArea->setOption(QMdiArea::DontMaximizeSubWindowOnActivation, true); m_mdiArea->setOption(QMdiArea::DontMaximizeSubWindowOnActivation, true);
connect(m_mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow *)), SLOT(slotSubWindowActivated(QMdiSubWindow*))); connect(m_mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), SLOT(slotSubWindowActivated(QMdiSubWindow*)));
setCentralWidget(m_mdiArea); setCentralWidget(m_mdiArea);
createMenus(); createMenus();
@ -84,8 +80,7 @@ RiuMainPlotWindow::RiuMainPlotWindow()
// Enabling the line below will activate the undo stack // Enabling the line below will activate the undo stack
// When enableUndoCommandSystem is set false, all commands are executed and deleted immediately // When enableUndoCommandSystem is set false, all commands are executed and deleted immediately
//caf::CmdExecCommandManager::instance()->enableUndoCommandSystem(true); // caf::CmdExecCommandManager::instance()->enableUndoCommandSystem(true);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -163,7 +158,8 @@ void RiuMainPlotWindow::closeEvent(QCloseEvent* event)
saveWinGeoAndDockToolBarLayout(); saveWinGeoAndDockToolBarLayout();
if (!app->tryCloseMainWindow()) return; if (!app->tryCloseMainWindow())
return;
app->closeProject(); app->closeProject();
} }
@ -292,7 +288,10 @@ void RiuMainPlotWindow::createToolBars()
CVF_ASSERT(cmdFeatureMgr); CVF_ASSERT(cmdFeatureMgr);
QStringList toolbarNames; QStringList toolbarNames;
toolbarNames << "Standard" << "Window Management" << "View Snapshots" << "View"; toolbarNames << "Standard"
<< "Window Management"
<< "View Snapshots"
<< "View";
for (QString toolbarName : toolbarNames) for (QString toolbarName : toolbarNames)
{ {
@ -354,7 +353,8 @@ void RiuMainPlotWindow::createDockPanels()
connect(m_projectTreeView, SIGNAL(selectionChanged()), this, SLOT(selectedObjectsChanged())); connect(m_projectTreeView, SIGNAL(selectionChanged()), this, SLOT(selectedObjectsChanged()));
m_projectTreeView->treeView()->setContextMenuPolicy(Qt::CustomContextMenu); m_projectTreeView->treeView()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_projectTreeView->treeView(), SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(customMenuRequested(const QPoint&))); connect(m_projectTreeView->treeView(), SIGNAL(customContextMenuRequested(const QPoint&)),
SLOT(customMenuRequested(const QPoint&)));
m_projectTreeView->setUiConfigurationName("PlotWindow"); m_projectTreeView->setUiConfigurationName("PlotWindow");
} }
@ -367,12 +367,12 @@ void RiuMainPlotWindow::createDockPanels()
m_pdmUiPropertyView = new caf::PdmUiPropertyView(dockWidget); m_pdmUiPropertyView = new caf::PdmUiPropertyView(dockWidget);
dockWidget->setWidget(m_pdmUiPropertyView); dockWidget->setWidget(m_pdmUiPropertyView);
m_pdmUiPropertyView->layout()->setContentsMargins(5,0,0,0); m_pdmUiPropertyView->layout()->setContentsMargins(5, 0, 0, 0);
addDockWidget(Qt::LeftDockWidgetArea, dockWidget); addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
} }
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea); setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea);
} }
@ -383,7 +383,7 @@ void RiuMainPlotWindow::createDockPanels()
QMdiSubWindow* RiuMainPlotWindow::findMdiSubWindow(QWidget* viewer) QMdiSubWindow* RiuMainPlotWindow::findMdiSubWindow(QWidget* viewer)
{ {
QList<QMdiSubWindow*> subws = m_mdiArea->subWindowList(); QList<QMdiSubWindow*> subws = m_mdiArea->subWindowList();
int i; int i;
for (i = 0; i < subws.size(); ++i) for (i = 0; i < subws.size(); ++i)
{ {
if (subws[i]->widget() == viewer) if (subws[i]->widget() == viewer)
@ -400,7 +400,7 @@ QMdiSubWindow* RiuMainPlotWindow::findMdiSubWindow(QWidget* viewer)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
QList<QMdiSubWindow*> RiuMainPlotWindow::subWindowList(QMdiArea::WindowOrder order) QList<QMdiSubWindow*> RiuMainPlotWindow::subWindowList(QMdiArea::WindowOrder order)
{ {
return m_mdiArea->subWindowList(order); return m_mdiArea->subWindowList(order);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -434,13 +434,13 @@ void RiuMainPlotWindow::addViewer(QWidget* viewer, const RimMdiWindowGeometry& w
subWin->setAttribute(Qt::WA_DeleteOnClose); // Make sure the contained widget is destroyed when the MDI window is closed subWin->setAttribute(Qt::WA_DeleteOnClose); // Make sure the contained widget is destroyed when the MDI window is closed
subWin->setWidget(viewer); subWin->setWidget(viewer);
QSize subWindowSize; QSize subWindowSize;
QPoint subWindowPos(-1, -1); QPoint subWindowPos(-1, -1);
bool initialStateMaximized = false; bool initialStateMaximized = false;
if (windowsGeometry.isValid()) if (windowsGeometry.isValid())
{ {
subWindowPos = QPoint(windowsGeometry.x, windowsGeometry.y); subWindowPos = QPoint(windowsGeometry.x, windowsGeometry.y);
subWindowSize = QSize(windowsGeometry.width, windowsGeometry.height); subWindowSize = QSize(windowsGeometry.width, windowsGeometry.height);
initialStateMaximized = windowsGeometry.isMaximized; initialStateMaximized = windowsGeometry.isMaximized;
@ -503,10 +503,12 @@ void RiuMainPlotWindow::setPdmRoot(caf::PdmObject* pdmRoot)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuMainPlotWindow::slotSubWindowActivated(QMdiSubWindow* subWindow) void RiuMainPlotWindow::slotSubWindowActivated(QMdiSubWindow* subWindow)
{ {
if (!subWindow) return; if (!subWindow)
return;
RimProject * proj = RiaApplication::instance()->project(); RimProject* proj = RiaApplication::instance()->project();
if (!proj) return; if (!proj)
return;
// Select in Project Tree // Select in Project Tree
@ -528,12 +530,13 @@ void RiuMainPlotWindow::slotSubWindowActivated(QMdiSubWindow* subWindow)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuMainPlotWindow::setActiveViewer(QWidget* viewer) void RiuMainPlotWindow::setActiveViewer(QWidget* viewer)
{ {
m_blockSlotSubWindowActivated = true; m_blockSlotSubWindowActivated = true;
QMdiSubWindow * swin = findMdiSubWindow(viewer); QMdiSubWindow* swin = findMdiSubWindow(viewer);
if (swin) m_mdiArea->setActiveSubWindow(swin); if (swin)
m_mdiArea->setActiveSubWindow(swin);
m_blockSlotSubWindowActivated = false; m_blockSlotSubWindowActivated = false;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -558,7 +561,8 @@ void RiuMainPlotWindow::slotBuildWindowActions()
{ {
if (dock) if (dock)
{ {
if (i == 4) m_windowMenu->addSeparator(); if (i == 4)
m_windowMenu->addSeparator();
m_windowMenu->addAction(dock->toggleViewAction()); m_windowMenu->addAction(dock->toggleViewAction());
++i; ++i;
} }
@ -601,7 +605,6 @@ void RiuMainPlotWindow::selectedObjectsChanged()
{ {
toolBarFields = summaryPlot->summaryCurveCollection()->fieldsToShowInToolbar(); toolBarFields = summaryPlot->summaryCurveCollection()->fieldsToShowInToolbar();
} }
} }
m_summaryPlotToolBar->setFields(toolBarFields); m_summaryPlotToolBar->setFields(toolBarFields);
m_summaryPlotToolBar->updateUi(); m_summaryPlotToolBar->updateUi();
@ -613,10 +616,12 @@ void RiuMainPlotWindow::selectedObjectsChanged()
if (!firstSelectedObject) if (!firstSelectedObject)
{ {
caf::PdmFieldHandle* selectedField = dynamic_cast<caf::PdmFieldHandle*>(uiItems[0]); caf::PdmFieldHandle* selectedField = dynamic_cast<caf::PdmFieldHandle*>(uiItems[0]);
if (selectedField) firstSelectedObject = selectedField->ownerObject(); if (selectedField)
firstSelectedObject = selectedField->ownerObject();
} }
if (!firstSelectedObject) return; if (!firstSelectedObject)
return;
RimViewWindow* selectedWindow = dynamic_cast<RimViewWindow*>(firstSelectedObject); RimViewWindow* selectedWindow = dynamic_cast<RimViewWindow*>(firstSelectedObject);
if (!selectedWindow) if (!selectedWindow)
@ -678,7 +683,8 @@ void RiuMainPlotWindow::restoreTreeViewState()
QString currentIndexString = RiaApplication::instance()->project()->plotWindowCurrentModelIndexPath; QString currentIndexString = RiaApplication::instance()->project()->plotWindowCurrentModelIndexPath;
if (!currentIndexString.isEmpty()) if (!currentIndexString.isEmpty())
{ {
QModelIndex mi = caf::QTreeViewStateSerializer::getModelIndexFromString(m_projectTreeView->treeView()->model(), currentIndexString); QModelIndex mi = caf::QTreeViewStateSerializer::getModelIndexFromString(m_projectTreeView->treeView()->model(),
currentIndexString);
m_projectTreeView->treeView()->setCurrentIndex(mi); m_projectTreeView->treeView()->setCurrentIndex(mi);
} }
} }
@ -720,8 +726,8 @@ void RiuMainPlotWindow::customMenuRequested(const QPoint& pos)
// Qt doc: QAbstractScrollArea and its subclasses that map the context menu event to coordinates of the viewport(). // Qt doc: QAbstractScrollArea and its subclasses that map the context menu event to coordinates of the viewport().
// Since we might get this signal from different treeViews, we need to map the position accordingly. // Since we might get this signal from different treeViews, we need to map the position accordingly.
QObject* senderObj = this->sender(); QObject* senderObj = this->sender();
QTreeView* treeView = dynamic_cast<QTreeView*>(senderObj); QTreeView* treeView = dynamic_cast<QTreeView*>(senderObj);
if (treeView) if (treeView)
{ {
QPoint globalPos = treeView->viewport()->mapToGlobal(pos); QPoint globalPos = treeView->viewport()->mapToGlobal(pos);
@ -751,8 +757,9 @@ void RiuMainPlotWindow::tileWindows()
// Based on workaround described here // Based on workaround described here
// https://forum.qt.io/topic/50053/qmdiarea-tilesubwindows-always-places-widgets-in-activationhistoryorder-in-subwindowview-mode // https://forum.qt.io/topic/50053/qmdiarea-tilesubwindows-always-places-widgets-in-activationhistoryorder-in-subwindowview-mode
QMdiSubWindow *a = m_mdiArea->activeSubWindow(); QMdiSubWindow* a = m_mdiArea->activeSubWindow();
QList<QMdiSubWindow *> list = m_mdiArea->subWindowList(m_mdiArea->activationOrder());
QList<QMdiSubWindow*> list = m_mdiArea->subWindowList(m_mdiArea->activationOrder());
for (int i = 0; i < list.count(); i++) for (int i = 0; i < list.count(); i++)
{ {
m_mdiArea->setActiveSubWindow(list[i]); m_mdiArea->setActiveSubWindow(list[i]);
@ -769,4 +776,3 @@ bool RiuMainPlotWindow::isAnyMdiSubWindowVisible()
{ {
return m_mdiArea->subWindowList().size() > 0; return m_mdiArea->subWindowList().size() > 0;
} }