Skip to content

Commit 5e6c82b

Browse files
author
Uwe Kindler
committed
Started implementing VisibleDockAreaCount cache
1 parent 268f865 commit 5e6c82b

File tree

6 files changed

+61
-45
lines changed

6 files changed

+61
-45
lines changed

src/DockAreaWidget.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
410410
//============================================================================
411411
void CDockAreaWidget::hideAreaWithNoVisibleContent()
412412
{
413-
this->hide();
413+
this->toggleView(false);
414414

415415
// Hide empty parent splitter
416416
auto Splitter = internal::findParent<CDockSplitter*>(this);
@@ -433,16 +433,6 @@ void CDockAreaWidget::hideAreaWithNoVisibleContent()
433433
}
434434

435435

436-
//============================================================================
437-
void CDockAreaWidget::hideAreaIfNoVisibleContent()
438-
{
439-
if (openedDockWidgets().isEmpty())
440-
{
441-
hideAreaIfNoVisibleContent();
442-
}
443-
}
444-
445-
446436
//============================================================================
447437
void CDockAreaWidget::onTabCloseRequested(int Index)
448438
{
@@ -668,18 +658,11 @@ CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const
668658

669659

670660
//============================================================================
671-
void CDockAreaWidget::setVisible(bool visible)
661+
void CDockAreaWidget::toggleView(bool Open)
672662
{
673-
Super::setVisible(visible);
674-
QString FirstDockWidgetLabel;
675-
if (dockWidgetsCount())
676-
{
677-
FirstDockWidgetLabel = dockWidget(0)->windowTitle();
678-
}
679-
qDebug() << "CDockAreaWidget::setVisible " << visible << " " << FirstDockWidgetLabel
680-
<< " count: " << dockWidgetsCount() << " open count: " << openDockWidgetsCount();
663+
setVisible(Open);
664+
emit viewToggled(Open);
681665
}
682-
683666
} // namespace ads
684667

685668
//---------------------------------------------------------------------------

src/DockAreaWidget.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ private slots:
116116
*/
117117
void hideAreaWithNoVisibleContent();
118118

119-
/**
120-
* This function checks, if the dock area has visible content, that means
121-
* if any dock widget is open, and then calls hideAreaWithNoVisibleContent()
122-
* if it does not find any visible content
123-
*/
124-
void hideAreaIfNoVisibleContent();
125-
126119
/**
127120
* Updates the dock area layout and components visibility
128121
*/
@@ -226,9 +219,10 @@ public slots:
226219
void setCurrentIndex(int index);
227220

228221
/**
229-
* This function is required for debugging purposes
222+
* This property controls whether the dock area is open or closed.
223+
* The toogleViewAction triggers this slot.
230224
*/
231-
virtual void setVisible(bool visible) override;
225+
void toggleView(bool Open);
232226

233227
signals:
234228
/**
@@ -249,6 +243,12 @@ public slots:
249243
* @param index
250244
*/
251245
void currentChanged(int index);
246+
247+
/**
248+
* This signal is emitted if the visibility of this dock area is toggled
249+
* via toggle view function
250+
*/
251+
void viewToggled(bool Open);
252252
}; // class DockAreaWidget
253253
}
254254
// namespace ads

