diff --git a/.cproject b/.cproject
index 59a6803..9416104 100644
--- a/.cproject
+++ b/.cproject
@@ -25,6 +25,7 @@
+
@@ -35,6 +36,7 @@
+
@@ -45,6 +47,7 @@
+
diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
index ef6f6a9..c89bb59 100644
--- a/.settings/language.settings.xml
+++ b/.settings/language.settings.xml
@@ -2,10 +2,7 @@
-
-
-
-
+
diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp
new file mode 100644
index 0000000..e6f8d1f
--- /dev/null
+++ b/demo/MainWindow.cpp
@@ -0,0 +1,327 @@
+
+/*******************************************************************************
+** Qt Advanced Docking System
+** Copyright (C) 2017 Uwe Kindler
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License as published by the Free Software Foundation; either
+** version 2.1 of the License, or (at your option) any later version.
+**
+** This library is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; If not, see .
+******************************************************************************/
+
+
+//============================================================================
+/// \file MainWindow.cpp
+/// \author Uwe Kindler
+/// \date 13.02.2018
+/// \brief Implementation of CMainWindow demo class
+//============================================================================
+
+
+//============================================================================
+// INCLUDES
+//============================================================================
+#include
+#include "ui_mainwindow.h"
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include "DockManager.h"
+#include "DockWidget.h"
+#include "DockAreaWidget.h"
+
+
+//============================================================================
+static ads::CDockWidget* createLongTextLabelDockWidget(QMenu* ViewMenu)
+{
+ static int LabelCount = 0;
+ QLabel* l = new QLabel();
+ l->setWordWrap(true);
+ l->setAlignment(Qt::AlignTop | Qt::AlignLeft);
+ l->setText(QString("Label %1 %2 - Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "
+ "Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque "
+ "penatibus et magnis dis parturient montes, nascetur ridiculus mus. "
+ "Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. "
+ "Nulla consequat massa quis enim. Donec pede justo, fringilla vel, "
+ "aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, "
+ "imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede "
+ "mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum "
+ "semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, "
+ "porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, "
+ "dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla "
+ "ut metus varius laoreet.")
+ .arg(LabelCount)
+ .arg(QTime::currentTime().toString("hh:mm:ss:zzz")));
+
+ ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Label %1").arg(LabelCount++));
+ DockWidget->setWidget(l);
+ DockWidget->setObjectName(DockWidget->windowTitle());
+ ViewMenu->addAction(DockWidget->toggleViewAction());
+ return DockWidget;
+}
+
+
+//============================================================================
+static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu)
+{
+ static int CalendarCount = 0;
+ QCalendarWidget* w = new QCalendarWidget();
+ ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Calendar %1").arg(CalendarCount++));
+ DockWidget->setWidget(w);
+ DockWidget->setObjectName(DockWidget->windowTitle());
+ DockWidget->setToggleViewActionMode(ads::CDockWidget::ActionModeShow);
+ ViewMenu->addAction(DockWidget->toggleViewAction());
+ return DockWidget;
+}
+
+
+//============================================================================
+static ads::CDockWidget* createFileSystemTreeDockWidget(QMenu* ViewMenu)
+{
+ static int FileSystemCount = 0;
+ QTreeView* w = new QTreeView();
+ w->setFrameShape(QFrame::NoFrame);
+ QFileSystemModel* m = new QFileSystemModel(w);
+ m->setRootPath(QDir::currentPath());
+ w->setModel(m);
+ ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Filesystem %1").arg(FileSystemCount++));
+ DockWidget->setWidget(w);
+ DockWidget->setObjectName(DockWidget->windowTitle());
+ ViewMenu->addAction(DockWidget->toggleViewAction());
+ return DockWidget;
+}
+
+
+//============================================================================
+/**
+ * Private data class pimpl
+ */
+struct MainWindowPrivate
+{
+ CMainWindow* _this;
+ Ui::MainWindow ui;
+ QAction* SavePerspectiveAction = nullptr;
+ QWidgetAction* PerspectiveListAction = nullptr;
+ QComboBox* PerspectiveComboBox = nullptr;;
+ ads::CDockManager* DockManager = nullptr;
+
+ MainWindowPrivate(CMainWindow* _public) : _this(_public) {}
+
+ /**
+ * Creates the toolbar actions
+ */
+ void createActions();
+
+ /**
+ * Fill the dock manager with dock widgets
+ */
+ void createContent();
+
+ /**
+ * Saves the dock manager state and the main window geometry
+ */
+ void saveState();
+
+ /**
+ * Save the list of perspectives
+ */
+ void savePerspectives();
+
+ /**
+ * Restores the dock manager state
+ */
+ void restoreState();
+
+ /**
+ * Restore the perspective listo of the dock manager
+ */
+ void restorePerspectives();
+};
+
+
+//============================================================================
+void MainWindowPrivate::createContent()
+{
+ // Test container docking
+ QMenu* ViewMenu = ui.menuView;
+ auto DockWidget = createCalendarDockWidget(ViewMenu);
+ DockWidget->setIcon(_this->style()->standardIcon(QStyle::SP_DialogOpenButton));
+ DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
+ DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
+ DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
+ DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
+ auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
+ DockWidget = createCalendarDockWidget(ViewMenu);
+ DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
+ DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);
+
+ // Test dock area docking
+ auto RighDockArea = DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), TopDockArea);
+ DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
+ auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
+ DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
+ DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
+}
+
+
+//============================================================================
+void MainWindowPrivate::createActions()
+{
+ ui.toolBar->addAction(ui.actionSaveState);
+ ui.actionSaveState->setIcon(_this->style()->standardIcon(QStyle::SP_DialogSaveButton));
+ ui.toolBar->addAction(ui.actionRestoreState);
+ ui.actionRestoreState->setIcon(_this->style()->standardIcon(QStyle::SP_DialogOpenButton));
+
+ SavePerspectiveAction = new QAction("Save Perspective", _this);
+ _this->connect(SavePerspectiveAction, SIGNAL(triggered()), SLOT(savePerspective()));
+ PerspectiveListAction = new QWidgetAction(_this);
+ PerspectiveComboBox = new QComboBox(_this);
+ PerspectiveComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
+ PerspectiveComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ PerspectiveListAction->setDefaultWidget(PerspectiveComboBox);
+ ui.toolBar->addSeparator();
+ ui.toolBar->addAction(PerspectiveListAction);
+ ui.toolBar->addAction(SavePerspectiveAction);
+}
+
+
+//============================================================================
+void MainWindowPrivate::saveState()
+{
+ QSettings Settings("Settings.ini", QSettings::IniFormat);
+ Settings.setValue("mainWindow/Geometry", _this->saveGeometry());
+ Settings.setValue("mainWindow/State", _this->saveState());
+ Settings.setValue("mainWindow/DockingState", DockManager->saveState());
+}
+
+
+//============================================================================
+void MainWindowPrivate::restoreState()
+{
+ QSettings Settings("Settings.ini", QSettings::IniFormat);
+ _this->restoreGeometry(Settings.value("mainWindow/Geometry").toByteArray());
+ _this->restoreState(Settings.value("mainWindow/State").toByteArray());
+ DockManager->restoreState(Settings.value("mainWindow/DockingState").toByteArray());
+}
+
+
+
+//============================================================================
+void MainWindowPrivate::savePerspectives()
+{
+ QSettings Settings("Settings.ini", QSettings::IniFormat);
+ DockManager->savePerspectives(Settings);
+}
+
+
+
+//============================================================================
+void MainWindowPrivate::restorePerspectives()
+{
+ QSettings Settings("Settings.ini", QSettings::IniFormat);
+ DockManager->loadPerspectives(Settings);
+ PerspectiveComboBox->clear();
+ PerspectiveComboBox->addItems(DockManager->perspectiveNames());
+}
+
+
+//============================================================================
+CMainWindow::CMainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ d(new MainWindowPrivate(this))
+{
+ d->ui.setupUi(this);
+ d->createActions();
+
+ // Now create the dock manager and its content
+ d->DockManager = new ads::CDockManager(this);
+ connect(d->PerspectiveComboBox, SIGNAL(activated(const QString&)),
+ d->DockManager, SLOT(openPerspective(const QString&)));
+
+ d->createContent();
+ // Default window geometry
+ resize(800, 600);
+
+ d->restoreState();
+ d->restorePerspectives();
+}
+
+
+//============================================================================
+CMainWindow::~CMainWindow()
+{
+ delete d;
+}
+
+
+//============================================================================
+void CMainWindow::closeEvent(QCloseEvent* event)
+{
+ d->saveState();
+ QMainWindow::closeEvent(event);
+}
+
+
+//============================================================================
+void CMainWindow::on_actionSaveState_triggered(bool)
+{
+ qDebug() << "MainWindow::on_actionSaveState_triggered";
+ d->saveState();
+}
+
+
+//============================================================================
+void CMainWindow::on_actionRestoreState_triggered(bool)
+{
+ qDebug() << "MainWindow::on_actionRestoreState_triggered";
+ d->restoreState();
+}
+
+
+//============================================================================
+void CMainWindow::savePerspective()
+{
+ std::cout << "savePerspective" << std::endl;
+ QString PerspectiveName = QInputDialog::getText(this, "Save Perspective", "Enter unique name:");
+ if (PerspectiveName.isEmpty())
+ {
+ return;
+ }
+
+ d->DockManager->addPerspective(PerspectiveName);
+ QSignalBlocker Blocker(d->PerspectiveComboBox);
+ d->PerspectiveComboBox->clear();
+ d->PerspectiveComboBox->addItems(d->DockManager->perspectiveNames());
+ d->PerspectiveComboBox->setCurrentText(PerspectiveName);
+
+ d->savePerspectives();
+}
+
diff --git a/demo/MainWindow.h b/demo/MainWindow.h
new file mode 100644
index 0000000..19d789e
--- /dev/null
+++ b/demo/MainWindow.h
@@ -0,0 +1,63 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+/*******************************************************************************
+** Qt Advanced Docking System
+** Copyright (C) 2017 Uwe Kindler
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License as published by the Free Software Foundation; either
+** version 2.1 of the License, or (at your option) any later version.
+**
+** This library is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; If not, see .
+******************************************************************************/
+
+
+//============================================================================
+/// \file MainWindow.h
+/// \author Uwe Kindler
+/// \date 13.02.2018
+/// \brief Declaration of CMainWindow class
+//============================================================================
+
+
+//============================================================================
+// INCLUDES
+//============================================================================
+#include
+
+
+
+struct MainWindowPrivate;
+
+
+/**
+ * Simple main window for demo
+ */
+class CMainWindow : public QMainWindow
+{
+ Q_OBJECT
+private:
+ MainWindowPrivate* d;///< private data - pimpl
+ friend class MainWindowPrivate;
+
+protected:
+ virtual void closeEvent(QCloseEvent* event) override;
+
+public:
+ explicit CMainWindow(QWidget *parent = 0);
+ virtual ~CMainWindow();
+
+private slots:
+ void on_actionSaveState_triggered(bool);
+ void on_actionRestoreState_triggered(bool);
+ void savePerspective();
+};
+
+#endif // MAINWINDOW_H
diff --git a/demo/demo.pro b/demo/demo.pro
index ce7b54b..e896870 100644
--- a/demo/demo.pro
+++ b/demo/demo.pro
@@ -4,24 +4,16 @@ ADS_OUT_ROOT = $${OUT_PWD}/..
TARGET = AdvancedDockingSystemDemo
DESTDIR = $${ADS_OUT_ROOT}/lib
QT += core gui widgets
+CONFIG *= c++14
-windows {
- # MinGW
- *-g++* {
- QMAKE_CXXFLAGS += -std=c++11
- }
- # MSVC
- *-msvc* {
- }
-}
SOURCES += \
main.cpp \
- mainwindow.cpp
+ MainWindow.cpp
HEADERS += \
- mainwindow.h
+ MainWindow.h
FORMS += \
mainwindow.ui
diff --git a/demo/main.cpp b/demo/main.cpp
index 0c4cc56..1df2221 100644
--- a/demo/main.cpp
+++ b/demo/main.cpp
@@ -1,3 +1,4 @@
+#include
#include
#include
#include
@@ -5,7 +6,6 @@
#include
-#include "mainwindow.h"
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
qInstallMessageHandler(myMessageOutput);
qDebug() << "Message handler test";
- MainWindow mw;
+ CMainWindow mw;
mw.show();
return a.exec();
}
diff --git a/demo/mainwindow.cpp b/demo/mainwindow.cpp
deleted file mode 100644
index a9d6bb2..0000000
--- a/demo/mainwindow.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-#include "mainwindow.h"
-
-#include "ui_mainwindow.h"
-
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "DockManager.h"
-#include "DockWidget.h"
-#include "DockAreaWidget.h"
-
-
-
-
-static ads::CDockWidget* createLongTextLabelDockWidget(QMenu* ViewMenu)
-{
- static int LabelCount = 0;
- QLabel* l = new QLabel();
- l->setWordWrap(true);
- l->setAlignment(Qt::AlignTop | Qt::AlignLeft);
- l->setText(QString("Label %1 %2 - Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "
- "Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque "
- "penatibus et magnis dis parturient montes, nascetur ridiculus mus. "
- "Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. "
- "Nulla consequat massa quis enim. Donec pede justo, fringilla vel, "
- "aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, "
- "imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede "
- "mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum "
- "semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, "
- "porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, "
- "dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla "
- "ut metus varius laoreet.")
- .arg(LabelCount)
- .arg(QTime::currentTime().toString("hh:mm:ss:zzz")));
-
- ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Label %1").arg(LabelCount++));
- DockWidget->setWidget(l);
- DockWidget->setObjectName(DockWidget->windowTitle());
- ViewMenu->addAction(DockWidget->toggleViewAction());
- return DockWidget;
-}
-
-
-static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu)
-{
- static int CalendarCount = 0;
- QCalendarWidget* w = new QCalendarWidget();
- ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Calendar %1").arg(CalendarCount++));
- DockWidget->setWidget(w);
- DockWidget->setObjectName(DockWidget->windowTitle());
- DockWidget->setToggleViewActionMode(ads::CDockWidget::ActionModeShow);
- ViewMenu->addAction(DockWidget->toggleViewAction());
- return DockWidget;
-}
-
-static ads::CDockWidget* createFileSystemTreeDockWidget(QMenu* ViewMenu)
-{
- static int FileSystemCount = 0;
- QTreeView* w = new QTreeView();
- w->setFrameShape(QFrame::NoFrame);
- QFileSystemModel* m = new QFileSystemModel(w);
- m->setRootPath(QDir::currentPath());
- w->setModel(m);
- ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Filesystem %1").arg(FileSystemCount++));
- DockWidget->setWidget(w);
- DockWidget->setObjectName(DockWidget->windowTitle());
- ViewMenu->addAction(DockWidget->toggleViewAction());
- return DockWidget;
-}
-
-
-
-MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
-{
- ui->setupUi(this);
- ui->toolBar->addAction(ui->actionSaveState);
- ui->actionSaveState->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
- ui->toolBar->addAction(ui->actionRestoreState);
- ui->actionRestoreState->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
-
- m_SavePerspectiveAction = new QAction("Save Perspective", this);
- m_PerspectiveListAction = new QWidgetAction(this);
- m_PerspectiveComboBox = new QComboBox(this);
- m_PerspectiveListAction->setDefaultWidget(m_PerspectiveComboBox);
- ui->toolBar->addSeparator();
- ui->toolBar->addAction(m_PerspectiveListAction);
- ui->toolBar->addAction(m_SavePerspectiveAction);
-
- m_DockManager = new ads::CDockManager(this);
- createContent();
- // Default window geometry
- resize(800, 600);
-}
-
-MainWindow::~MainWindow()
-{
- delete ui;
-}
-
-
-void MainWindow::createContent()
-{
- // Test container docking
- QMenu* ViewMenu = this->ui->menuView;
- auto DockWidget = createCalendarDockWidget(ViewMenu);
- DockWidget->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
- DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
- m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
- m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
- m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
- auto TopDockArea = m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
- DockWidget = createCalendarDockWidget(ViewMenu);
- DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
- m_DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);
-
- // Test dock area docking
- auto RighDockArea = m_DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), TopDockArea);
- m_DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
- auto BottomDockArea = m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
- m_DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
- m_DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
-}
-
-
-void MainWindow::closeEvent(QCloseEvent* event)
-{
- /*QSettings Settings("Settings.ini", QSettings::IniFormat);
- Settings.setValue("mainWindow/Geometry", saveGeometry());
- Settings.setValue("mainWindow/DockingState", m_DockManager->saveState());*/
- QMainWindow::closeEvent(event);
-}
-
-
-void MainWindow::on_actionSaveState_triggered(bool)
-{
- qDebug() << "MainWindow::on_actionSaveState_triggered";
- QSettings Settings("Settings.ini", QSettings::IniFormat);
- Settings.setValue("mainWindow/Geometry", saveGeometry());
- Settings.setValue("mainWindow/DockingState", m_DockManager->saveState());
-}
-
-
-void MainWindow::on_actionRestoreState_triggered(bool)
-{
- qDebug() << "MainWindow::on_actionRestoreState_triggered";
- QSettings Settings("Settings.ini", QSettings::IniFormat);
- restoreGeometry(Settings.value("mainWindow/Geometry").toByteArray());
- m_DockManager->restoreState(Settings.value("mainWindow/DockingState").toByteArray());
-}
-
diff --git a/demo/mainwindow.h b/demo/mainwindow.h
deleted file mode 100644
index 391e99b..0000000
--- a/demo/mainwindow.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include
-#include
-#include
-
-#include
-#include "DockManager.h"
-
-namespace Ui {
-class MainWindow;
-}
-
-/**
- * Simple main window for demo
- */
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-private:
- QAction* m_SavePerspectiveAction;
- QWidgetAction* m_PerspectiveListAction;
- QComboBox* m_PerspectiveComboBox;
-
-protected:
- virtual void closeEvent(QCloseEvent* event) override;
-;
-public:
- explicit MainWindow(QWidget *parent = 0);
- virtual ~MainWindow();
-
-private:
- Ui::MainWindow *ui;
- ads::CDockManager* m_DockManager;
- void createContent();
-
-private slots:
- void on_actionSaveState_triggered(bool);
- void on_actionRestoreState_triggered(bool);
-};
-
-#endif // MAINWINDOW_H
diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp
index f6694a4..db3ecc5 100644
--- a/src/DockContainerWidget.cpp
+++ b/src/DockContainerWidget.cpp
@@ -522,9 +522,10 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
else
{
DockArea->setProperty("currentIndex", CurrentIndex);
+ DockAreas.append(DockArea);
}
+
CreatedWidget = DockArea;
- DockAreas.append(DockArea);
return true;
}
diff --git a/src/DockManager.cpp b/src/DockManager.cpp
index 7c190d5..c32c556 100644
--- a/src/DockManager.cpp
+++ b/src/DockManager.cpp
@@ -42,6 +42,7 @@
#include
#include
#include
+#include
#include "FloatingDockContainer.h"
#include "DockOverlay.h"
@@ -53,7 +54,6 @@
namespace ads
{
-
/**
* Private data class of CDockManager class (pimpl)
*/
@@ -65,6 +65,7 @@ struct DockManagerPrivate
CDockOverlay* ContainerOverlay;
CDockOverlay* DockAreaOverlay;
QMap DockWidgetsMap;
+ QMap Perspectives;
/**
* Private data constructor
@@ -386,6 +387,80 @@ CDockWidget* CDockManager::findDockWidget(const QString& ObjectName)
{
return d->DockWidgetsMap.value(ObjectName, nullptr);
}
+
+
+//============================================================================
+void CDockManager::addPerspective(const QString& UniquePrespectiveName)
+{
+ d->Perspectives.insert(UniquePrespectiveName, saveState());
+ emit perspectiveListChanged();
+}
+
+
+//============================================================================
+QStringList CDockManager::perspectiveNames() const
+{
+ return d->Perspectives.keys();
+}
+
+
+//============================================================================
+void CDockManager::openPerspective(const QString& PerspectiveName)
+{
+ std::cout << "CDockManager::openPerspective " << PerspectiveName.toStdString() << std::endl;
+ const auto Iterator = d->Perspectives.find(PerspectiveName);
+ if (d->Perspectives.end() == Iterator)
+ {
+ return;
+ }
+
+ std::cout << "CDockManager::openPerspective - restoring state" << std::endl;
+ restoreState(Iterator.value());
+}
+
+
+//============================================================================
+void CDockManager::savePerspectives(QSettings& Settings) const
+{
+ Settings.beginWriteArray("Perspectives", d->Perspectives.size());
+ int i = 0;
+ for (auto it = d->Perspectives.constBegin(); it != d->Perspectives.constEnd(); ++it)
+ {
+ Settings.setArrayIndex(i);
+ Settings.setValue("Name", it.key());
+ Settings.setValue("State", it.value());
+ ++i;
+ }
+ Settings.endArray();
+}
+
+
+//============================================================================
+void CDockManager::loadPerspectives(QSettings& Settings)
+{
+ d->Perspectives.clear();
+ int Size = Settings.beginReadArray("Perspectives");
+ if (!Size)
+ {
+ Settings.endArray();
+ return;
+ }
+
+ for (int i = 0; i < Size; ++i)
+ {
+ Settings.setArrayIndex(i);
+ QString Name = Settings.value("Name").toString();
+ QByteArray Data = Settings.value("State").toByteArray();
+ if (Name.isEmpty() || Data.isEmpty())
+ {
+ continue;
+ }
+
+ d->Perspectives.insert(Name, Data);
+ }
+
+ Settings.endArray();
+}
} // namespace ads
//---------------------------------------------------------------------------
diff --git a/src/DockManager.h b/src/DockManager.h
index d93504c..4d73892 100644
--- a/src/DockManager.h
+++ b/src/DockManager.h
@@ -32,6 +32,8 @@
//============================================================================
#include "DockContainerWidget.h"
+class QSettings;
+
namespace ads
{
struct DockManagerPrivate;
@@ -134,6 +136,7 @@ public:
/**
* Saves the current state of the dockmanger and all its dock widgets
+ * into the returned QByteArray
*/
QByteArray saveState(int version = 0) const;
@@ -145,6 +148,43 @@ public:
* returns true.
*/
bool restoreState(const QByteArray &state, int version = 0);
+
+ /**
+ * Saves the current perspective to the internal list of perspectives.
+ * A perspective is the current state of the dock manager assigned
+ * with a certain name. This makes it possible for the user,
+ * to switch between different perspectives quickly.
+ * If a perspective with the given name already exists, then
+ * it will be overwritten with the new state.
+ */
+ void addPerspective(const QString& UniquePrespectiveName);
+
+ /**
+ * Returns the names of all available perspectives
+ */
+ QStringList perspectiveNames() const;
+
+ /**
+ * Saves the perspectives to the given settings file.
+ */
+ void savePerspectives(QSettings& Settings) const;
+
+ /**
+ * Loads the perspectives from the given settings file
+ */
+ void loadPerspectives(QSettings& Settings);
+
+public slots:
+ /**
+ * Opens the perspective with the given name.
+ */
+ void openPerspective(const QString& PerspectiveName);
+
+signals:
+ /**
+ * This signal is emitted if the list of perspectives changed
+ */
+ void perspectiveListChanged();
}; // class DockManager
} // namespace ads
//-----------------------------------------------------------------------------