Adds possibility to remove section contents.
This commit is contained in:
@@ -54,6 +54,13 @@ public:
|
||||
*/
|
||||
SectionWidget* addSectionContent(const SectionContent::RefPtr& sc, SectionWidget* sw = NULL, DropArea area = CenterDropArea);
|
||||
|
||||
/*!
|
||||
* Completely removes the <em>sc</em> from this ContainerWidget.
|
||||
* This container will no longer hold a reference to the content.
|
||||
* The content can be safely deleted.
|
||||
*/
|
||||
bool removeSectionContent(const SectionContent::RefPtr& sc);
|
||||
|
||||
/*!
|
||||
* Shows the specific SectionContent in UI.
|
||||
* Independed of the current state, whether it is used inside a section or is floating.
|
||||
@@ -101,6 +108,12 @@ public:
|
||||
QRect outerBottomDropRect() const;
|
||||
QRect outerLeftDropRect() const;
|
||||
|
||||
/*!
|
||||
* \brief contents
|
||||
* \return List of known SectionContent for this ContainerWidget.
|
||||
*/
|
||||
QList<SectionContent::RefPtr> contents() const;
|
||||
|
||||
private:
|
||||
//
|
||||
// Internal Stuff Begins Here
|
||||
|
||||
@@ -57,6 +57,9 @@ private:
|
||||
// Optional attributes
|
||||
QString _title;
|
||||
|
||||
/* Note: This method could be a problem in static build environment
|
||||
* since it may begin with 0 for every module which uses ADS.
|
||||
*/
|
||||
static int GetNextUid();
|
||||
};
|
||||
|
||||
|
||||
@@ -106,6 +106,49 @@ SectionWidget* ContainerWidget::addSectionContent(const SectionContent::RefPtr&
|
||||
return dropContent(data, sw, area, false);
|
||||
}
|
||||
|
||||
bool ContainerWidget::removeSectionContent(const SectionContent::RefPtr& sc)
|
||||
{
|
||||
// Hide the content.
|
||||
// The hideSectionContent() automatically deletes no longer required SectionWidget objects.
|
||||
if (!hideSectionContent(sc))
|
||||
return false;
|
||||
|
||||
// Begin of ugly work arround.
|
||||
// TODO The hideSectionContent() method should take care of deleting FloatingWidgets and SectionWidgets,
|
||||
// but only cares about SectionWidgets right now. So we need to check whether it was a FloatingWidget
|
||||
// and delete it.
|
||||
bool found = false;
|
||||
for (int i = 0; i < _floatings.count(); ++i)
|
||||
{
|
||||
FloatingWidget* fw = _floatings.at(i);
|
||||
InternalContentData data;
|
||||
if (!(found = fw->takeContent(data)))
|
||||
continue;
|
||||
_floatings.removeAll(fw);
|
||||
delete fw;
|
||||
delete data.titleWidget;
|
||||
delete data.contentWidget;
|
||||
break;
|
||||
} // End of ugly work arround.
|
||||
|
||||
// Get from hidden contents and delete associated internal stuff.
|
||||
if (!_hiddenSectionContents.contains(sc->uid()))
|
||||
{
|
||||
qFatal("Something went wrong... The content should have been there :-/");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Delete internal objects.
|
||||
HiddenSectionItem hsi = _hiddenSectionContents.take(sc->uid());
|
||||
delete hsi.data.titleWidget;
|
||||
delete hsi.data.contentWidget;
|
||||
|
||||
// Hide the custom widgets of SectionContent.
|
||||
// ... should we? ...
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ContainerWidget::showSectionContent(const SectionContent::RefPtr& sc)
|
||||
{
|
||||
// Search SC in floatings
|
||||
@@ -603,6 +646,19 @@ QRect ContainerWidget::outerLeftDropRect() const
|
||||
return QRect(r.left(), r.top(), w, r.height());
|
||||
}
|
||||
|
||||
QList<SectionContent::RefPtr> ContainerWidget::contents() const
|
||||
{
|
||||
QList<SectionContent::WeakPtr> wl = _scLookupMapById.values();
|
||||
QList<SectionContent::RefPtr> sl;
|
||||
for (int i = 0; i < wl.count(); ++i)
|
||||
{
|
||||
const SectionContent::RefPtr sc = wl.at(i).toStrongRef();
|
||||
if (sc)
|
||||
sl.append(sc);
|
||||
}
|
||||
return sl;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE API BEGINS HERE
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -21,6 +21,7 @@ SectionContentWidget::SectionContentWidget(SectionContent::RefPtr c, QWidget* pa
|
||||
SectionContentWidget::~SectionContentWidget()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
layout()->removeWidget(_content->contentWidget());
|
||||
}
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
|
||||
@@ -43,6 +43,7 @@ SectionTitleWidget::SectionTitleWidget(SectionContent::RefPtr content, QWidget*
|
||||
SectionTitleWidget::~SectionTitleWidget()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
layout()->removeWidget(_content->titleWidget());
|
||||
}
|
||||
|
||||
bool SectionTitleWidget::isActiveTab() const
|
||||
|
||||
Reference in New Issue
Block a user