src/DockContainerWidget.cpp

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ static void insertWidgetIntoSplitter(QSplitter* Splitter, QWidget* widget, bool
9393
/**
9494
* Private data class of CDockContainerWidget class (pimpl)
9595
*/
96-
struct DockContainerWidgetPrivate
96+
class DockContainerWidgetPrivate
9797
{
98+
public:
9899
CDockContainerWidget* _this;
99100
QPointer<CDockManager> DockManager;
100101
unsigned int zOrderIndex = 0;
@@ -103,6 +104,7 @@ struct DockContainerWidgetPrivate
103104
QSplitter* RootSplitter;
104105
bool isFloating = false;
105106
CDockAreaWidget* LastAddedAreaCache[5]{0, 0, 0, 0, 0};
107+
int VisibleDockAreaCount = -1;
106108

107109
/**
108110
* Private data constructor
@@ -176,6 +178,42 @@ struct DockContainerWidgetPrivate
176178
* Helper function for recursive dumping of layout
177179
*/
178180
void dumpRecursive(int level, QWidget* widget);
181+
182+
/**
183+
* Initializes the visible dock area count variable if it is not initialized
184+
* yet
185+
*/
186+
void initVisibleDockAreaCount()
187+
{
188+
if (VisibleDockAreaCount > -1)
189+
{
190+
return;
191+
}
192+
193+
VisibleDockAreaCount = 0;
194+
for (auto DockArea : DockAreas)
195+
{
196+
VisibleDockAreaCount += DockArea->isHidden() ? 0 : 1;
197+
}
198+
}
199+
200+
/**
201+
* Access function for the visible dock area counter
202+
*/
203+
int& visibleDockAreaCount()
204+
{
205+
// Lazy initialisation - we initialize the VisibleDockAreaCount variable
206+
// on first use
207+
initVisibleDockAreaCount();
208+
return VisibleDockAreaCount;
209+
}
210+
211+
// private slots: ------------------------------------------------------------
212+
void onDockAreaViewToggled(bool Visible)
213+
{
214+
std::cout << "onDockAreaViewToggled " << Visible << std::endl;
215+
VisibleDockAreaCount += Visible ? 1 : -1;
216+
}
179217
}; // struct DockContainerWidgetPrivate
180218

181219

@@ -922,15 +960,17 @@ int CDockContainerWidget::dockAreaCount() const
922960
//============================================================================
923961
int CDockContainerWidget::visibleDockAreaCount() const
924962
{
925-
// TODO Cache or precalculate this to speed it up because it is used during
926-
// movement of floating widget
927963
int Result = 0;
928964
for (auto DockArea : d->DockAreas)
929965
{
930966
Result += DockArea->isHidden() ? 0 : 1;
931967
}
932968

933969
return Result;
970+
971+
// TODO Cache or precalculate this to speed it up because it is used during
972+
// movement of floating widget
973+
//return d->visibleDockAreaCount();
934974
}
935975

936976

@@ -1029,6 +1069,7 @@ bool CDockContainerWidget::restoreState(QXmlStreamReader& s, bool Testing)
10291069
QWidget*NewRootSplitter {};
10301070
if (!Testing)
10311071
{
1072+
d->VisibleDockAreaCount = -1;// invalidate the dock area count
10321073
d->DockAreas.clear();
10331074
}
10341075

@@ -1162,9 +1203,8 @@ CDockWidget::DockWidgetFeatures CDockContainerWidget::features() const
11621203
return Features;
11631204
}
11641205

1165-
1166-
11671206
} // namespace ads
11681207

1208+
#include "moc_DockContainerWidget.cpp"
11691209
//---------------------------------------------------------------------------
11701210
// EOF DockContainerWidget.cpp

src/DockContainerWidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class QXmlStreamReader;
4040

4141
namespace ads
4242
{
43-
struct DockContainerWidgetPrivate;
43+
class DockContainerWidgetPrivate;
4444
class CDockAreaWidget;
4545
class CDockWidget;
4646
class CDockManager;
@@ -65,6 +65,7 @@ class ADS_EXPORT CDockContainerWidget : public QFrame
6565
friend class CFloatingDockContainer;
6666
friend struct FloatingDockContainerPrivate;
6767
friend class CDockWidget;
68+
Q_PRIVATE_SLOT(d, void onDockAreaViewToggled(bool Visible))
6869

6970
protected:
7071
/**

src/DockWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void DockWidgetPrivate::showDockWidget()
130130
}
131131
else
132132
{
133-
DockArea->show();
133+
DockArea->toggleView(true);
134134
DockArea->setCurrentDockWidget(_this);
135135
TabWidget->show();
136136
QSplitter* Splitter = internal::findParent<QSplitter*>(DockArea);

src/FloatingDockContainer.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,6 @@ void CFloatingDockContainer::showEvent(QShowEvent *event)
350350
{
351351
std::cout << "CFloatingDockContainer showEvent" << std::endl;
352352
QWidget::showEvent(event);
353-
/*for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
354-
{
355-
auto DockArea = DockContainer->dockArea(i);
356-
for (auto DockWidget : DockArea->openedDockWidgets())
357-
{
358-
DockWidget->setToggleViewActionChecked(true);
359-
}
360-
}*/
361353
for (auto DockArea : d->DockContainer->openedDockAreas())
362354
{
363355
for (auto DockWidget : DockArea->openedDockWidgets())

0 commit comments

Comments
 (0)