Skip to content

Commit 54e1ff6

Browse files
committed
1.Restore widgets upon restart 2.Load only plugins if requested by user or required dependency
1 parent 41044e3 commit 54e1ff6

File tree

20 files changed

+449
-179
lines changed

20 files changed

+449
-179
lines changed

plugins/gui/include/gui/content_anchor/content_anchor.h

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,25 @@
2525

2626
#pragma once
2727

28+
#include <QList>
29+
#include <QObject>
30+
#include <QMetaEnum>
31+
2832
namespace hal
2933
{
34+
class ContentFrame;
3035
class ContentWidget;
36+
class DockBar;
37+
38+
namespace ContentLayout
39+
{
40+
Q_NAMESPACE
41+
enum Position {Center, Left, Right, Bottom};
42+
Q_ENUM_NS(Position)
43+
44+
QString positionToString(Position pos);
45+
Position positionFromString(const QString& s);
46+
}
3147

3248
/**
3349
* @ingroup docking
@@ -36,6 +52,11 @@ namespace hal
3652
*/
3753
class ContentAnchor
3854
{
55+
56+
protected:
57+
DockBar* mDockBar;
58+
ContentLayout::Position mAnchorPosition;
59+
3960
public:
4061
/**
4162
* Adds a given ContentWidget to the anchor.
@@ -56,8 +77,9 @@ namespace hal
5677
* Detaches a given widget from the anchor.
5778
*
5879
* @param widget - The widget to detach.
80+
* @returns the enclosing frame of the detached widget
5981
*/
60-
virtual void detach(ContentWidget* widget) = 0;
82+
virtual ContentFrame* detach(ContentWidget* widget) = 0;
6183

6284
/**
6385
* Reattaches a given widget to the anchor.
@@ -81,17 +103,18 @@ namespace hal
81103
virtual void close(ContentWidget* widget) = 0;
82104

83105
/**
84-
* Destructor that has to be overriden.
106+
* Destructor
85107
*/
86-
virtual inline ~ContentAnchor() = 0;
108+
virtual ~ContentAnchor() {;}
87109

88110
/**
89111
* Returns the number of widgets / buttons as of mDockBar->count()
90112
*/
91-
virtual int count() const = 0;
92-
};
113+
virtual int count() const;
93114

94-
ContentAnchor::~ContentAnchor()
95-
{
96-
}
115+
/**
116+
* Save state of widgets using anchor tag
117+
*/
118+
void saveState() const;
119+
};
97120
}

plugins/gui/include/gui/content_layout_area/content_layout_area.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#pragma once
2727

2828
#include "gui/content_widget/content_widget.h"
29+
#include "gui/content_anchor/content_anchor.h"
2930

3031
#include <QWidget>
3132

@@ -40,14 +41,6 @@ namespace hal
4041
class SplitterAnchor;
4142
class TabWidget;
4243

43-
enum class content_anchor
44-
{
45-
center = 0,
46-
left = 1,
47-
right = 2,
48-
bottom = 3
49-
};
50-
5144
/**
5245
* @ingroup gui
5346
* @brief Manages the layout of all ContentWidget%s
@@ -97,7 +90,7 @@ namespace hal
9790
* @param anchor - The anchor the content widget should be moved to (i.e. the direction of the docker bar it
9891
* is moved to)
9992
*/
100-
void addContent(ContentWidget* widget, int index, content_anchor anchor);
93+
void addContent(ContentWidget* widget, int index, ContentLayout::Position anchor);
10194

10295
/**
10396
* Not yet implemented.
@@ -148,6 +141,16 @@ namespace hal
148141
*/
149142
void handleDragEnd();
150143

144+
/**
145+
* Save state of widgets (location, visibility, docking state) and splitter to guisettings
146+
*/
147+
void saveState() const;
148+
149+
/**
150+
* Restore splitter setting from guisettings
151+
*/
152+
void restoreSplitter();
153+
151154
private:
152155
QVBoxLayout* mTopLevelLayout;
153156
QHBoxLayout* mSecondLevelLayout;

plugins/gui/include/gui/content_manager/content_manager.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "gui/gui_utils/special_log_content_manager.h"
3434
#include "gui/content_widget/content_widget.h"
35+
#include "gui/content_anchor/content_anchor.h"
3536
#include "hal_config.h"
3637

3738
namespace hal
@@ -62,6 +63,13 @@ namespace hal
6263
virtual ExternalContentWidget* contentFactory() const = 0;
6364
};
6465

