Ref T472, heap issue follow up + minor clean ups

* unfortunately the issue did still persist
* reason still unknown
* not expanding all seems to solve it

Maybe using the high level API without own model would be better
https://www.bogotobogo.com/Qt/Qt5_QTreeWidget.php
This commit is contained in:
Klaus Basan
2019-02-08 19:05:01 +01:00
committed by Mat Sutcliffe
parent d4ddcab84a
commit 474207eeab
3 changed files with 13 additions and 15 deletions

View File

@@ -12,6 +12,7 @@
#include "blackgui/models/columns.h"
#include "blackmisc/compare.h"
#include "blackmisc/icon.h"
#include "blackmisc/threadutils.h"
#include "blackmisc/variant.h"
#include "blackmisc/propertyindex.h"
@@ -40,6 +41,8 @@ namespace BlackGui
void CAircraftCategoryTreeModel::updateContainer(const CAircraftCategoryList &categories)
{
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Wrong thread");
this->clear();
if (categories.isEmpty()) { return; }
@@ -73,6 +76,8 @@ namespace BlackGui
// add all items
if (categoryRow.isEmpty()) { continue; }
QStandardItem *parent = categoryRow.first();
if (category.isFirstLevel())
{
this->invisibleRootItem()->appendRow(categoryRow);
@@ -83,9 +88,7 @@ namespace BlackGui
Q_ASSERT_X(items[p], Q_FUNC_INFO, "No parent item");
items[p]->appendRow(categoryRow);
}
Q_ASSERT_X(!categoryRow.isEmpty(), Q_FUNC_INFO, "Category row is empty");
items.insert(category.getDepth(), categoryRow.front());
items.insert(category.getDepth(), parent);
}
}

View File

@@ -32,14 +32,18 @@ namespace BlackGui
this->setModel(new CAircraftCategoryTreeModel(this));
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &CAircraftCategoryTreeView::customContextMenuRequested, this, &CAircraftCategoryTreeView::customMenu);
connect(this, &CAircraftCategoryTreeView::expanded, this, &CAircraftCategoryTreeView::onExpanded);
connect(this, &CAircraftCategoryTreeView::expanded, this, &CAircraftCategoryTreeView::onExpanded, Qt::QueuedConnection);
}
void CAircraftCategoryTreeView::updateContainer(const CAircraftCategoryList &categories)
{
if (!this->categoryModel()) { return; }
this->categoryModel()->updateContainer(categories);
if (!this->isEmpty()) { this->expandAll(); }
//! \fixme 2019-02 workaround for HEAP: Free Heap block 000001AB439BFFF0 modified at 000001AB439C00BC after it was freed
// using Qt::QueuedConnection seems to fix for expand all
// also this->expandToDepth(0) seems to work
this->expandAll();
}
void CAircraftCategoryTreeView::clear()
@@ -86,18 +90,12 @@ namespace BlackGui
CAircraftCategory CAircraftCategoryTreeView::selectedObject() const
{
const QModelIndex index = this->currentIndex();
const QVariant data = this->model()->data(index.siblingAtColumn(0)); // supposed to be the callsign
const QVariant data = this->model()->data(index.siblingAtColumn(0));
const CAircraftCategoryTreeModel *model = this->categoryModel();
if (!model) { return CAircraftCategory(); }
return model->container().frontOrDefault();
}
QString CAircraftCategoryTreeView::suffixForIndex(const QModelIndex &index)
{
const QVariant data = this->model()->data(index); // supposed to be the suffix
return data.toString();
}
void CAircraftCategoryTreeView::onExpanded(const QModelIndex &index)
{
Q_UNUSED(index);

View File

@@ -69,9 +69,6 @@ namespace BlackGui
//! The selected object
BlackMisc::Aviation::CAircraftCategory selectedObject() const;
//! Suffix for index
QString suffixForIndex(const QModelIndex &index);
//! Expanded
void onExpanded(const QModelIndex &index);