Allow configuring a callback to create tool windows on-demand

* This means we can start with an empty manager, load a layout, and just
  create the needed windows as we go according to what the layout needs.
This commit is contained in:
baldurk
2016-10-07 15:53:16 +02:00
parent f8b7f0ca87
commit e64c666883
3 changed files with 27 additions and 0 deletions
@@ -66,6 +66,7 @@ ToolWindowManager::ToolWindowManager(QWidget *parent) :
m_dropSuggestionSwitchTimer.setInterval(1000);
m_dropCurrentSuggestionIndex = 0;
m_allowFloatingWindow = true;
m_createCallback = NULL;
m_rectRubberBand = new QRubberBand(QRubberBand::Rectangle, this);
m_lineRubberBand = new QRubberBand(QRubberBand::Line, this);
@@ -271,6 +272,21 @@ void ToolWindowManager::removeToolWindow(QWidget *toolWindow) {
m_toolWindowProperties.remove(toolWindow);
}
QWidget* ToolWindowManager::createToolWindow(const QString& objectName)
{
if (m_createCallback) {
QWidget *toolWindow = m_createCallback(objectName);
if(toolWindow) {
m_toolWindows << toolWindow;
m_toolWindowProperties[toolWindow] = ToolWindowProperty(0);
QObject::connect(toolWindow, &QWidget::windowTitleChanged, this, &ToolWindowManager::windowTitleChanged);
return toolWindow;
}
}
return NULL;
}
void ToolWindowManager::setSuggestionSwitchInterval(int msec) {
m_dropSuggestionSwitchTimer.setInterval(msec);
}
@@ -35,6 +35,8 @@
#include <QVariant>
#include <QLabel>
#include <functional>
class ToolWindowManagerArea;
class ToolWindowManagerWrapper;
@@ -240,6 +242,12 @@ public:
*/
void restoreState(const QVariantMap& data);
typedef std::function<QWidget*(const QString &)> CreateCallback;
void setToolWindowCreateCallback(const CreateCallback &cb) { m_createCallback = cb; }
QWidget *createToolWindow(const QString& objectName);
bool checkValidSplitter(QWidget *w);
/*! \cond PRIVATE */
void setSuggestionSwitchInterval(int msec);
@@ -289,6 +297,8 @@ private:
// (e.g. always 0 if there is only one possible drop location)
QTimer m_dropSuggestionSwitchTimer; // used for switching drop suggestions
CreateCallback m_createCallback;
// last widget used for adding tool windows, or 0 if there isn't one
// (warning: may contain pointer to deleted object)
ToolWindowManagerArea* m_lastUsedArea;
@@ -186,6 +186,7 @@ void ToolWindowManagerArea::restoreState(const QVariantMap &data) {
break;
}
}
if (t == NULL) t = m_manager->createToolWindow(objectName);
if (t) {
t->setProperty("persistData", objectData["data"]);
addToolWindow(t);