66+
struct ContentWidgetPlacement {
67+
ContentWidget* widget;
68+
int index;
69+
ContentLayout::Position anchorPos;
70+
bool visible;
71+
};
72+
6573
class ExternalContent : public QList<ContentFactory*>
6674
{
6775
static ExternalContent* inst;
@@ -174,11 +182,8 @@ namespace hal
174182

175183
private:
176184
MainWindow* mMainWindow;
177-
int mExternalIndex;
178185
QString mWindowTitle;
179186

180-
QList<ContentWidget*> mContent;
181-
182187
PythonConsoleWidget* mPythonConsoleWidget;
183188
PythonEditor* mPythonWidget;
184189
GraphTabWidget* mGraphTabWidget;

plugins/gui/include/gui/content_widget/content_widget.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class QVBoxLayout;
3636
namespace hal
3737
{
3838
class ContentAnchor;
39+
class ContentFrame;
3940
class Toolbar;
4041

4142
/**
@@ -89,14 +90,14 @@ namespace hal
8990
*
9091
* @return The name.
9192
*/
92-
QString name();
93+
QString name() const;
9394

9495
/**
9596
* Get the loaded and processed icon that can be set in the stylesheet.
9697
*
9798
* @return The icon.
9899
*/
99-
QIcon icon();
100+
QIcon icon() const;
100101

101102
/**
102103
* Sets the anchor of the content widget. This function is used by the docking system.
@@ -232,6 +233,17 @@ namespace hal
232233
*/
233234
virtual void restoreFromProject() {;}
234235

236+
/**
237+
* Detached frame if widget is detached, nullptr otherwise
238+
*/
239+
ContentFrame* detachedFrame() const;
240+
241+
/**
242+
* Set pointer to frame when detached, to nullptr when reattached
243+
* @param df - pointer to frame
244+
*/
245+
void setDetachedFrame(ContentFrame* df);
246+
235247
private:
236248
void closeEvent(QCloseEvent* event);
237249

@@ -247,5 +259,6 @@ namespace hal
247259
QAction* mSearchAction;
248260
QShortcut* mSearchShortcut;
249261
QKeySequence mSearchKeysequence;
262+
ContentFrame* mDetachedFrame;
250263
};
251264
}

plugins/gui/include/gui/docking_system/dock_bar.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ namespace hal
250250
*/
251251
void clear();
252252

253+
/**
254+
* Returns the 'hidden' property for index button
255+
* @param index - The index for the content widget.
256+
* @return true if the button is hidden (the widget detached)
257+
*/
258+
bool isHidden(int index) const;
259+
253260
Q_SIGNALS:
254261

255262
/**

plugins/gui/include/gui/docking_system/splitter_anchor.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ namespace hal
5353
/**
5454
*The splitter anchor's constructor.
5555
*
56-
* @param DockBar - The splitter ancor's dockbar.
57-
* @param Splitter - The actual splitter to represent the dockbar's area.
56+
* @param dockBar - The splitter ancor's dockbar.
57+
* @param splitter - The actual splitter to represent the dockbar's area.
5858
* @param parent - The parent of the splitter anchor.
5959
*/
60-
SplitterAnchor(DockBar* DockBar, Splitter* Splitter, QObject* parent = nullptr);
60+
SplitterAnchor(ContentLayout::Position apos, DockBar* dockBar, Splitter* splitter, QObject* parent = nullptr);
6161

6262
/**
6363
* Adds a contentwidget at the given position to the splitter area and tells the dockbar to
@@ -82,8 +82,9 @@ namespace hal
8282
* frame is created and the widget is displayed on the same level as hal as a seperate window.
8383
*
8484
* @param widget - The widget to be detached.
85+
* @returns the enclosing frame of the detached widget
8586
*/
86-
virtual void detach(ContentWidget* widget) override;
87+
virtual ContentFrame* detach(ContentWidget* widget) override;
8788

8889
/**
8990
* Reattaches the given widget back to the splitter area and dockbar (shows them again) when
@@ -108,13 +109,6 @@ namespace hal
108109
*/
109110
virtual void close(ContentWidget* widget) override;
110111

111-
/**
112-
* Get the number of widgets currently associated with the dockbar.
113-
*
114-
* @return The number of widgets.
115-
*/
116-
int count() const override;
117-
118112
/**
119113
* Removes all buttons from the dockbar and therefore the widgets from the area. The corresponding
120114
* widgets are not destroyed but hidden.
@@ -129,8 +123,6 @@ namespace hal
129123
void contentChanged();
130124

131125
private:
132-
DockBar* mDockBar;
133126
Splitter* mSplitter;
134-
QList<ContentFrame*> mDetachedFrames;
135127
};
136128
}

plugins/gui/include/gui/docking_system/tab_widget.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ namespace hal
8383
* Detaches the content widget and its corresponding dockbutton (hides it) from the dockbar
8484
* and displays the content widget in its own window.
8585
* @param widget
86+
* @returns the enclosing frame of the detached widget
8687
*/
87-
virtual void detach(ContentWidget* widget);
88+
virtual ContentFrame* detach(ContentWidget* widget);
8889

