fixes #20 crash on-show.

checks for _sections.count() > 0 in dropContent() and creates first
SectionWidget, if needed.
This commit is contained in:
mfreiholz 2016-06-08 06:50:08 +02:00
parent 0be013bca2
commit 0317c3ebeb
2 changed files with 23 additions and 12 deletions

View File

@ -70,17 +70,6 @@ ContainerWidget::~ContainerWidget()
SectionWidget* ContainerWidget::addSectionContent(const SectionContent::RefPtr& sc, SectionWidget* sw, DropArea area)
{
ADS_Expects(!sc.isNull());
if (!sw)
{
if (_sections.isEmpty())
{ // Create default section
sw = newSectionWidget();
addSection(sw);
}
else if (area == CenterDropArea)
// Use existing default section
sw = _sections.first();
}
// Drop it based on "area"
InternalContentData data;
@ -496,6 +485,14 @@ SectionWidget* ContainerWidget::dropContent(const InternalContentData& data, Sec
SectionWidget* ret = NULL;
// If no sections exists yet, create a default one and always drop into it.
if (_sections.count() <= 0)
{
targetSection = newSectionWidget();
addSection(targetSection);
area = CenterDropArea;
}
// Drop on outer area
if (!targetSection)
{

View File

@ -116,9 +116,9 @@ MainWindow::MainWindow(QWidget *parent) :
}
// ADS - Adding some contents.
// Test #1: Use high-level public API
if (true)
{
// Test #1: Use high-level public API
ADS_NS::ContainerWidget* cw = _container;
ADS_NS::SectionWidget* sw = NULL;
@ -131,6 +131,20 @@ MainWindow::MainWindow(QWidget *parent) :
_container->addSectionContent(createLongTextLabelSC(_container));
_container->addSectionContent(createLongTextLabelSC(_container));
}
else if (false)
{
// Issue #2: If the first drop is not into CenterDropArea, the application crashes.
ADS_NS::ContainerWidget* cw = _container;
ADS_NS::SectionWidget* sw = NULL;
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::LeftDropArea);
sw = _container->addSectionContent(createCalendarSC(cw), sw, ADS_NS::LeftDropArea);
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::CenterDropArea);
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::CenterDropArea);
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::CenterDropArea);
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::RightDropArea);
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::BottomDropArea);
}
// Default window geometry
resize(800, 600);