diff --git a/src/blackgui/models/aircraftcategorytreemodel.cpp b/src/blackgui/models/aircraftcategorytreemodel.cpp index e459748cc..682326659 100644 --- a/src/blackgui/models/aircraftcategorytreemodel.cpp +++ b/src/blackgui/models/aircraftcategorytreemodel.cpp @@ -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); } } diff --git a/src/blackgui/views/aircraftcategorytreeview.cpp b/src/blackgui/views/aircraftcategorytreeview.cpp index c1f8e5a28..b40e7e63a 100644 --- a/src/blackgui/views/aircraftcategorytreeview.cpp +++ b/src/blackgui/views/aircraftcategorytreeview.cpp @@ -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); diff --git a/src/blackgui/views/aircraftcategorytreeview.h b/src/blackgui/views/aircraftcategorytreeview.h index 10af2265f..4d9d404cd 100644 --- a/src/blackgui/views/aircraftcategorytreeview.h +++ b/src/blackgui/views/aircraftcategorytreeview.h @@ -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);