Skip to content

Commit 471c135

Browse files
committed
First version of DockManager
For #1625
1 parent 6189c21 commit 471c135

File tree

8 files changed

+58
-14
lines changed

8 files changed

+58
-14
lines changed

src/Interface/Application/MainWindowCollaborators.cc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
#include <QtGui>
3030
#include <Interface/Application/MainWindowCollaborators.h>
3131
#include <Interface/Application/SCIRunMainWindow.h>
32+
#include <Interface/Modules/Base/ModuleDialogGeneric.h>
3233
#include <Core/Logging/Log.h>
3334
#include <Core/Application/Preferences/Preferences.h>
3435
#include <Interface/Application/NetworkEditorControllerGuiProxy.h>
36+
#include <numeric>
3537

3638
#include "ui_ConnectionStyleWizardPage.h"
3739
#include "ui_OtherSettingsWizardPage.h"
@@ -397,3 +399,40 @@ void NetworkEditorBuilder::connectAll(NetworkEditor* editor)
397399
// children only
398400
// addDockWidget(Qt::RightDockWidgetArea, subnet);
399401
}
402+
403+
DockManager::DockManager(int& availableSize, QObject* parent) : QObject(parent),
404+
availableHeight_(availableSize),
405+
currentDialogs_(ModuleDialogGeneric::instances())
406+
{
407+
408+
}
409+
410+
void DockManager::requestShow(ModuleDialogGeneric* dialog)
411+
{
412+
//clear out old pointers
413+
collapseQueue_.erase(std::remove_if(collapseQueue_.begin(), collapseQueue_.end(),
414+
[this](ModuleDialogGeneric* d) { return currentDialogs_.find(d) == currentDialogs_.end(); }),
415+
collapseQueue_.end());
416+
417+
// collapse oldest until they fit
418+
auto needToFit = availableHeight_ - dialog->size().height();
419+
while (usedSpace() > needToFit)
420+
{
421+
auto firstNonCollapsed = std::find_if(collapseQueue_.begin(), collapseQueue_.end(),
422+
[dialog](ModuleDialogGeneric* d) { return d != dialog && !d->isCollapsed(); });
423+
if (firstNonCollapsed != collapseQueue_.end())
424+
(*firstNonCollapsed)->collapse();
425+
else
426+
break;
427+
}
428+
429+
// add latest
430+
collapseQueue_.push_back(dialog);
431+
dialog->expand();
432+
}
433+
434+
int DockManager::usedSpace() const
435+
{
436+
return std::accumulate(currentDialogs_.begin(), currentDialogs_.end(), 0,
437+
[](int height, ModuleDialogGeneric* d) { return height + (d->isCollapsed() ? 0 : d->size().height()); });
438+
}

src/Interface/Application/MainWindowCollaborators.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include <Core/Logging/Log.h>
3535
#include <Core/Utils/Singleton.h>
3636
#include <set>
37-
#include <queue>
37+
#include <deque>
3838
#include <Interface/Application/NetworkEditor.h> //TODO
3939
#include <Interface/Application/NetworkExecutionProgressBar.h>
4040
#endif
@@ -242,11 +242,13 @@ namespace Gui {
242242
Q_OBJECT
243243
public:
244244
explicit DockManager(int& availableSize, QObject* parent);
245+
public Q_SLOTS:
245246
void requestShow(ModuleDialogGeneric* dialog);
246247
private:
247-
int& availableSize_;
248-
std::set<ModuleDialogGeneric*>& currentDialogs_;
249-
std::queue<ModuleDialogGeneric*> collapseQueue_;
248+
int& availableHeight_;
249+
const std::set<ModuleDialogGeneric*>& currentDialogs_;
250+
std::deque<ModuleDialogGeneric*> collapseQueue_;
251+
int usedSpace() const;
250252
};
251253
}
252254
}

src/Interface/Application/ModuleWidget.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,7 @@ void ModuleWidget::updateDockWidgetProperties(bool isFloating)
11951195
{
11961196
dockable_->setWindowFlags(Qt::Window);
11971197
dockable_->show();
1198+
Q_EMIT showUIrequested(dialog_);
11981199
}
11991200
dialog_->setButtonBarTitleVisible(!isFloating);
12001201
}
@@ -1233,8 +1234,8 @@ void ModuleWidget::toggleOptionsDialog()
12331234
{
12341235
if (dockable_->isHidden())
12351236
{
1236-
qDebug() << "h: " << dockable_->size().height();
12371237
dockable_->show();
1238+
Q_EMIT showUIrequested(dialog_);
12381239
dockable_->raise();
12391240
dockable_->activateWindow();
12401241
if (isViewScene_)
@@ -1329,7 +1330,7 @@ void ModuleWidget::pinUI()
13291330
if (dockable_)
13301331
{
13311332
dockable_->setFloating(false);
1332-
qDebug() << dockable_->size().height();
1333+
Q_EMIT showUIrequested(dialog_);
13331334
}
13341335
}
13351336

@@ -1345,7 +1346,7 @@ void ModuleWidget::showUI()
13451346
{
13461347
dockable_->show();
13471348
dialog_->expand();
1348-
qDebug() << dockable_->size().height();
1349+
Q_EMIT showUIrequested(dialog_);
13491350
}
13501351
}
13511352

src/Interface/Application/ModuleWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public Q_SLOTS:
224224
void executionDisabled(bool disabled);
225225
void findInNetwork();
226226
void showSubnetworkEditor(const QString& name);
227+
void showUIrequested(class ModuleDialogGeneric* dialog);
227228
private Q_SLOTS:
228229
void subnetButtonClicked();
229230
void updateBackgroundColorForModuleState(int moduleState);