8990
/**
9091
* Reattches the given content widget and corresponding dockbutton (shows it) to the dockbar.
@@ -116,12 +117,6 @@ namespace hal
116117
*/
117118
void handleNoCurrentWidget(int index);
118119

119-
/**
120-
* Returns the number of widgets / buttons as of mDockBar->count()
121-
* @return - The number of widgets / buttons
122-
*/
123-
int count() const override;
124-
125120
/**
126121
* Removes all buttons from the dockbar and therefore the widgets from the area. The corresponding
127122
* widgets are not destroyed but hidden.
@@ -150,12 +145,10 @@ namespace hal
150145
private:
151146
QVBoxLayout* mVerticalLayout;
152147
QHBoxLayout* mHorizontalLayout;
153-
DockBar* mDockBar;
154148
Toolbar* mLeftToolbar;
155149
Toolbar* mRightToolbar;
156150
ContentWidget* mCurrentWidget;
157151
QAction* mActionDetach;
158-
QList<ContentFrame*> mDetachedFrames;
159152
QList<QShortcut*> mActiveShortcuts;
160153
};
161154
}

plugins/gui/include/gui/main_window/main_window.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ namespace hal
288288
* @param index - The position index within the anchor, the widget should be put in
289289
* @param anchor - The anchor, the widget should be assigned to
290290
*/
291-
void addContent(ContentWidget* widget, int index, content_anchor anchor);
291+
void addContent(ContentWidget* widget, int index, ContentLayout::Position anchor);
292292

293293
/**
294294
* Remove a content widget from the layout area.
@@ -427,6 +427,11 @@ namespace hal
427427

428428
void reloadStylsheet(int istyle);
429429

430+
/**
431+
* Getter for content layout area, needed to restore gui settings by content manager
432+
*/
433+
ContentLayoutArea* layoutArea() const;
434+
430435
private Q_SLOTS:
431436
/**
432437
* Private slot to handle event log setting

plugins/gui/include/gui/settings/settings_manager.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@
2929
#include <QList>
3030
#include <QSettings>
3131
#include "gui/settings/settings_items/settings_item.h"
32+
#include "gui/content_anchor/content_anchor.h"
3233
#include "gui/logger/logger_settings.h"
3334
#include <QPoint>
3435
#include <QSize>
36+
#include <QSplitter>
3537

3638
namespace hal
3739
{
40+
class ContentWidget;
41+
struct ContentWidgetPlacement;
42+
3843
/**
3944
* @ingroup settings
4045
* @brief Manages and persists the settings on the lowest level.
@@ -91,6 +96,28 @@ namespace hal
9196
*/
9297
void mainWindowSaveGeometry(const QPoint& pos, const QSize& size);
9398

99+
/**
100+
* Write widgets location and geometry to the user settings file.
101+
* @param anchor - One of L(eft), R(ight), B(ottom), T(ab)
102+
* @param widgets - List of widgets in that anchor
103+
*/
104+
void widgetsSaveGeometry(ContentLayout::Position anchorPos, QList<const ContentWidget*>& widgets);
105+
106+
/**
107+
* Returns placement object for widget if info found in setting file.
108+
* The index -1 indicates that the info was not found.
109+
*
110+
* @param cw - Pointer to ContentWidget
111+
* @return Placement structure
112+
*/
113+
ContentWidgetPlacement widgetPlacement(ContentWidget* cw) const;
114+
115+
/**
116+
* Detach widget and place at screen position if info is given in setting file.
117+
* @param cw - Pointer to ContentWidget
118+
*/
119+
void widgetDetach(ContentWidget* cw) const;
120+
94121
/**
95122
* Get the value in the user settings file for a given key.
96123
*
@@ -107,6 +134,19 @@ namespace hal
107134
*/
108135
QVariant defaultValue(const QString& tag) const;
109136

137+
/**
138+
* Save state of splitter in setting file
139+
* @param tag - tag to save parameter
140+
* @param splitter - save settings for this splitter
141+
*/
142+
void saveSplitterState(const QString& tag, const QSplitter* splitter);
143+
144+
/**
145+
* Restore state of splitter from setting file
146+
* @param tag - tag for which the splitter gets restored
147+
* @param splitter - the splitter to be restored
148+
*/
149+
void restoreSplitterState(const QString& tag, QSplitter *splitter) const;
110150

111151
LoggerSettings loggerSettings() const;
112152

0 commit comments

Comments
 (0)