src/Interface/Application/NetworkEditor.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <Core/Application/Preferences/Preferences.h>
4747
#include <Core/Application/Application.h>
4848
#include <Dataflow/Serialization/Network/XMLSerializer.h>
49+
#include <Interface/Application/MainWindowCollaborators.h>
4950
#ifdef BUILD_WITH_PYTHON
5051
#include <Dataflow/Engine/Python/NetworkEditorPythonAPI.h>
5152
#endif
@@ -386,6 +387,7 @@ ModuleProxyWidget* NetworkEditor::setupModuleWidget(ModuleWidget* module)
386387
connect(module, SIGNAL(disableWidgetDisabling()), this, SIGNAL(disableWidgetDisabling()));
387388
connect(module, SIGNAL(reenableWidgetDisabling()), this, SIGNAL(reenableWidgetDisabling()));
388389
connect(module, SIGNAL(showSubnetworkEditor(const QString&)), this, SLOT(showSubnetChild(const QString&)));
390+
connect(module, SIGNAL(showUIrequested(ModuleDialogGeneric*)), ctorParams_.dockManager_, SLOT(requestShow(ModuleDialogGeneric*)));
389391

390392
if (module->hasDynamicPorts())
391393
{

src/Interface/Application/SCIRunMainWindow.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ SCIRunMainWindow::SCIRunMainWindow()
8585
{
8686
setupUi(this);
8787
builder_ = boost::make_shared<NetworkEditorBuilder>(this);
88+
dockManager_ = new DockManager(dockSpace_, this);
8889

8990
startup_ = true;
9091

@@ -313,13 +314,11 @@ SCIRunMainWindow::SCIRunMainWindow()
313314
setupVersionButton();
314315

315316
WidgetStyleMixin::tabStyle(optionsTabWidget_);
316-
317-
qDebug() << "available height:" << size().height();
317+
setMaximumHeight(QApplication::desktop()->screenGeometry().height());
318318
}
319319

320320
void SCIRunMainWindow::resizeEvent(QResizeEvent* event)
321321
{
322-
qDebug() << "available height:" << size().height();
323322
dockSpace_ = size().height();
324323
QMainWindow::resizeEvent(event);
325324
}
@@ -542,7 +541,7 @@ void SCIRunMainWindow::setupNetworkEditor()
542541
highResolutionExpandFactor *= 1.5;
543542
}
544543
networkEditor_ = new NetworkEditor({ getter, defaultNotePositionGetter_, dialogErrorControl_, preexecuteFunc,
545-
tagColorFunc, tagNameFunc, highResolutionExpandFactor }, scrollAreaWidgetContents_);
544+
tagColorFunc, tagNameFunc, highResolutionExpandFactor, dockManager_ }, scrollAreaWidgetContents_);
546545
gridLayout_5->addWidget(networkEditor_, 0, 0, 1, 1);
547546

548547
builder_->connectAll(networkEditor_);
@@ -1936,7 +1935,6 @@ void SCIRunMainWindow::addModuleToWindowList(const QString& modId, bool hasUI)
19361935

19371936
connect(showAction, SIGNAL(triggered()), networkEditor_, SLOT(subnetMenuActionTriggered()));
19381937
connect(renameAction, SIGNAL(triggered()), networkEditor_, SLOT(subnetMenuActionTriggered()));
1939-
//qDebug() << "add" << modId;
19401938
currentSubnetActions_.insert(modId, subnetMenu);
19411939
menuCurrentSubnets_->addMenu(subnetMenu);
19421940
}
@@ -1945,7 +1943,6 @@ void SCIRunMainWindow::addModuleToWindowList(const QString& modId, bool hasUI)
19451943
void SCIRunMainWindow::removeModuleFromWindowList(const ModuleId& modId)
19461944
{
19471945
auto name = QString::fromStdString(modId.id_);
1948-
//qDebug() << "remove" << name;
19491946
auto action = currentModuleActions_[name];
19501947
menuCurrent_->removeAction(action);
19511948
currentModuleActions_.remove(name);
@@ -1954,7 +1951,6 @@ void SCIRunMainWindow::removeModuleFromWindowList(const ModuleId& modId)
19541951

19551952
if (modId.id_.find("Subnet") != std::string::npos)
19561953
{
1957-
//qDebug() << currentSubnetActions_;
19581954
auto subnet = currentSubnetActions_[name];
19591955
if (subnet)
19601956
menuCurrentSubnets_->removeAction(subnet->menuAction());

src/Interface/Application/SCIRunMainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ public Q_SLOTS:
186186
bool startup_;
187187
boost::shared_ptr<NetworkEditorBuilder> builder_;
188188
int dockSpace_{0};
189+
class DockManager* dockManager_;
189190

190191
Q_SIGNALS:
191192
void moduleItemDoubleClicked();

src/Interface/Modules/Base/ModuleDialogGeneric.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ namespace Gui {
7878
void updateWindowTitle(const QString& title);
7979
void setButtonBarTitleVisible(bool visible);
8080
void setupButtonBar();
81+
bool isCollapsed() const { return collapsed_; }
8182
virtual void createStartupNote() {}
8283
static void setExecutionDisablingServiceFunctionAdd(ExecutionDisablingServiceFunction add) { disablerAdd_ = add; }
8384
static void setExecutionDisablingServiceFunctionRemove(ExecutionDisablingServiceFunction remove) { disablerRemove_ = remove; }
85+
static const std::set<ModuleDialogGeneric*>& instances() { return instances_; }
8486

8587
//TODO: input state hookup?
8688
//yeah: eventually replace int with generic dialog state object, but needs to be two-way (set/get)

0 commit comments

Comments
 (0)