From 6b789bd1fba721e51e7ce60af78228d2cf2fa3b9 Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Wed, 7 Apr 2021 17:30:58 +0200 Subject: [PATCH 01/20] Add Button to UI that will open the Ifc Tree once it is implemented --- UserInterface/MainWindow.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/UserInterface/MainWindow.cpp b/UserInterface/MainWindow.cpp index f8e4654f2..64c8b7c9d 100644 --- a/UserInterface/MainWindow.cpp +++ b/UserInterface/MainWindow.cpp @@ -488,6 +488,7 @@ void OpenInfraPlatform::UserInterface::MainWindow::updateModelsUI() // - min, mid, max : QVector3D // 4. - GeoRef : georeferencing metadata // - key - val + // 5. - treeviewer : button (to open) // 1. filename auto itemModel = new QTreeWidgetItem(modelsTreeWidget_); @@ -534,6 +535,18 @@ void OpenInfraPlatform::UserInterface::MainWindow::updateModelsUI() // do nothing } + // 5. treeviewer + QString filetype = filename.right(3); + if (filetype == "ifc") + { + auto itemIfcTree = new QTreeWidgetItem(itemModel); + itemIfcTree->setText(0, "IfcTree"); + + QPushButton *openIfcTreeButton = new QPushButton(); + openIfcTreeButton->setText("Open Ifc Tree Dialog"); + modelsTreeWidget_->setItemWidget(itemIfcTree, 1, openIfcTreeButton); + } + // expanded per default itemModel->setExpanded(true); } From 4fab59d8a5a2491ba4b7f196fb9dce3239396f41 Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Thu, 8 Apr 2021 14:26:56 +0200 Subject: [PATCH 02/20] Add TreeDialog to UI --- CMakeLists.txt | 1 + UserInterface/Dialogues/IfcTreeDialog.cpp | 35 ++++++++++++++++ UserInterface/Dialogues/IfcTreeDialog.h | 50 +++++++++++++++++++++++ UserInterface/Forms/IfcTreeDialog.ui | 35 ++++++++++++++++ UserInterface/MainWindow.cpp | 12 +++++- UserInterface/MainWindow.h | 3 ++ 6 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 UserInterface/Dialogues/IfcTreeDialog.cpp create mode 100644 UserInterface/Dialogues/IfcTreeDialog.h create mode 100644 UserInterface/Forms/IfcTreeDialog.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index f2962d9bf..445460c9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -391,6 +391,7 @@ set(OpenInfraPlatform_UserInterface_Forms UserInterface/Forms/MainWindow.ui UserInterface/Forms/LicenseAndCopyrightInformation.ui UserInterface/Forms/PreferencesDialog.ui + UserInterface/Forms/IfcTreeDialog.ui # Currently not included. #UserInterface/Forms/CreateAccidentReport.ui diff --git a/UserInterface/Dialogues/IfcTreeDialog.cpp b/UserInterface/Dialogues/IfcTreeDialog.cpp new file mode 100644 index 000000000..5cff9e8ba --- /dev/null +++ b/UserInterface/Dialogues/IfcTreeDialog.cpp @@ -0,0 +1,35 @@ +/* + Copyright (c) 2021 Technical University of Munich + Chair of Computational Modeling and Simulation. + + TUM Open Infra Platform is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + TUM Open Infra Platform is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "IfcTreeDialog.h" + +OpenInfraPlatform::UserInterface::IfcTreeDialog::IfcTreeDialog(QWidget *parent /*= nullptr*/) : + QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint), + ui_(new Ui::IfcTreeDialog) +{ + ui_->setupUi(this); +} + +OpenInfraPlatform::UserInterface::IfcTreeDialog::~IfcTreeDialog() +{ + +} + +void OpenInfraPlatform::UserInterface::IfcTreeDialog::on_pushButtonClose_clicked() +{ + hide(); +} diff --git a/UserInterface/Dialogues/IfcTreeDialog.h b/UserInterface/Dialogues/IfcTreeDialog.h new file mode 100644 index 000000000..e5c920e63 --- /dev/null +++ b/UserInterface/Dialogues/IfcTreeDialog.h @@ -0,0 +1,50 @@ +/* + Copyright (c) 2021 Technical University of Munich + Chair of Computational Modeling and Simulation. + + TUM Open Infra Platform is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + TUM Open Infra Platform is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#pragma once + +#include "ui_IfcTreeDialog.h" +#include +#include + +namespace OpenInfraPlatform +{ + namespace UserInterface + { + class IfcTreeDialog : public QDialog + { + Q_OBJECT; + + public: + IfcTreeDialog(QWidget *parent = nullptr); + + //! Virtual destructor. + virtual ~IfcTreeDialog(); + + private Q_SLOTS: + void on_pushButtonClose_clicked(); + + private: + Ui::IfcTreeDialog* ui_; + }; // end class IfcTree + } // end namespace UserInterface +} // end namespace OpenInfraPlatform + +namespace buw +{ + using OpenInfraPlatform::UserInterface::IfcTreeDialog; +} diff --git a/UserInterface/Forms/IfcTreeDialog.ui b/UserInterface/Forms/IfcTreeDialog.ui new file mode 100644 index 000000000..f7ee712f9 --- /dev/null +++ b/UserInterface/Forms/IfcTreeDialog.ui @@ -0,0 +1,35 @@ + + + IfcTreeDialog + + + + 0 + 0 + 200 + 600 + + + + Ifc Tree Viewer + + + + + + Hierarchy Tree + + + + + + + Close + + + + + + + + \ No newline at end of file diff --git a/UserInterface/MainWindow.cpp b/UserInterface/MainWindow.cpp index 64c8b7c9d..24cd90df1 100644 --- a/UserInterface/MainWindow.cpp +++ b/UserInterface/MainWindow.cpp @@ -537,13 +537,15 @@ void OpenInfraPlatform::UserInterface::MainWindow::updateModelsUI() // 5. treeviewer QString filetype = filename.right(3); - if (filetype == "ifc") + if (std::dynamic_pointer_cast(model)) { auto itemIfcTree = new QTreeWidgetItem(itemModel); itemIfcTree->setText(0, "IfcTree"); QPushButton *openIfcTreeButton = new QPushButton(); + QTreeWidget *sdsd = new QTreeWidget(); openIfcTreeButton->setText("Open Ifc Tree Dialog"); + QObject::connect(openIfcTreeButton, SIGNAL(clicked()), this, SLOT(on_actionShow_Ifc_Tree_triggered())); modelsTreeWidget_->setItemWidget(itemIfcTree, 1, openIfcTreeButton); } @@ -1805,6 +1807,14 @@ void OpenInfraPlatform::UserInterface::MainWindow::on_actionShow_License_and_Cop licenseAndCopyrightInformationDialog_->show(); } +void OpenInfraPlatform::UserInterface::MainWindow::on_actionShow_Ifc_Tree_triggered() { + if (ifcTreeDialog_ == nullptr) { + ifcTreeDialog_ = new IfcTreeDialog(this); + } + + ifcTreeDialog_->show(); +} + void OpenInfraPlatform::UserInterface::MainWindow::on_actionShow_Log_Folder_triggered() { // TODO: Find a way to do this with pure Qt or move it at least to an own // function that can be reused by on_actionShow_Log_File_triggered diff --git a/UserInterface/MainWindow.h b/UserInterface/MainWindow.h index c9528ed0c..f368180b5 100644 --- a/UserInterface/MainWindow.h +++ b/UserInterface/MainWindow.h @@ -22,6 +22,7 @@ #include "../UserInterface/ViewPanel/View.h" #include "../UserInterface/Dialogues/LicenseAndCopyrightInformationDialog.h" +#include "../UserInterface/Dialogues/IfcTreeDialog.h" #include "DataManagement/General/Data.h" #include "../UserInterface/Dialogues/PreferencesDialog.h" #include "../Core/src/DataManagement/General/ProgressCallback.h" @@ -141,6 +142,7 @@ namespace OpenInfraPlatform //void on_actionIFC_Alignment_1_1_Export_triggered(); void on_actionShow_License_and_Copyright_Information_triggered(); + void on_actionShow_Ifc_Tree_triggered(); void on_actionShow_Log_Folder_triggered(); @@ -366,6 +368,7 @@ namespace OpenInfraPlatform PreferencesDialog* preferencesDialog_ = nullptr; QProgressDialog* progressDialog_ = nullptr; LicenseAndCopyrightInformationDialog* licenseAndCopyrightInformationDialog_ = nullptr; + IfcTreeDialog* ifcTreeDialog_ = nullptr; QProgressBar* progressBar_; From 773bafec4abe7926265134fda6c711d8a96c915c Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Thu, 15 Apr 2021 17:20:48 +0200 Subject: [PATCH 03/20] Adding first part of the tree model and tree item (not working yet) --- UserInterface/Dialogues/IfcTreeDialog.cpp | 8 +++ UserInterface/Dialogues/IfcTreeDialog.h | 2 + UserInterface/Dialogues/IfcTreeItem.cpp | 0 UserInterface/Dialogues/IfcTreeItem.h | 59 +++++++++++++++++++++++ UserInterface/Dialogues/IfcTreeModel.cpp | 0 UserInterface/Dialogues/IfcTreeModel.h | 47 ++++++++++++++++++ UserInterface/MainWindow.cpp | 1 - 7 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 UserInterface/Dialogues/IfcTreeItem.cpp create mode 100644 UserInterface/Dialogues/IfcTreeItem.h create mode 100644 UserInterface/Dialogues/IfcTreeModel.cpp create mode 100644 UserInterface/Dialogues/IfcTreeModel.h diff --git a/UserInterface/Dialogues/IfcTreeDialog.cpp b/UserInterface/Dialogues/IfcTreeDialog.cpp index 5cff9e8ba..afada962c 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.cpp +++ b/UserInterface/Dialogues/IfcTreeDialog.cpp @@ -16,6 +16,8 @@ */ #include "IfcTreeDialog.h" +#include "IfcTreeModel.h" +#include "ui_IfcTreeDialog.h" OpenInfraPlatform::UserInterface::IfcTreeDialog::IfcTreeDialog(QWidget *parent /*= nullptr*/) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint), @@ -29,6 +31,12 @@ OpenInfraPlatform::UserInterface::IfcTreeDialog::~IfcTreeDialog() } +void OpenInfraPlatform::UserInterface::IfcTreeDialog::setModel() +{ + //ui_->ifcTreeView->setModel(new IfcTreeModel()); + //((QDialog*)this)->show(); +} + void OpenInfraPlatform::UserInterface::IfcTreeDialog::on_pushButtonClose_clicked() { hide(); diff --git a/UserInterface/Dialogues/IfcTreeDialog.h b/UserInterface/Dialogues/IfcTreeDialog.h index e5c920e63..75bf8ff8f 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.h +++ b/UserInterface/Dialogues/IfcTreeDialog.h @@ -35,6 +35,8 @@ namespace OpenInfraPlatform //! Virtual destructor. virtual ~IfcTreeDialog(); + void setModel(); + private Q_SLOTS: void on_pushButtonClose_clicked(); diff --git a/UserInterface/Dialogues/IfcTreeItem.cpp b/UserInterface/Dialogues/IfcTreeItem.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/UserInterface/Dialogues/IfcTreeItem.h b/UserInterface/Dialogues/IfcTreeItem.h new file mode 100644 index 000000000..16731b6fe --- /dev/null +++ b/UserInterface/Dialogues/IfcTreeItem.h @@ -0,0 +1,59 @@ +/* + Copyright (c) 2021 Technical University of Munich + Chair of Computational Modeling and Simulation. + + TUM Open Infra Platform is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + TUM Open Infra Platform is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef IFCTREEITEM_H +#define IFCTREEITEM_H + +#include "EXPRESS/EXPRESSReference.h" + + +namespace OpenInfraPlatform { + namespace UserInterface { + + class IfcTreeItem + { + public: + explicit IfcTreeItem(std::shared_ptr parentItem = nullptr); + ~IfcTreeItem(); + + void appendchild(std::shared_ptr child); + + std::shared_ptr child(int row); + int childCount() const; + int columnCount() const; + QVariant data(int column, int row) const; + int row() const; + std::shared_ptr parentItem(); + QString getIfcClassName(); + + private: + QList> childItems_; + std::vector data_; + std::shared_ptr parentItem_; + + struct getAttributeDescription; + }; + } +} + + +#endif //IFCTREITEM_H + +namespace buw +{ + using OpenInfraPlatform::UserInterface::IfcTreeItem; +} \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeModel.cpp b/UserInterface/Dialogues/IfcTreeModel.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/UserInterface/Dialogues/IfcTreeModel.h b/UserInterface/Dialogues/IfcTreeModel.h new file mode 100644 index 000000000..a047914bf --- /dev/null +++ b/UserInterface/Dialogues/IfcTreeModel.h @@ -0,0 +1,47 @@ +/* + Copyright (c) 2021 Technical University of Munich + Chair of Computational Modeling and Simulation. + + TUM Open Infra Platform is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + TUM Open Infra Platform is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#pragma once + +#include "IfcTreeItem.h" + +#include + +namespace OpenInfraPlatform { + namespace UserInterface { + + class IfcTreeModel : public QAbstractItemModel { + Q_OBJECT; + + public: + IfcTreeModel(); + ~IfcTreeModel(); + + //override from QAbstractItemModel + virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override; + virtual QModelIndex parent(const QModelIndex & child) const override; + virtual int rowCount(const QModelIndex & parent = QModelIndex()) const override; + virtual int columnCount(const QModelIndex & patent = QModelIndex()) const override; + virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; + virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; + + private: + std::vector> data_; + }; + + } +} \ No newline at end of file diff --git a/UserInterface/MainWindow.cpp b/UserInterface/MainWindow.cpp index 24cd90df1..aa8b7fac1 100644 --- a/UserInterface/MainWindow.cpp +++ b/UserInterface/MainWindow.cpp @@ -543,7 +543,6 @@ void OpenInfraPlatform::UserInterface::MainWindow::updateModelsUI() itemIfcTree->setText(0, "IfcTree"); QPushButton *openIfcTreeButton = new QPushButton(); - QTreeWidget *sdsd = new QTreeWidget(); openIfcTreeButton->setText("Open Ifc Tree Dialog"); QObject::connect(openIfcTreeButton, SIGNAL(clicked()), this, SLOT(on_actionShow_Ifc_Tree_triggered())); modelsTreeWidget_->setItemWidget(itemIfcTree, 1, openIfcTreeButton); From 49fe4850a1222bc8e1d677ef871de3ec55f68fc3 Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Tue, 20 Apr 2021 13:55:59 +0200 Subject: [PATCH 04/20] Small changes maily to treeModel and treeItem --- UserInterface/Dialogues/IfcTreeDialog.h | 4 +-- UserInterface/Dialogues/IfcTreeItem.h | 11 ++++---- UserInterface/Dialogues/IfcTreeModel.h | 36 ++++++++++++++++--------- UserInterface/MainWindow.cpp | 1 - 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/UserInterface/Dialogues/IfcTreeDialog.h b/UserInterface/Dialogues/IfcTreeDialog.h index 75bf8ff8f..020657d9d 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.h +++ b/UserInterface/Dialogues/IfcTreeDialog.h @@ -35,7 +35,7 @@ namespace OpenInfraPlatform //! Virtual destructor. virtual ~IfcTreeDialog(); - void setModel(); + void show(); private Q_SLOTS: void on_pushButtonClose_clicked(); @@ -46,7 +46,7 @@ namespace OpenInfraPlatform } // end namespace UserInterface } // end namespace OpenInfraPlatform -namespace buw +namespace oip { using OpenInfraPlatform::UserInterface::IfcTreeDialog; } diff --git a/UserInterface/Dialogues/IfcTreeItem.h b/UserInterface/Dialogues/IfcTreeItem.h index 16731b6fe..58b051223 100644 --- a/UserInterface/Dialogues/IfcTreeItem.h +++ b/UserInterface/Dialogues/IfcTreeItem.h @@ -19,6 +19,7 @@ #define IFCTREEITEM_H #include "EXPRESS/EXPRESSReference.h" +#include namespace OpenInfraPlatform { @@ -27,7 +28,7 @@ namespace OpenInfraPlatform { class IfcTreeItem { public: - explicit IfcTreeItem(std::shared_ptr parentItem = nullptr); + IfcTreeItem(std::shared_ptr data, std::shared_ptr parentItem = nullptr); ~IfcTreeItem(); void appendchild(std::shared_ptr child); @@ -35,14 +36,14 @@ namespace OpenInfraPlatform { std::shared_ptr child(int row); int childCount() const; int columnCount() const; - QVariant data(int column, int row) const; + QVariant data(int row, int column) const; int row() const; std::shared_ptr parentItem(); - QString getIfcClassName(); + QString getIfcClassName() const; private: QList> childItems_; - std::vector data_; + std::shared_ptr data_; std::shared_ptr parentItem_; struct getAttributeDescription; @@ -53,7 +54,7 @@ namespace OpenInfraPlatform { #endif //IFCTREITEM_H -namespace buw +namespace oip { using OpenInfraPlatform::UserInterface::IfcTreeItem; } \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeModel.h b/UserInterface/Dialogues/IfcTreeModel.h index a047914bf..2afaf9d9c 100644 --- a/UserInterface/Dialogues/IfcTreeModel.h +++ b/UserInterface/Dialogues/IfcTreeModel.h @@ -15,33 +15,43 @@ along with this program. If not, see . */ -#pragma once +#ifndef IFCTREEMODEL_H +#define IFCTREEMODEL_H #include "IfcTreeItem.h" #include +#include +#include -namespace OpenInfraPlatform { - namespace UserInterface { - class IfcTreeModel : public QAbstractItemModel { +namespace OpenInfraPlatform +{ + namespace UserInterface + { + + class IfcTreeModel : public QAbstractItemModel + { Q_OBJECT; public: - IfcTreeModel(); + IfcTreeModel(std::shared_ptr entities, QObject *parent = nullptr); ~IfcTreeModel(); //override from QAbstractItemModel - virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override; - virtual QModelIndex parent(const QModelIndex & child) const override; - virtual int rowCount(const QModelIndex & parent = QModelIndex()) const override; - virtual int columnCount(const QModelIndex & patent = QModelIndex()) const override; - virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; - virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override; + QModelIndex parent(const QModelIndex &index) const override; + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; private: - std::vector> data_; + void setupModelData(std::shared_ptr entities, IfcTreeItem *parent); + + IfcTreeItem *rootItem_; }; } -} \ No newline at end of file +} + +#endif //TREEMODEL_H \ No newline at end of file diff --git a/UserInterface/MainWindow.cpp b/UserInterface/MainWindow.cpp index aa8b7fac1..44cc54a3b 100644 --- a/UserInterface/MainWindow.cpp +++ b/UserInterface/MainWindow.cpp @@ -536,7 +536,6 @@ void OpenInfraPlatform::UserInterface::MainWindow::updateModelsUI() } // 5. treeviewer - QString filetype = filename.right(3); if (std::dynamic_pointer_cast(model)) { auto itemIfcTree = new QTreeWidgetItem(itemModel); From 4383357453ed6b3eb20df010438b138ed33270fb Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Tue, 20 Apr 2021 21:43:23 +0200 Subject: [PATCH 05/20] Adding a ExpressModel to the ifcModel in order to be able to access it in the tree viewer dialog --- .../IfcGeometryConverter/IfcGeometryModel.cpp | 6 ++++++ .../IfcGeometryConverter/IfcGeometryModel.h | 10 ++++++++-- Core/src/IfcGeometryConverter/IfcImporter.h | 3 +++ UserInterface/Dialogues/IfcTreeDialog.cpp | 18 ++++++++++++++---- UserInterface/Dialogues/IfcTreeDialog.h | 7 +++++-- UserInterface/MainWindow.cpp | 2 +- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Core/src/IfcGeometryConverter/IfcGeometryModel.cpp b/Core/src/IfcGeometryConverter/IfcGeometryModel.cpp index 3836d3fc1..f5752642b 100644 --- a/Core/src/IfcGeometryConverter/IfcGeometryModel.cpp +++ b/Core/src/IfcGeometryConverter/IfcGeometryModel.cpp @@ -19,6 +19,7 @@ #include "IfcGeometryModel.h" #include "Exception\UnhandledException.h" + void OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::reset() { for( auto geom : geometries_ ) @@ -37,6 +38,11 @@ void OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::addGeometry(std::s geometryMutex_.unlock(); } +void OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::addExpressModel(std::shared_ptr expressModel) +{ + expressModel_ = expressModel; +} + // --------------------------------------------------------------------------------------------------------------------------------------------------- // Interface IModel implementation bool OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::isEmpty() const diff --git a/Core/src/IfcGeometryConverter/IfcGeometryModel.h b/Core/src/IfcGeometryConverter/IfcGeometryModel.h index 207904f0a..8ec43eebe 100644 --- a/Core/src/IfcGeometryConverter/IfcGeometryModel.h +++ b/Core/src/IfcGeometryConverter/IfcGeometryModel.h @@ -30,6 +30,7 @@ #include #include "namespace.h" +#include "EXPRESS/EXPRESSModel.h" typedef buw::VertexPosition3Color3Normal3 VertexLayout; @@ -80,8 +81,10 @@ namespace OpenInfraPlatform std::vector> geometries_; std::mutex geometryMutex_; - std::string filename_; - oip::GeorefMetadata georefMeta_; + std::string filename_; + oip::GeorefMetadata georefMeta_; + + std::shared_ptr expressModel_; public: void reset(); @@ -89,6 +92,9 @@ namespace OpenInfraPlatform void addGeometry(std::shared_ptr geometry); std::vector> const &geometries() const { return geometries_; } + void addExpressModel(std::shared_ptr expressModel); + std::shared_ptr const getExpressModel() const { return expressModel_; } + // --------------------------------------------------------------------------------------------------------------------------------------------------- // Interface IModel implementation // --------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/Core/src/IfcGeometryConverter/IfcImporter.h b/Core/src/IfcGeometryConverter/IfcImporter.h index 472e0261b..76f3abe8c 100644 --- a/Core/src/IfcGeometryConverter/IfcImporter.h +++ b/Core/src/IfcGeometryConverter/IfcImporter.h @@ -77,6 +77,9 @@ class IfcImporterT georefConverter->init(expressModel); ifcModel->setGeoref(georefConverter->getGeorefMetadata()); + //store a pointer to the express model in the in the ifc model (used for the tree viewer) + ifcModel->addExpressModel(expressModel); + // collect all geometries if (!collectGeometryData(expressModel)) return ifcModel; diff --git a/UserInterface/Dialogues/IfcTreeDialog.cpp b/UserInterface/Dialogues/IfcTreeDialog.cpp index afada962c..bd87df0ae 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.cpp +++ b/UserInterface/Dialogues/IfcTreeDialog.cpp @@ -18,12 +18,16 @@ #include "IfcTreeDialog.h" #include "IfcTreeModel.h" #include "ui_IfcTreeDialog.h" +#include "DataManagement/General/Data.h" -OpenInfraPlatform::UserInterface::IfcTreeDialog::IfcTreeDialog(QWidget *parent /*= nullptr*/) : +OpenInfraPlatform::UserInterface::IfcTreeDialog::IfcTreeDialog(OpenInfraPlatform::UserInterface::View* view, QWidget *parent /*= nullptr*/) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint), - ui_(new Ui::IfcTreeDialog) + ui_(new Ui::IfcTreeDialog), + view_(view) { ui_->setupUi(this); + //ui_->ifcTreeWidget->setAnimated(true); + //ui_->ifcTreeView->setModel(new IfcTreeModel()); } OpenInfraPlatform::UserInterface::IfcTreeDialog::~IfcTreeDialog() @@ -31,12 +35,18 @@ OpenInfraPlatform::UserInterface::IfcTreeDialog::~IfcTreeDialog() } -void OpenInfraPlatform::UserInterface::IfcTreeDialog::setModel() +void OpenInfraPlatform::UserInterface::IfcTreeDialog::show() { + //for first testing just get last model, later this will be changed to selecting the model need + auto model = Core::DataManagement::DocumentManager::getInstance().getData().getLastModel(); + auto ifcModel = std::static_pointer_cast(model); + auto entities = ifcModel->getExpressModel(); + ui_->ifcTreeView->setAnimated(true); //ui_->ifcTreeView->setModel(new IfcTreeModel()); - //((QDialog*)this)->show(); + ((QDialog*)this)->show(); } + void OpenInfraPlatform::UserInterface::IfcTreeDialog::on_pushButtonClose_clicked() { hide(); diff --git a/UserInterface/Dialogues/IfcTreeDialog.h b/UserInterface/Dialogues/IfcTreeDialog.h index 020657d9d..59c062956 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.h +++ b/UserInterface/Dialogues/IfcTreeDialog.h @@ -18,6 +18,8 @@ #pragma once #include "ui_IfcTreeDialog.h" +#include "ViewPanel/View.h" + #include #include @@ -30,7 +32,7 @@ namespace OpenInfraPlatform Q_OBJECT; public: - IfcTreeDialog(QWidget *parent = nullptr); + IfcTreeDialog(OpenInfraPlatform::UserInterface::View* view, QWidget *parent = nullptr); //! Virtual destructor. virtual ~IfcTreeDialog(); @@ -41,7 +43,8 @@ namespace OpenInfraPlatform void on_pushButtonClose_clicked(); private: - Ui::IfcTreeDialog* ui_; + Ui::IfcTreeDialog* ui_; + OpenInfraPlatform::UserInterface::View* view_; }; // end class IfcTree } // end namespace UserInterface } // end namespace OpenInfraPlatform diff --git a/UserInterface/MainWindow.cpp b/UserInterface/MainWindow.cpp index 44cc54a3b..6ca0ee9fe 100644 --- a/UserInterface/MainWindow.cpp +++ b/UserInterface/MainWindow.cpp @@ -1807,7 +1807,7 @@ void OpenInfraPlatform::UserInterface::MainWindow::on_actionShow_License_and_Cop void OpenInfraPlatform::UserInterface::MainWindow::on_actionShow_Ifc_Tree_triggered() { if (ifcTreeDialog_ == nullptr) { - ifcTreeDialog_ = new IfcTreeDialog(this); + ifcTreeDialog_ = new IfcTreeDialog(view_, this); } ifcTreeDialog_->show(); From 02418af59f6ac4b5ad55a65f4675eb9635d4370f Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Wed, 21 Apr 2021 12:39:37 +0200 Subject: [PATCH 06/20] Add IfcTreeItem.cpp + some minor changes --- UserInterface/Dialogues/IfcTreeDialog.cpp | 6 +- UserInterface/Dialogues/IfcTreeItem.cpp | 131 ++++++++++++++++++++++ UserInterface/Dialogues/IfcTreeItem.h | 6 +- UserInterface/Dialogues/IfcTreeModel.h | 17 +-- 4 files changed, 146 insertions(+), 14 deletions(-) diff --git a/UserInterface/Dialogues/IfcTreeDialog.cpp b/UserInterface/Dialogues/IfcTreeDialog.cpp index bd87df0ae..abe57a8ba 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.cpp +++ b/UserInterface/Dialogues/IfcTreeDialog.cpp @@ -40,9 +40,9 @@ void OpenInfraPlatform::UserInterface::IfcTreeDialog::show() //for first testing just get last model, later this will be changed to selecting the model need auto model = Core::DataManagement::DocumentManager::getInstance().getData().getLastModel(); auto ifcModel = std::static_pointer_cast(model); - auto entities = ifcModel->getExpressModel(); - ui_->ifcTreeView->setAnimated(true); - //ui_->ifcTreeView->setModel(new IfcTreeModel()); + auto expressModel = ifcModel->getExpressModel(); + auto treeModel = new IfcTreeModel(expressModel); + ui_->ifcTreeView->setModel(treeModel); ((QDialog*)this)->show(); } diff --git a/UserInterface/Dialogues/IfcTreeItem.cpp b/UserInterface/Dialogues/IfcTreeItem.cpp index e69de29bb..e45ccf73c 100644 --- a/UserInterface/Dialogues/IfcTreeItem.cpp +++ b/UserInterface/Dialogues/IfcTreeItem.cpp @@ -0,0 +1,131 @@ +/* + Copyright (c) 2021 Technical University of Munich + Chair of Computational Modeling and Simulation. + + TUM Open Infra Platform is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + TUM Open Infra Platform is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "IfcTreeItem.h" +#include +#include +#include +#include "Exception\UnhandledException.h" +#include "visit_struct\visit_struct.hpp" + + +OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(std::shared_ptr data, std::shared_ptr parentItem) + :data_(data), parentItem_(parentItem) +{} + +OpenInfraPlatform::UserInterface::IfcTreeItem::~IfcTreeItem() +{ + childItems_.clear(); +} + +void OpenInfraPlatform::UserInterface::IfcTreeItem::appendchild(std::shared_ptr child) +{ + childItems_.append(child); +} + +std::shared_ptr OpenInfraPlatform::UserInterface::IfcTreeItem::child(int row) +{ + if (row < 0 || row >= childItems_.size()) + return nullptr; + return childItems_.at(row); +} + +int OpenInfraPlatform::UserInterface::IfcTreeItem::childCount() const +{ + return childItems_.count(); +} + +int OpenInfraPlatform::UserInterface::IfcTreeItem::columnCount() const +{ + return 3; +} + +QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int row, int column) const +{ + //auto attributes = getAttributeDescription(); + + //switch (column) + //{ + //case 0: + // return attributes.names_[row]; + // break; + //case 1: + // return attributes.value_[row]; + // break; + //case 2: + // return attributes.typename_[row]; + // break; + //} + return QVariant(); +} + +int OpenInfraPlatform::UserInterface::IfcTreeItem::row() +{ + if (parentItem_) + { + return parentItem_->childItems_.indexOf(shared_from_this()); + } + return 0; +} + +std::shared_ptr OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() +{ + if (parentItem_) + return parentItem_; + + return std::shared_ptr(); +} + +QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const +{ + std::string ifcClassName = data_->classname(); + return QString::fromStdString(ifcClassName); +} + +struct OpenInfraPlatform::UserInterface::IfcTreeItem::getAttributeDescription +{ + + template typename std::enable_if::value && std::is_base_of::value, void>::type + operator()(T entity) + { + visit_struct::for_each(entity, [&](const char* name, const auto &value) { + names_.push_back(name); + typename_ = typeid(T).name(entity); + value_.push_back(value); + + }); + } + + //This is a dummy function which should never be called but is required by the compiler since it could theoretically be called. Throws exception. + template typename std::enable_if::value, void>::type + operator()(T& entity) const + { + std::string message = "Invalid function call. " + std::string(typeid(entity).name()) + " isn't a member of EXPRESSEntity."; + throw buw::Exception(message); + } + + //This is a dummy function which should never be called but is required by the compiler since it could theoretically be called. Throws exception. + void operator()(OpenInfraPlatform::EarlyBinding::EXPRESSEntity& entity) const + { + throw oip::UnhandledException("Invalid function call (IfcTreeItem::getAttributeDescription)"); + } + + std::vector names_; + std::vector typename_; + std::vector value_; + +}; \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeItem.h b/UserInterface/Dialogues/IfcTreeItem.h index 58b051223..f3d55678d 100644 --- a/UserInterface/Dialogues/IfcTreeItem.h +++ b/UserInterface/Dialogues/IfcTreeItem.h @@ -25,7 +25,7 @@ namespace OpenInfraPlatform { namespace UserInterface { - class IfcTreeItem + class IfcTreeItem : public std::enable_shared_from_this { public: IfcTreeItem(std::shared_ptr data, std::shared_ptr parentItem = nullptr); @@ -37,7 +37,7 @@ namespace OpenInfraPlatform { int childCount() const; int columnCount() const; QVariant data(int row, int column) const; - int row() const; + int row(); std::shared_ptr parentItem(); QString getIfcClassName() const; @@ -52,7 +52,7 @@ namespace OpenInfraPlatform { } -#endif //IFCTREITEM_H +#endif //IFCTREEITEM_H namespace oip { diff --git a/UserInterface/Dialogues/IfcTreeModel.h b/UserInterface/Dialogues/IfcTreeModel.h index 2afaf9d9c..8489fa240 100644 --- a/UserInterface/Dialogues/IfcTreeModel.h +++ b/UserInterface/Dialogues/IfcTreeModel.h @@ -19,6 +19,7 @@ #define IFCTREEMODEL_H #include "IfcTreeItem.h" +#include "EXPRESS/EXPRESSEntity.h" #include #include @@ -35,20 +36,20 @@ namespace OpenInfraPlatform Q_OBJECT; public: - IfcTreeModel(std::shared_ptr entities, QObject *parent = nullptr); + IfcTreeModel(std::shared_ptr expressModel, QObject *parent = nullptr); ~IfcTreeModel(); //override from QAbstractItemModel - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override; - QModelIndex parent(const QModelIndex &index) const override; - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - int columnCount(const QModelIndex &parent = QModelIndex()) const override; + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + virtual QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override; + virtual QModelIndex parent(const QModelIndex &index) const override; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override; private: - void setupModelData(std::shared_ptr entities, IfcTreeItem *parent); + void setupModelData(std::shared_ptr expressModel, std::shared_ptr parent); - IfcTreeItem *rootItem_; + std::shared_ptr rootItem_; }; } From 6de63e93f3420e84a4832066e5ba6fe12d82e57f Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Fri, 23 Apr 2021 10:28:12 +0200 Subject: [PATCH 07/20] Small improvements --- .../IfcGeometryConverter/IfcGeometryModel.cpp | 2 +- .../IfcGeometryConverter/IfcGeometryModel.h | 2 +- Core/src/IfcGeometryConverter/IfcImporter.h | 2 +- UserInterface/Dialogues/IfcTreeDialog.cpp | 19 ++++++++++++++----- UserInterface/Dialogues/IfcTreeItem.cpp | 6 ++---- UserInterface/Forms/IfcTreeDialog.ui | 5 +---- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Core/src/IfcGeometryConverter/IfcGeometryModel.cpp b/Core/src/IfcGeometryConverter/IfcGeometryModel.cpp index f5752642b..9cb1ec812 100644 --- a/Core/src/IfcGeometryConverter/IfcGeometryModel.cpp +++ b/Core/src/IfcGeometryConverter/IfcGeometryModel.cpp @@ -38,7 +38,7 @@ void OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::addGeometry(std::s geometryMutex_.unlock(); } -void OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::addExpressModel(std::shared_ptr expressModel) +void OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::setExpressModel(std::shared_ptr expressModel) { expressModel_ = expressModel; } diff --git a/Core/src/IfcGeometryConverter/IfcGeometryModel.h b/Core/src/IfcGeometryConverter/IfcGeometryModel.h index 8ec43eebe..0736faf9f 100644 --- a/Core/src/IfcGeometryConverter/IfcGeometryModel.h +++ b/Core/src/IfcGeometryConverter/IfcGeometryModel.h @@ -92,7 +92,7 @@ namespace OpenInfraPlatform void addGeometry(std::shared_ptr geometry); std::vector> const &geometries() const { return geometries_; } - void addExpressModel(std::shared_ptr expressModel); + void setExpressModel(std::shared_ptr expressModel); std::shared_ptr const getExpressModel() const { return expressModel_; } // --------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/Core/src/IfcGeometryConverter/IfcImporter.h b/Core/src/IfcGeometryConverter/IfcImporter.h index 76f3abe8c..16fb54f2e 100644 --- a/Core/src/IfcGeometryConverter/IfcImporter.h +++ b/Core/src/IfcGeometryConverter/IfcImporter.h @@ -78,7 +78,7 @@ class IfcImporterT ifcModel->setGeoref(georefConverter->getGeorefMetadata()); //store a pointer to the express model in the in the ifc model (used for the tree viewer) - ifcModel->addExpressModel(expressModel); + ifcModel->setExpressModel(expressModel); // collect all geometries if (!collectGeometryData(expressModel)) diff --git a/UserInterface/Dialogues/IfcTreeDialog.cpp b/UserInterface/Dialogues/IfcTreeDialog.cpp index abe57a8ba..69f237910 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.cpp +++ b/UserInterface/Dialogues/IfcTreeDialog.cpp @@ -19,6 +19,7 @@ #include "IfcTreeModel.h" #include "ui_IfcTreeDialog.h" #include "DataManagement/General/Data.h" +#include "Exception\UnhandledException.h" OpenInfraPlatform::UserInterface::IfcTreeDialog::IfcTreeDialog(OpenInfraPlatform::UserInterface::View* view, QWidget *parent /*= nullptr*/) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint), @@ -39,11 +40,19 @@ void OpenInfraPlatform::UserInterface::IfcTreeDialog::show() { //for first testing just get last model, later this will be changed to selecting the model need auto model = Core::DataManagement::DocumentManager::getInstance().getData().getLastModel(); - auto ifcModel = std::static_pointer_cast(model); - auto expressModel = ifcModel->getExpressModel(); - auto treeModel = new IfcTreeModel(expressModel); - ui_->ifcTreeView->setModel(treeModel); - ((QDialog*)this)->show(); + if (std::dynamic_pointer_cast(model)) + { + auto ifcModel = std::static_pointer_cast(model); + auto expressModel = ifcModel->getExpressModel(); + auto treeModel = new IfcTreeModel(expressModel); + ui_->ifcTreeView->setModel(treeModel); + ((QDialog*)this)->show(); + } + else + { + //only for now till the selected model is properly handled + throw oip::UnhandledException("Last model is not a IFC model"); + } } diff --git a/UserInterface/Dialogues/IfcTreeItem.cpp b/UserInterface/Dialogues/IfcTreeItem.cpp index e45ccf73c..c77527f29 100644 --- a/UserInterface/Dialogues/IfcTreeItem.cpp +++ b/UserInterface/Dialogues/IfcTreeItem.cpp @@ -40,7 +40,8 @@ void OpenInfraPlatform::UserInterface::IfcTreeItem::appendchild(std::shared_ptr< std::shared_ptr OpenInfraPlatform::UserInterface::IfcTreeItem::child(int row) { if (row < 0 || row >= childItems_.size()) - return nullptr; + throw oip::UnhandledException("Child index out of range (IfcTreeItem::child)"); + return childItems_.at(row); } @@ -98,7 +99,6 @@ QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const struct OpenInfraPlatform::UserInterface::IfcTreeItem::getAttributeDescription { - template typename std::enable_if::value && std::is_base_of::value, void>::type operator()(T entity) { @@ -106,7 +106,6 @@ struct OpenInfraPlatform::UserInterface::IfcTreeItem::getAttributeDescription names_.push_back(name); typename_ = typeid(T).name(entity); value_.push_back(value); - }); } @@ -127,5 +126,4 @@ struct OpenInfraPlatform::UserInterface::IfcTreeItem::getAttributeDescription std::vector names_; std::vector typename_; std::vector value_; - }; \ No newline at end of file diff --git a/UserInterface/Forms/IfcTreeDialog.ui b/UserInterface/Forms/IfcTreeDialog.ui index f7ee712f9..580bb8406 100644 --- a/UserInterface/Forms/IfcTreeDialog.ui +++ b/UserInterface/Forms/IfcTreeDialog.ui @@ -15,10 +15,7 @@ - - - Hierarchy Tree - + From b54c25589ce450d70446772694dd5be6484d004c Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Fri, 21 May 2021 15:05:26 +0200 Subject: [PATCH 08/20] Changes to the tree model --- UserInterface/Dialogues/IfcTreeModel.cpp | 169 +++++++++++++++++++++++ UserInterface/Dialogues/IfcTreeModel.h | 4 +- 2 files changed, 172 insertions(+), 1 deletion(-) diff --git a/UserInterface/Dialogues/IfcTreeModel.cpp b/UserInterface/Dialogues/IfcTreeModel.cpp index e69de29bb..5fa18091b 100644 --- a/UserInterface/Dialogues/IfcTreeModel.cpp +++ b/UserInterface/Dialogues/IfcTreeModel.cpp @@ -0,0 +1,169 @@ +/* + Copyright (c) 2021 Technical University of Munich + Chair of Computational Modeling and Simulation. + + TUM Open Infra Platform is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + TUM Open Infra Platform is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "IfcTreeModel.h" + +#include +#include +#include + + +OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(std::shared_ptr expressModel, QObject *parent) + : QAbstractItemModel(parent) +{ + //rootItem_ = std::make_shared(expressModel->entities.find(1)->second, nullptr); //make ifcProject the root item + //std::string text = "Title"; + rootItem_ = std::make_shared(); + setupModelData(expressModel, rootItem_); +} + +OpenInfraPlatform::UserInterface::IfcTreeModel::~IfcTreeModel() +{ + +} + +QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + std::shared_ptr parentItemShared; + + if (!parent.isValid()) + parentItemShared = rootItem_; + //return this->createIndex(row, column, nullptr); + else + { + IfcTreeItem *parentItem = static_cast(parent.internalPointer()); + std::shared_ptr parentTemp(parentItem); + parentItemShared = parentTemp; + } + + std::shared_ptr childItemShared = parentItemShared->child(row); + IfcTreeItem *childItem = childItemShared.get(); + if (childItem) + return createIndex(row, column, childItem); + return QModelIndex(); +} + +QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::headerData(int section, Qt::Orientation orientation, + int role) const +{ + return rootItem_->data(section); +} + +QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::parent(const QModelIndex &index) const +{ + if (!index.isValid()) + return QModelIndex(); + + IfcTreeItem *childItem = static_cast(index.internalPointer()); + std::shared_ptr childItemShared(childItem); + std::shared_ptr parentItemShared = childItem->parentItem(); + IfcTreeItem *parentItem = parentItemShared.get(); + + if (parentItemShared == rootItem_) + return QModelIndex(); + + return createIndex(parentItem->row(), 0, parentItem); +} + +int OpenInfraPlatform::UserInterface::IfcTreeModel::rowCount(const QModelIndex &parent) const +{ + //normal pointer is needed for parent.internalPoiter() and shared_ptr is needed to compare with rootitem_ + std::shared_ptr parentItemShared; + IfcTreeItem *parentItem = parentItemShared.get(); + + if (parent.column() > 0) + return 0; + + if (!parent.isValid()) + { + parentItemShared = rootItem_; + parentItem = parentItemShared.get(); + } + else + parentItem = static_cast(parent.internalPointer()); + + int nrOfRows = parentItem->childCount(); + return nrOfRows; +} + +int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + return rootItem_->columnCount(); +} + +//int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const +//{ +// if (!parent.isValid()) +// return 1; //correct for testing? +// else +// return 3; +//} + +Qt::ItemFlags OpenInfraPlatform::UserInterface::IfcTreeModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::NoItemFlags; + + return QAbstractItemModel::flags(index); +} + +QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + IfcTreeItem *item = static_cast(index.internalPointer()); + + return item->data(index.column()); +} + +void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(std::shared_ptr expressModel, std::shared_ptr parent) +{ + //auto entities = expressModel->entities; + + //for (int i = 0; i < 10; i++) + //{ + // std::shared_ptr item = std::make_shared(entities.find(i)->second, parent); + // parent->appendchild(item); + //} + + for (const auto& entity : expressModel->entities) + { + parent->appendchild(std::make_shared(entity.second, parent)); + } + + //for (int i = 3; i < 4; i++) + //{ + // std::shared_ptr item1 = std::make_shared(entities.find(i)->second, parent); + // parent->appendchild(item1); + // std::shared_ptr item2 = std::make_shared(entities.find(i + 1)->second, parent); + // parent->appendchild(item2); + // std::shared_ptr item3 = std::make_shared(entities.find(i + 2)->second, parent); + // parent->appendchild(item3); + //} + //for (auto entity : entities) + //{ + // IfcTreeItem *item = new IfcTreeItem(entity.second); + // std::shared_ptr itemShared(item); + // rootItem_->appendchild(itemShared); + //} +} \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeModel.h b/UserInterface/Dialogues/IfcTreeModel.h index 8489fa240..a6943e48c 100644 --- a/UserInterface/Dialogues/IfcTreeModel.h +++ b/UserInterface/Dialogues/IfcTreeModel.h @@ -41,10 +41,12 @@ namespace OpenInfraPlatform //override from QAbstractItemModel virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - virtual QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override; + virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; virtual QModelIndex parent(const QModelIndex &index) const override; virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + virtual Qt::ItemFlags flags(const QModelIndex &index) const override; private: void setupModelData(std::shared_ptr expressModel, std::shared_ptr parent); From bc8c7678ce46e019adfc1c26b6844f251a37941f Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Fri, 21 May 2021 15:06:12 +0200 Subject: [PATCH 09/20] Small changes to tree items (not working yet!) --- UserInterface/Dialogues/IfcTreeItem.cpp | 130 ++++++++++++++---------- UserInterface/Dialogues/IfcTreeItem.h | 11 +- 2 files changed, 83 insertions(+), 58 deletions(-) diff --git a/UserInterface/Dialogues/IfcTreeItem.cpp b/UserInterface/Dialogues/IfcTreeItem.cpp index c77527f29..49890f111 100644 --- a/UserInterface/Dialogues/IfcTreeItem.cpp +++ b/UserInterface/Dialogues/IfcTreeItem.cpp @@ -23,13 +23,26 @@ #include "visit_struct\visit_struct.hpp" -OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(std::shared_ptr data, std::shared_ptr parentItem) - :data_(data), parentItem_(parentItem) -{} +OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(const std::shared_ptr& data, const std::shared_ptr& parentItem) +{ + data_ = data; + parentItem_ = parentItem; + //itemData_.push_back(data_->getStepLine()); + itemData_.push_back(data_->classname()); +} + +OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem() +{ + data_ = nullptr; + parentItem_ = nullptr; + std::string text = "Title"; + itemData_.push_back(text); +} OpenInfraPlatform::UserInterface::IfcTreeItem::~IfcTreeItem() { childItems_.clear(); + //qDeleteAll(childItems_); } void OpenInfraPlatform::UserInterface::IfcTreeItem::appendchild(std::shared_ptr child) @@ -47,33 +60,43 @@ std::shared_ptr OpenInfraPlatform int OpenInfraPlatform::UserInterface::IfcTreeItem::childCount() const { - return childItems_.count(); + int nrOfChilds = childItems_.count(); + return nrOfChilds; } int OpenInfraPlatform::UserInterface::IfcTreeItem::columnCount() const { - return 3; + return itemData_.size(); } -QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int row, int column) const +QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const { - //auto attributes = getAttributeDescription(); - - //switch (column) - //{ - //case 0: - // return attributes.names_[row]; - // break; - //case 1: - // return attributes.value_[row]; - // break; - //case 2: - // return attributes.typename_[row]; - // break; - //} - return QVariant(); + if (column < 0 || column >= itemData_.size()) + return QVariant(); + return QString::fromStdString(itemData_.at(column)); } +//QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const +//{ +// //auto attributes = getAttributeDescription()(*data_); +// +// //switch (column) +// //{ +// //case 0: +// // return attributes.names_[row]; +// // break; +// //case 1: +// // return attributes.value_[row]; +// // break; +// //case 2: +// // return attributes.typename_[row]; +// // break; +// //} +// +// //return QVariant(); +// return getIfcClassName(); +//} + int OpenInfraPlatform::UserInterface::IfcTreeItem::row() { if (parentItem_) @@ -85,10 +108,9 @@ int OpenInfraPlatform::UserInterface::IfcTreeItem::row() std::shared_ptr OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() { - if (parentItem_) - return parentItem_; + return parentItem_; - return std::shared_ptr(); + //return std::shared_ptr(); //could be wrong } QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const @@ -97,33 +119,33 @@ QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const return QString::fromStdString(ifcClassName); } -struct OpenInfraPlatform::UserInterface::IfcTreeItem::getAttributeDescription -{ - template typename std::enable_if::value && std::is_base_of::value, void>::type - operator()(T entity) - { - visit_struct::for_each(entity, [&](const char* name, const auto &value) { - names_.push_back(name); - typename_ = typeid(T).name(entity); - value_.push_back(value); - }); - } - - //This is a dummy function which should never be called but is required by the compiler since it could theoretically be called. Throws exception. - template typename std::enable_if::value, void>::type - operator()(T& entity) const - { - std::string message = "Invalid function call. " + std::string(typeid(entity).name()) + " isn't a member of EXPRESSEntity."; - throw buw::Exception(message); - } - - //This is a dummy function which should never be called but is required by the compiler since it could theoretically be called. Throws exception. - void operator()(OpenInfraPlatform::EarlyBinding::EXPRESSEntity& entity) const - { - throw oip::UnhandledException("Invalid function call (IfcTreeItem::getAttributeDescription)"); - } - - std::vector names_; - std::vector typename_; - std::vector value_; -}; \ No newline at end of file +//struct OpenInfraPlatform::UserInterface::IfcTreeItem::getAttributeDescription +//{ +// template typename std::enable_if::value && std::is_base_of::value, void>::type +// operator()(T entity) +// { +// visit_struct::for_each(entity, [&](const char* name, const auto &value) { +// names_.push_back(name); +// typename_ = typeid(T).name(entity); +// value_.push_back(value); +// }); +// } +// +// //This is a dummy function which should never be called but is required by the compiler since it could theoretically be called. Throws exception. +// template typename std::enable_if::value, void>::type +// operator()(T& entity) const +// { +// std::string message = "Invalid function call. " + std::string(typeid(entity).name()) + " isn't a member of EXPRESSEntity."; +// throw oip::UnhandledException(message); +// } +// +// //This is a dummy function which should never be called but is required by the compiler since it could theoretically be called. Throws exception. +// void operator()(OpenInfraPlatform::EarlyBinding::EXPRESSEntity& entity) const +// { +// throw oip::UnhandledException("Invalid function call (IfcTreeItem::getAttributeDescription)"); +// } +// +// std::vector names_; +// std::vector typename_; +// std::vector value_; +//}; \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeItem.h b/UserInterface/Dialogues/IfcTreeItem.h index f3d55678d..105d07368 100644 --- a/UserInterface/Dialogues/IfcTreeItem.h +++ b/UserInterface/Dialogues/IfcTreeItem.h @@ -20,6 +20,7 @@ #include "EXPRESS/EXPRESSReference.h" #include +#include namespace OpenInfraPlatform { @@ -28,7 +29,8 @@ namespace OpenInfraPlatform { class IfcTreeItem : public std::enable_shared_from_this { public: - IfcTreeItem(std::shared_ptr data, std::shared_ptr parentItem = nullptr); + IfcTreeItem(const std::shared_ptr& data, const std::shared_ptr& parentItem); + IfcTreeItem(); ~IfcTreeItem(); void appendchild(std::shared_ptr child); @@ -36,17 +38,18 @@ namespace OpenInfraPlatform { std::shared_ptr child(int row); int childCount() const; int columnCount() const; - QVariant data(int row, int column) const; + QVariant data(int column) const; int row(); std::shared_ptr parentItem(); QString getIfcClassName() const; private: - QList> childItems_; + QVector> childItems_; std::shared_ptr data_; + std::vector itemData_; std::shared_ptr parentItem_; - struct getAttributeDescription; + //struct getAttributeDescription; }; } } From a1f2e4afd41a8489505f338756d70be079629393 Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Fri, 21 May 2021 18:00:43 +0200 Subject: [PATCH 10/20] Change everything from shared pointers to pointers (not working yet!) --- UserInterface/Dialogues/IfcTreeDialog.cpp | 3 +- UserInterface/Dialogues/IfcTreeItem.cpp | 16 ++++----- UserInterface/Dialogues/IfcTreeItem.h | 16 ++++----- UserInterface/Dialogues/IfcTreeModel.cpp | 42 ++++++++--------------- UserInterface/Dialogues/IfcTreeModel.h | 6 ++-- 5 files changed, 35 insertions(+), 48 deletions(-) diff --git a/UserInterface/Dialogues/IfcTreeDialog.cpp b/UserInterface/Dialogues/IfcTreeDialog.cpp index 69f237910..56fba5c1b 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.cpp +++ b/UserInterface/Dialogues/IfcTreeDialog.cpp @@ -43,7 +43,8 @@ void OpenInfraPlatform::UserInterface::IfcTreeDialog::show() if (std::dynamic_pointer_cast(model)) { auto ifcModel = std::static_pointer_cast(model); - auto expressModel = ifcModel->getExpressModel(); + auto expressModelShared = ifcModel->getExpressModel(); + OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel = expressModelShared.get(); auto treeModel = new IfcTreeModel(expressModel); ui_->ifcTreeView->setModel(treeModel); ((QDialog*)this)->show(); diff --git a/UserInterface/Dialogues/IfcTreeItem.cpp b/UserInterface/Dialogues/IfcTreeItem.cpp index 49890f111..daea1cc8f 100644 --- a/UserInterface/Dialogues/IfcTreeItem.cpp +++ b/UserInterface/Dialogues/IfcTreeItem.cpp @@ -23,7 +23,7 @@ #include "visit_struct\visit_struct.hpp" -OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(const std::shared_ptr& data, const std::shared_ptr& parentItem) +OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem) { data_ = data; parentItem_ = parentItem; @@ -41,16 +41,16 @@ OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem() OpenInfraPlatform::UserInterface::IfcTreeItem::~IfcTreeItem() { - childItems_.clear(); - //qDeleteAll(childItems_); + //childItems_.clear(); + qDeleteAll(childItems_); } -void OpenInfraPlatform::UserInterface::IfcTreeItem::appendchild(std::shared_ptr child) +void OpenInfraPlatform::UserInterface::IfcTreeItem::appendchild(IfcTreeItem *child) { childItems_.append(child); } -std::shared_ptr OpenInfraPlatform::UserInterface::IfcTreeItem::child(int row) +OpenInfraPlatform::UserInterface::IfcTreeItem* OpenInfraPlatform::UserInterface::IfcTreeItem::child(int row) { if (row < 0 || row >= childItems_.size()) throw oip::UnhandledException("Child index out of range (IfcTreeItem::child)"); @@ -101,16 +101,14 @@ int OpenInfraPlatform::UserInterface::IfcTreeItem::row() { if (parentItem_) { - return parentItem_->childItems_.indexOf(shared_from_this()); + return parentItem_->childItems_.indexOf(const_cast(this)); } return 0; } -std::shared_ptr OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() +OpenInfraPlatform::UserInterface::IfcTreeItem* OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() { return parentItem_; - - //return std::shared_ptr(); //could be wrong } QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const diff --git a/UserInterface/Dialogues/IfcTreeItem.h b/UserInterface/Dialogues/IfcTreeItem.h index 105d07368..f416fdbd7 100644 --- a/UserInterface/Dialogues/IfcTreeItem.h +++ b/UserInterface/Dialogues/IfcTreeItem.h @@ -26,28 +26,28 @@ namespace OpenInfraPlatform { namespace UserInterface { - class IfcTreeItem : public std::enable_shared_from_this + class IfcTreeItem { public: - IfcTreeItem(const std::shared_ptr& data, const std::shared_ptr& parentItem); + IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem); IfcTreeItem(); ~IfcTreeItem(); - void appendchild(std::shared_ptr child); + void appendchild(IfcTreeItem *child); - std::shared_ptr child(int row); + IfcTreeItem *child(int row); int childCount() const; int columnCount() const; QVariant data(int column) const; int row(); - std::shared_ptr parentItem(); + IfcTreeItem *parentItem(); QString getIfcClassName() const; private: - QVector> childItems_; - std::shared_ptr data_; + QVector childItems_; + OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data_; std::vector itemData_; - std::shared_ptr parentItem_; + IfcTreeItem *parentItem_; //struct getAttributeDescription; }; diff --git a/UserInterface/Dialogues/IfcTreeModel.cpp b/UserInterface/Dialogues/IfcTreeModel.cpp index 5fa18091b..5cad21bb1 100644 --- a/UserInterface/Dialogues/IfcTreeModel.cpp +++ b/UserInterface/Dialogues/IfcTreeModel.cpp @@ -22,18 +22,18 @@ #include -OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(std::shared_ptr expressModel, QObject *parent) +OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent) : QAbstractItemModel(parent) { //rootItem_ = std::make_shared(expressModel->entities.find(1)->second, nullptr); //make ifcProject the root item //std::string text = "Title"; - rootItem_ = std::make_shared(); + rootItem_ = new IfcTreeItem(); setupModelData(expressModel, rootItem_); } OpenInfraPlatform::UserInterface::IfcTreeModel::~IfcTreeModel() { - + delete rootItem_; } QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::index(int row, int column, const QModelIndex &parent) const @@ -41,20 +41,15 @@ QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::index(int row, int c if (!hasIndex(row, column, parent)) return QModelIndex(); - std::shared_ptr parentItemShared; + IfcTreeItem* parentItem; if (!parent.isValid()) - parentItemShared = rootItem_; + parentItem = rootItem_; //return this->createIndex(row, column, nullptr); else - { - IfcTreeItem *parentItem = static_cast(parent.internalPointer()); - std::shared_ptr parentTemp(parentItem); - parentItemShared = parentTemp; - } + parentItem = static_cast(parent.internalPointer()); - std::shared_ptr childItemShared = parentItemShared->child(row); - IfcTreeItem *childItem = childItemShared.get(); + IfcTreeItem *childItem = parentItem->child(row); if (childItem) return createIndex(row, column, childItem); return QModelIndex(); @@ -71,12 +66,10 @@ QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::parent(const QModelI if (!index.isValid()) return QModelIndex(); - IfcTreeItem *childItem = static_cast(index.internalPointer()); - std::shared_ptr childItemShared(childItem); - std::shared_ptr parentItemShared = childItem->parentItem(); - IfcTreeItem *parentItem = parentItemShared.get(); + IfcTreeItem *child = static_cast(index.internalPointer()); + IfcTreeItem *parentItem = child->parentItem(); - if (parentItemShared == rootItem_) + if (parentItem == rootItem_) return QModelIndex(); return createIndex(parentItem->row(), 0, parentItem); @@ -84,18 +77,13 @@ QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::parent(const QModelI int OpenInfraPlatform::UserInterface::IfcTreeModel::rowCount(const QModelIndex &parent) const { - //normal pointer is needed for parent.internalPoiter() and shared_ptr is needed to compare with rootitem_ - std::shared_ptr parentItemShared; - IfcTreeItem *parentItem = parentItemShared.get(); + IfcTreeItem *parentItem; if (parent.column() > 0) return 0; if (!parent.isValid()) - { - parentItemShared = rootItem_; - parentItem = parentItemShared.get(); - } + parentItem = rootItem_; else parentItem = static_cast(parent.internalPointer()); @@ -136,7 +124,7 @@ QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::data(const QModelIndex return item->data(index.column()); } -void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(std::shared_ptr expressModel, std::shared_ptr parent) +void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent) { //auto entities = expressModel->entities; @@ -146,9 +134,9 @@ void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(std::shared_ // parent->appendchild(item); //} - for (const auto& entity : expressModel->entities) + for (auto entity : expressModel->entities) { - parent->appendchild(std::make_shared(entity.second, parent)); + parent->appendchild(new IfcTreeItem(entity.second.get(), parent)); } //for (int i = 3; i < 4; i++) diff --git a/UserInterface/Dialogues/IfcTreeModel.h b/UserInterface/Dialogues/IfcTreeModel.h index a6943e48c..929f122c2 100644 --- a/UserInterface/Dialogues/IfcTreeModel.h +++ b/UserInterface/Dialogues/IfcTreeModel.h @@ -36,7 +36,7 @@ namespace OpenInfraPlatform Q_OBJECT; public: - IfcTreeModel(std::shared_ptr expressModel, QObject *parent = nullptr); + IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent = nullptr); ~IfcTreeModel(); //override from QAbstractItemModel @@ -49,9 +49,9 @@ namespace OpenInfraPlatform virtual Qt::ItemFlags flags(const QModelIndex &index) const override; private: - void setupModelData(std::shared_ptr expressModel, std::shared_ptr parent); + void setupModelData(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent); - std::shared_ptr rootItem_; + IfcTreeItem *rootItem_; }; } From 6226824bd3fff7a056581b884dce2957ede98ed4 Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Fri, 28 May 2021 12:34:59 +0200 Subject: [PATCH 11/20] minor changes (still not working) --- UserInterface/Dialogues/IfcTreeDialog.cpp | 12 +++++++++--- UserInterface/Dialogues/IfcTreeDialog.h | 2 +- UserInterface/Dialogues/IfcTreeItem.cpp | 8 +++++--- UserInterface/Dialogues/IfcTreeItem.h | 6 +++--- UserInterface/Dialogues/IfcTreeModel.cpp | 11 ++++++++--- UserInterface/Dialogues/IfcTreeModel.h | 16 ++++++++-------- UserInterface/MainWindow.cpp | 2 +- 7 files changed, 35 insertions(+), 22 deletions(-) diff --git a/UserInterface/Dialogues/IfcTreeDialog.cpp b/UserInterface/Dialogues/IfcTreeDialog.cpp index 56fba5c1b..4174562fc 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.cpp +++ b/UserInterface/Dialogues/IfcTreeDialog.cpp @@ -20,11 +20,11 @@ #include "ui_IfcTreeDialog.h" #include "DataManagement/General/Data.h" #include "Exception\UnhandledException.h" +#include -OpenInfraPlatform::UserInterface::IfcTreeDialog::IfcTreeDialog(OpenInfraPlatform::UserInterface::View* view, QWidget *parent /*= nullptr*/) : +OpenInfraPlatform::UserInterface::IfcTreeDialog::IfcTreeDialog(QWidget *parent /*= nullptr*/) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint), - ui_(new Ui::IfcTreeDialog), - view_(view) + ui_(new Ui::IfcTreeDialog) { ui_->setupUi(this); //ui_->ifcTreeWidget->setAnimated(true); @@ -47,6 +47,7 @@ void OpenInfraPlatform::UserInterface::IfcTreeDialog::show() OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel = expressModelShared.get(); auto treeModel = new IfcTreeModel(expressModel); ui_->ifcTreeView->setModel(treeModel); + //ui_->ifcTreeView->show(); ((QDialog*)this)->show(); } else @@ -54,6 +55,11 @@ void OpenInfraPlatform::UserInterface::IfcTreeDialog::show() //only for now till the selected model is properly handled throw oip::UnhandledException("Last model is not a IFC model"); } + //QFileSystemModel *model = new QFileSystemModel; + //model->setRootPath(QDir::currentPath()); + //ui_->ifcTreeView->setModel(model); + //ui_->ifcTreeView->setRootIndex(model->index(QDir::currentPath())); + //((QDialog*)this)->show(); } diff --git a/UserInterface/Dialogues/IfcTreeDialog.h b/UserInterface/Dialogues/IfcTreeDialog.h index 59c062956..d69f52e32 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.h +++ b/UserInterface/Dialogues/IfcTreeDialog.h @@ -32,7 +32,7 @@ namespace OpenInfraPlatform Q_OBJECT; public: - IfcTreeDialog(OpenInfraPlatform::UserInterface::View* view, QWidget *parent = nullptr); + IfcTreeDialog(QWidget *parent = nullptr); //! Virtual destructor. virtual ~IfcTreeDialog(); diff --git a/UserInterface/Dialogues/IfcTreeItem.cpp b/UserInterface/Dialogues/IfcTreeItem.cpp index daea1cc8f..8c66b481f 100644 --- a/UserInterface/Dialogues/IfcTreeItem.cpp +++ b/UserInterface/Dialogues/IfcTreeItem.cpp @@ -66,14 +66,16 @@ int OpenInfraPlatform::UserInterface::IfcTreeItem::childCount() const int OpenInfraPlatform::UserInterface::IfcTreeItem::columnCount() const { - return itemData_.size(); + int nrOfColumns = itemData_.size(); //size right here? + return nrOfColumns; } QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const { if (column < 0 || column >= itemData_.size()) return QVariant(); - return QString::fromStdString(itemData_.at(column)); + //QString text = QString::fromStdString(itemData_.at(column)); + return QString("text"); } //QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const @@ -97,7 +99,7 @@ QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const // return getIfcClassName(); //} -int OpenInfraPlatform::UserInterface::IfcTreeItem::row() +int OpenInfraPlatform::UserInterface::IfcTreeItem::row() const { if (parentItem_) { diff --git a/UserInterface/Dialogues/IfcTreeItem.h b/UserInterface/Dialogues/IfcTreeItem.h index f416fdbd7..0e45c0191 100644 --- a/UserInterface/Dialogues/IfcTreeItem.h +++ b/UserInterface/Dialogues/IfcTreeItem.h @@ -29,8 +29,8 @@ namespace OpenInfraPlatform { class IfcTreeItem { public: - IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem); - IfcTreeItem(); + explicit IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem); + explicit IfcTreeItem(); ~IfcTreeItem(); void appendchild(IfcTreeItem *child); @@ -39,7 +39,7 @@ namespace OpenInfraPlatform { int childCount() const; int columnCount() const; QVariant data(int column) const; - int row(); + int row() const; IfcTreeItem *parentItem(); QString getIfcClassName() const; diff --git a/UserInterface/Dialogues/IfcTreeModel.cpp b/UserInterface/Dialogues/IfcTreeModel.cpp index 5cad21bb1..40e0b49dc 100644 --- a/UserInterface/Dialogues/IfcTreeModel.cpp +++ b/UserInterface/Dialogues/IfcTreeModel.cpp @@ -51,7 +51,11 @@ QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::index(int row, int c IfcTreeItem *childItem = parentItem->child(row); if (childItem) - return createIndex(row, column, childItem); + { + auto n = createIndex(row, column, childItem); + return n; + } + //return createIndex(row, column, childItem); return QModelIndex(); } @@ -70,7 +74,7 @@ QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::parent(const QModelI IfcTreeItem *parentItem = child->parentItem(); if (parentItem == rootItem_) - return QModelIndex(); + return QModelIndex(); return createIndex(parentItem->row(), 0, parentItem); } @@ -95,7 +99,8 @@ int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelInde { if (parent.isValid()) return static_cast(parent.internalPointer())->columnCount(); - return rootItem_->columnCount(); + int nrOfColumns = rootItem_->columnCount(); + return nrOfColumns; } //int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const diff --git a/UserInterface/Dialogues/IfcTreeModel.h b/UserInterface/Dialogues/IfcTreeModel.h index 929f122c2..402f8298a 100644 --- a/UserInterface/Dialogues/IfcTreeModel.h +++ b/UserInterface/Dialogues/IfcTreeModel.h @@ -36,17 +36,17 @@ namespace OpenInfraPlatform Q_OBJECT; public: - IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent = nullptr); + explicit IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent = nullptr); ~IfcTreeModel(); //override from QAbstractItemModel - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; - virtual QModelIndex parent(const QModelIndex &index) const override; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - virtual Qt::ItemFlags flags(const QModelIndex &index) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; + QModelIndex parent(const QModelIndex &index) const override; + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + Qt::ItemFlags flags(const QModelIndex &index) const override; private: void setupModelData(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent); diff --git a/UserInterface/MainWindow.cpp b/UserInterface/MainWindow.cpp index 6ca0ee9fe..44cc54a3b 100644 --- a/UserInterface/MainWindow.cpp +++ b/UserInterface/MainWindow.cpp @@ -1807,7 +1807,7 @@ void OpenInfraPlatform::UserInterface::MainWindow::on_actionShow_License_and_Cop void OpenInfraPlatform::UserInterface::MainWindow::on_actionShow_Ifc_Tree_triggered() { if (ifcTreeDialog_ == nullptr) { - ifcTreeDialog_ = new IfcTreeDialog(view_, this); + ifcTreeDialog_ = new IfcTreeDialog(this); } ifcTreeDialog_->show(); From 79b3c90dd476e524918dd2c53abd856a4b89258b Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Thu, 1 Jul 2021 10:09:33 +0200 Subject: [PATCH 12/20] Just some testing --- UserInterface/Dialogues/IfcTreeDialog.cpp | 67 +++-- UserInterface/Dialogues/IfcTreeDialog.h | 2 +- UserInterface/Dialogues/IfcTreeItem.cpp | 199 +++++++++----- UserInterface/Dialogues/IfcTreeItem.h | 38 ++- UserInterface/Dialogues/IfcTreeModel.cpp | 315 ++++++++++++++++------ UserInterface/Dialogues/IfcTreeModel.h | 35 ++- testdata/default.txt | 40 +++ 7 files changed, 501 insertions(+), 195 deletions(-) create mode 100644 testdata/default.txt diff --git a/UserInterface/Dialogues/IfcTreeDialog.cpp b/UserInterface/Dialogues/IfcTreeDialog.cpp index 4174562fc..842a04e64 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.cpp +++ b/UserInterface/Dialogues/IfcTreeDialog.cpp @@ -21,14 +21,18 @@ #include "DataManagement/General/Data.h" #include "Exception\UnhandledException.h" #include +#include + +#include +#include +#include +#include OpenInfraPlatform::UserInterface::IfcTreeDialog::IfcTreeDialog(QWidget *parent /*= nullptr*/) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint), ui_(new Ui::IfcTreeDialog) { ui_->setupUi(this); - //ui_->ifcTreeWidget->setAnimated(true); - //ui_->ifcTreeView->setModel(new IfcTreeModel()); } OpenInfraPlatform::UserInterface::IfcTreeDialog::~IfcTreeDialog() @@ -38,28 +42,53 @@ OpenInfraPlatform::UserInterface::IfcTreeDialog::~IfcTreeDialog() void OpenInfraPlatform::UserInterface::IfcTreeDialog::show() { - //for first testing just get last model, later this will be changed to selecting the model need - auto model = Core::DataManagement::DocumentManager::getInstance().getData().getLastModel(); - if (std::dynamic_pointer_cast(model)) - { - auto ifcModel = std::static_pointer_cast(model); - auto expressModelShared = ifcModel->getExpressModel(); - OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel = expressModelShared.get(); - auto treeModel = new IfcTreeModel(expressModel); - ui_->ifcTreeView->setModel(treeModel); - //ui_->ifcTreeView->show(); - ((QDialog*)this)->show(); - } - else - { - //only for now till the selected model is properly handled - throw oip::UnhandledException("Last model is not a IFC model"); - } + ////for first testing just get last model, later this will be changed to selecting the model need + //auto model = Core::DataManagement::DocumentManager::getInstance().getData().getLastModel(); + //if (std::dynamic_pointer_cast(model)) + //{ + // auto ifcModel = std::static_pointer_cast(model); + // auto expressModelShared = ifcModel->getExpressModel(); + // OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel = expressModelShared.get(); + // auto treeModel = new IfcTreeModel(expressModel); + // ui_->ifcTreeView->setModel(treeModel); + // ((QDialog*)this)->show(); + //} + //else + //{ + // //only for now till the selected model is properly handled + // throw oip::UnhandledException("Last model is not a IFC model"); + //} + + + //testing simple tree example + //QFile file(":/default.txt"); + //std::string cwd = _getcwd(NULL, 0); + //QFile file("..//..//Open-Infra-Platform//testdata//default.txt"); + //file.open(QIODevice::ReadOnly); + //IfcTreeModel model(file.readAll()); + //file.close(); + + IfcTreeModel model(QString("May the stars align")); + ui_->ifcTreeView->setModel(&model); + ui_->ifcTreeView->setWindowTitle(QObject::tr("Title")); + ((QDialog*)this)->show(); + + ////testing with QFileSystemModel //QFileSystemModel *model = new QFileSystemModel; //model->setRootPath(QDir::currentPath()); //ui_->ifcTreeView->setModel(model); //ui_->ifcTreeView->setRootIndex(model->index(QDir::currentPath())); //((QDialog*)this)->show(); + + ////testing with QTreeWidget (IfcTreeDialog.ui needs to be changed) + //ui_->ifcTreeView->setColumnCount(1); + //QList items; + //for (int i = 0; i < 10; i++) + //{ + // items.append(new QTreeWidgetItem(static_cast(nullptr), QStringList(QString("item: %1").arg(i)))); + //} + //ui_->ifcTreeView->insertTopLevelItems(0, items); + //((QDialog*)this)->show(); } diff --git a/UserInterface/Dialogues/IfcTreeDialog.h b/UserInterface/Dialogues/IfcTreeDialog.h index d69f52e32..8240e4408 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.h +++ b/UserInterface/Dialogues/IfcTreeDialog.h @@ -44,7 +44,7 @@ namespace OpenInfraPlatform private: Ui::IfcTreeDialog* ui_; - OpenInfraPlatform::UserInterface::View* view_; + //OpenInfraPlatform::UserInterface::View* view_; }; // end class IfcTree } // end namespace UserInterface } // end namespace OpenInfraPlatform diff --git a/UserInterface/Dialogues/IfcTreeItem.cpp b/UserInterface/Dialogues/IfcTreeItem.cpp index 8c66b481f..e6bd76d6e 100644 --- a/UserInterface/Dialogues/IfcTreeItem.cpp +++ b/UserInterface/Dialogues/IfcTreeItem.cpp @@ -23,60 +23,60 @@ #include "visit_struct\visit_struct.hpp" -OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem) -{ - data_ = data; - parentItem_ = parentItem; - //itemData_.push_back(data_->getStepLine()); - itemData_.push_back(data_->classname()); -} - -OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem() -{ - data_ = nullptr; - parentItem_ = nullptr; - std::string text = "Title"; - itemData_.push_back(text); -} - -OpenInfraPlatform::UserInterface::IfcTreeItem::~IfcTreeItem() -{ - //childItems_.clear(); - qDeleteAll(childItems_); -} - -void OpenInfraPlatform::UserInterface::IfcTreeItem::appendchild(IfcTreeItem *child) -{ - childItems_.append(child); -} - -OpenInfraPlatform::UserInterface::IfcTreeItem* OpenInfraPlatform::UserInterface::IfcTreeItem::child(int row) -{ - if (row < 0 || row >= childItems_.size()) - throw oip::UnhandledException("Child index out of range (IfcTreeItem::child)"); - - return childItems_.at(row); -} - -int OpenInfraPlatform::UserInterface::IfcTreeItem::childCount() const -{ - int nrOfChilds = childItems_.count(); - return nrOfChilds; -} - -int OpenInfraPlatform::UserInterface::IfcTreeItem::columnCount() const -{ - int nrOfColumns = itemData_.size(); //size right here? - return nrOfColumns; -} - -QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const -{ - if (column < 0 || column >= itemData_.size()) - return QVariant(); - //QString text = QString::fromStdString(itemData_.at(column)); - return QString("text"); -} +//OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem) +//{ +// data_ = data; +// parentItem_ = parentItem; +// //itemData_.push_back(data_->getStepLine()); +// itemData_.push_back(data_->classname()); +//} +// +//OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem() +//{ +// data_ = nullptr; +// parentItem_ = nullptr; +// std::string text = "Title"; +// itemData_.push_back(text); +//} +// +//OpenInfraPlatform::UserInterface::IfcTreeItem::~IfcTreeItem() +//{ +// //childItems_.clear(); +// qDeleteAll(childItems_); +//} +// +//void OpenInfraPlatform::UserInterface::IfcTreeItem::appendchild(IfcTreeItem *child) +//{ +// childItems_.append(child); +//} +// +//OpenInfraPlatform::UserInterface::IfcTreeItem* OpenInfraPlatform::UserInterface::IfcTreeItem::child(int row) +//{ +// if (row < 0 || row >= childItems_.size()) +// throw oip::UnhandledException("Child index out of range (IfcTreeItem::child)"); +// +// return childItems_.at(row); +//} +// +//int OpenInfraPlatform::UserInterface::IfcTreeItem::childCount() const +//{ +// int nrOfChilds = childItems_.count(); +// return nrOfChilds; +//} +// +//int OpenInfraPlatform::UserInterface::IfcTreeItem::columnCount() const +//{ +// int nrOfColumns = itemData_.size(); //size right here? +// return nrOfColumns; +//} +// +//QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const +//{ +// if (column < 0 || column >= itemData_.size()) +// return QVariant(); +// //QString text = QString::fromStdString(itemData_.at(column)); +// return QString("text"); +//} //QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const //{ @@ -99,25 +99,25 @@ QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const // return getIfcClassName(); //} -int OpenInfraPlatform::UserInterface::IfcTreeItem::row() const -{ - if (parentItem_) - { - return parentItem_->childItems_.indexOf(const_cast(this)); - } - return 0; -} - -OpenInfraPlatform::UserInterface::IfcTreeItem* OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() -{ - return parentItem_; -} - -QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const -{ - std::string ifcClassName = data_->classname(); - return QString::fromStdString(ifcClassName); -} +//int OpenInfraPlatform::UserInterface::IfcTreeItem::row() const +//{ +// if (parentItem_) +// { +// return parentItem_->childItems_.indexOf(const_cast(this)); +// } +// return 0; +//} +// +//OpenInfraPlatform::UserInterface::IfcTreeItem* OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() +//{ +// return parentItem_; +//} +// +//QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const +//{ +// std::string ifcClassName = data_->classname(); +// return QString::fromStdString(ifcClassName); +//} //struct OpenInfraPlatform::UserInterface::IfcTreeItem::getAttributeDescription //{ @@ -148,4 +148,55 @@ QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const // std::vector names_; // std::vector typename_; // std::vector value_; -//}; \ No newline at end of file +//}; + +OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(const QVector &data, IfcTreeItem *parent) + : m_itemData(data), m_parentItem(parent) +{} + +OpenInfraPlatform::UserInterface::IfcTreeItem::~IfcTreeItem() +{ + qDeleteAll(m_childItems); +} + +void OpenInfraPlatform::UserInterface::IfcTreeItem::appendChild(IfcTreeItem *item) +{ + m_childItems.append(item); +} + +OpenInfraPlatform::UserInterface::IfcTreeItem *OpenInfraPlatform::UserInterface::IfcTreeItem::child(int row) +{ + if (row < 0 || row >= m_childItems.size()) + return nullptr; + return m_childItems.at(row); +} + +int OpenInfraPlatform::UserInterface::IfcTreeItem::childCount() const +{ + return m_childItems.count(); +} + +int OpenInfraPlatform::UserInterface::IfcTreeItem::columnCount() const +{ + return m_itemData.count(); +} + +QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const +{ + if (column < 0 || column >= m_itemData.size()) + return QVariant(); + return m_itemData.at(column); +} + +OpenInfraPlatform::UserInterface::IfcTreeItem *OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() +{ + return m_parentItem; +} + +int OpenInfraPlatform::UserInterface::IfcTreeItem::row() const +{ + if (m_parentItem) + return m_parentItem->m_childItems.indexOf(const_cast(this)); + + return 0; +} \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeItem.h b/UserInterface/Dialogues/IfcTreeItem.h index 0e45c0191..8bfc47f6a 100644 --- a/UserInterface/Dialogues/IfcTreeItem.h +++ b/UserInterface/Dialogues/IfcTreeItem.h @@ -28,12 +28,34 @@ namespace OpenInfraPlatform { class IfcTreeItem { + //public: + // explicit IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem); + // explicit IfcTreeItem(); + // ~IfcTreeItem(); + + // void appendchild(IfcTreeItem *child); + + // IfcTreeItem *child(int row); + // int childCount() const; + // int columnCount() const; + // QVariant data(int column) const; + // int row() const; + // IfcTreeItem *parentItem(); + // QString getIfcClassName() const; + + //private: + // QVector childItems_; + // OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data_; + // std::vector itemData_; + // IfcTreeItem *parentItem_; + + // //struct getAttributeDescription; + public: - explicit IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem); - explicit IfcTreeItem(); + explicit IfcTreeItem(const QVector &data, IfcTreeItem *parentItem = nullptr); ~IfcTreeItem(); - void appendchild(IfcTreeItem *child); + void appendChild(IfcTreeItem *child); IfcTreeItem *child(int row); int childCount() const; @@ -41,15 +63,11 @@ namespace OpenInfraPlatform { QVariant data(int column) const; int row() const; IfcTreeItem *parentItem(); - QString getIfcClassName() const; private: - QVector childItems_; - OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data_; - std::vector itemData_; - IfcTreeItem *parentItem_; - - //struct getAttributeDescription; + QVector m_childItems; + QVector m_itemData; + IfcTreeItem *m_parentItem; }; } } diff --git a/UserInterface/Dialogues/IfcTreeModel.cpp b/UserInterface/Dialogues/IfcTreeModel.cpp index 40e0b49dc..14559adc7 100644 --- a/UserInterface/Dialogues/IfcTreeModel.cpp +++ b/UserInterface/Dialogues/IfcTreeModel.cpp @@ -21,19 +21,196 @@ #include #include +#include +#include -OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent) + +//OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent) +// : QAbstractItemModel(parent) +//{ +// //rootItem_ = std::make_shared(expressModel->entities.find(1)->second, nullptr); //make ifcProject the root item +// //std::string text = "Title"; +// rootItem_ = new IfcTreeItem(); +// setupModelData(expressModel, rootItem_); +//} +// +//OpenInfraPlatform::UserInterface::IfcTreeModel::~IfcTreeModel() +//{ +// delete rootItem_; +//} +// +//QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::index(int row, int column, const QModelIndex &parent) const +//{ +// if (!hasIndex(row, column, parent)) +// return QModelIndex(); +// +// IfcTreeItem* parentItem; +// +// if (!parent.isValid()) +// parentItem = rootItem_; +// //return this->createIndex(row, column, nullptr); +// else +// parentItem = static_cast(parent.internalPointer()); +// +// IfcTreeItem *childItem = parentItem->child(row); +// if (childItem) +// { +// auto n = createIndex(row, column, childItem); +// return n; +// } +// //return createIndex(row, column, childItem); +// return QModelIndex(); +//} +// +//QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::headerData(int section, Qt::Orientation orientation, +// int role) const +//{ +// return rootItem_->data(section); +//} +// +//QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::parent(const QModelIndex &index) const +//{ +// if (!index.isValid()) +// return QModelIndex(); +// +// IfcTreeItem *child = static_cast(index.internalPointer()); +// IfcTreeItem *parentItem = child->parentItem(); +// +// if (parentItem == rootItem_) +// return QModelIndex(); +// +// return createIndex(parentItem->row(), 0, parentItem); +//} +// +//int OpenInfraPlatform::UserInterface::IfcTreeModel::rowCount(const QModelIndex &parent) const +//{ +// IfcTreeItem *parentItem; +// +// if (parent.column() > 0) +// return 0; +// +// if (!parent.isValid()) +// parentItem = rootItem_; +// else +// parentItem = static_cast(parent.internalPointer()); +// +// int nrOfRows = parentItem->childCount(); +// return nrOfRows; +//} +// +//int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const +//{ +// if (parent.isValid()) +// return static_cast(parent.internalPointer())->columnCount(); +// int nrOfColumns = rootItem_->columnCount(); +// return nrOfColumns; +//} + +//int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const +//{ +// if (!parent.isValid()) +// return 1; //correct for testing? +// else +// return 3; +//} + +//Qt::ItemFlags OpenInfraPlatform::UserInterface::IfcTreeModel::flags(const QModelIndex &index) const +//{ +// if (!index.isValid()) +// return Qt::NoItemFlags; +// +// return QAbstractItemModel::flags(index); +//} +// +//QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::data(const QModelIndex &index, int role) const +//{ +// if (!index.isValid()) +// return QVariant(); +// +// IfcTreeItem *item = static_cast(index.internalPointer()); +// +// return item->data(index.column()); +//} +// +//void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent) +//{ +// //auto entities = expressModel->entities; +// +// //for (int i = 0; i < 10; i++) +// //{ +// // std::shared_ptr item = std::make_shared(entities.find(i)->second, parent); +// // parent->appendchild(item); +// //} +// +// for (auto entity : expressModel->entities) +// { +// parent->appendchild(new IfcTreeItem(entity.second.get(), parent)); +// } +// +// //for (int i = 3; i < 4; i++) +// //{ +// // std::shared_ptr item1 = std::make_shared(entities.find(i)->second, parent); +// // parent->appendchild(item1); +// // std::shared_ptr item2 = std::make_shared(entities.find(i + 1)->second, parent); +// // parent->appendchild(item2); +// // std::shared_ptr item3 = std::make_shared(entities.find(i + 2)->second, parent); +// // parent->appendchild(item3); +// //} +// //for (auto entity : entities) +// //{ +// // IfcTreeItem *item = new IfcTreeItem(entity.second); +// // std::shared_ptr itemShared(item); +// // rootItem_->appendchild(itemShared); +// //} +//} + +OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(const QString &data, QObject *parent) : QAbstractItemModel(parent) { - //rootItem_ = std::make_shared(expressModel->entities.find(1)->second, nullptr); //make ifcProject the root item - //std::string text = "Title"; - rootItem_ = new IfcTreeItem(); - setupModelData(expressModel, rootItem_); + rootItem = new IfcTreeItem({ tr("Title"), tr("Summary") }); + setupModelData(data.split('\n'), rootItem); } OpenInfraPlatform::UserInterface::IfcTreeModel::~IfcTreeModel() { - delete rootItem_; + delete rootItem; +} + +int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + return rootItem->columnCount(); +} + +QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role != Qt::DisplayRole) + return QVariant(); + + IfcTreeItem *item = static_cast(index.internalPointer()); + + return item->data(index.column()); +} + +Qt::ItemFlags OpenInfraPlatform::UserInterface::IfcTreeModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::NoItemFlags; + + return QAbstractItemModel::flags(index); +} + +QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::headerData(int section, Qt::Orientation orientation, + int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return rootItem->data(section); + + return QVariant(); } QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::index(int row, int column, const QModelIndex &parent) const @@ -41,40 +218,29 @@ QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::index(int row, int c if (!hasIndex(row, column, parent)) return QModelIndex(); - IfcTreeItem* parentItem; + IfcTreeItem *parentItem; if (!parent.isValid()) - parentItem = rootItem_; - //return this->createIndex(row, column, nullptr); + parentItem = rootItem; else parentItem = static_cast(parent.internalPointer()); IfcTreeItem *childItem = parentItem->child(row); if (childItem) - { - auto n = createIndex(row, column, childItem); - return n; - } - //return createIndex(row, column, childItem); + return createIndex(row, column, childItem); return QModelIndex(); } -QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::headerData(int section, Qt::Orientation orientation, - int role) const -{ - return rootItem_->data(section); -} - QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::parent(const QModelIndex &index) const { if (!index.isValid()) return QModelIndex(); - IfcTreeItem *child = static_cast(index.internalPointer()); - IfcTreeItem *parentItem = child->parentItem(); + IfcTreeItem *childItem = static_cast(index.internalPointer()); + IfcTreeItem *parentItem = childItem->parentItem(); - if (parentItem == rootItem_) - return QModelIndex(); + if (parentItem == rootItem) + return QModelIndex(); return createIndex(parentItem->row(), 0, parentItem); } @@ -82,81 +248,64 @@ QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::parent(const QModelI int OpenInfraPlatform::UserInterface::IfcTreeModel::rowCount(const QModelIndex &parent) const { IfcTreeItem *parentItem; - if (parent.column() > 0) return 0; if (!parent.isValid()) - parentItem = rootItem_; + parentItem = rootItem; else parentItem = static_cast(parent.internalPointer()); - - int nrOfRows = parentItem->childCount(); - return nrOfRows; -} -int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const -{ - if (parent.isValid()) - return static_cast(parent.internalPointer())->columnCount(); - int nrOfColumns = rootItem_->columnCount(); - return nrOfColumns; + return parentItem->childCount(); } -//int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const -//{ -// if (!parent.isValid()) -// return 1; //correct for testing? -// else -// return 3; -//} - -Qt::ItemFlags OpenInfraPlatform::UserInterface::IfcTreeModel::flags(const QModelIndex &index) const +void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(const QStringList &lines, IfcTreeItem *parent) { - if (!index.isValid()) - return Qt::NoItemFlags; + QVector parents; + QVector indentations; + parents << parent; + indentations << 0; - return QAbstractItemModel::flags(index); -} + int number = 0; -QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); + while (number < lines.count()) { + int position = 0; + while (position < lines[number].length()) { + if (lines[number].at(position) != ' ') + break; + position++; + } - IfcTreeItem *item = static_cast(index.internalPointer()); + const QString lineData = lines[number].mid(position).trimmed(); - return item->data(index.column()); -} + if (!lineData.isEmpty()) { + // Read the column data from the rest of the line. + const QStringList columnStrings = + lineData.split(QLatin1Char('\t'), QString::SkipEmptyParts); + QVector columnData; + columnData.reserve(columnStrings.count()); + for (const QString &columnString : columnStrings) + columnData << columnString; -void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent) -{ - //auto entities = expressModel->entities; + if (position > indentations.last()) { + // The last child of the current parent is now the new parent + // unless the current parent has no children. - //for (int i = 0; i < 10; i++) - //{ - // std::shared_ptr item = std::make_shared(entities.find(i)->second, parent); - // parent->appendchild(item); - //} + if (parents.last()->childCount() > 0) { + parents << parents.last()->child(parents.last()->childCount() - 1); + indentations << position; + } + } + else { + while (position < indentations.last() && parents.count() > 0) { + parents.pop_back(); + indentations.pop_back(); + } + } - for (auto entity : expressModel->entities) - { - parent->appendchild(new IfcTreeItem(entity.second.get(), parent)); + // Append a new item to the current parent's list of children. + parents.last()->appendChild(new IfcTreeItem(columnData, parents.last())); + } + ++number; } - - //for (int i = 3; i < 4; i++) - //{ - // std::shared_ptr item1 = std::make_shared(entities.find(i)->second, parent); - // parent->appendchild(item1); - // std::shared_ptr item2 = std::make_shared(entities.find(i + 1)->second, parent); - // parent->appendchild(item2); - // std::shared_ptr item3 = std::make_shared(entities.find(i + 2)->second, parent); - // parent->appendchild(item3); - //} - //for (auto entity : entities) - //{ - // IfcTreeItem *item = new IfcTreeItem(entity.second); - // std::shared_ptr itemShared(item); - // rootItem_->appendchild(itemShared); - //} } \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeModel.h b/UserInterface/Dialogues/IfcTreeModel.h index 402f8298a..0cb49f9cb 100644 --- a/UserInterface/Dialogues/IfcTreeModel.h +++ b/UserInterface/Dialogues/IfcTreeModel.h @@ -35,23 +35,42 @@ namespace OpenInfraPlatform { Q_OBJECT; + //public: + // explicit IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent = nullptr); + // ~IfcTreeModel(); + + ////override from QAbstractItemModel + // QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + // QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; + // QModelIndex parent(const QModelIndex &index) const override; + // int rowCount(const QModelIndex &parent = QModelIndex()) const override; + // int columnCount(const QModelIndex &parent = QModelIndex()) const override; + // QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + // Qt::ItemFlags flags(const QModelIndex &index) const override; + + //private: + // void setupModelData(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent); + + // IfcTreeItem *rootItem_; + public: - explicit IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent = nullptr); + explicit IfcTreeModel(const QString &data, QObject *parent = nullptr); ~IfcTreeModel(); - //override from QAbstractItemModel - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role) const override; + Qt::ItemFlags flags(const QModelIndex &index) const override; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const override; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex &index) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - Qt::ItemFlags flags(const QModelIndex &index) const override; private: - void setupModelData(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent); + void setupModelData(const QStringList &lines, IfcTreeItem *parent); - IfcTreeItem *rootItem_; + IfcTreeItem *rootItem; }; } diff --git a/testdata/default.txt b/testdata/default.txt new file mode 100644 index 000000000..4a97883ef --- /dev/null +++ b/testdata/default.txt @@ -0,0 +1,40 @@ +Getting Started How to familiarize yourself with Qt Designer + Launching Designer Running the Qt Designer application + The User Interface How to interact with Qt Designer + +Designing a Component Creating a GUI for your application + Creating a Dialog How to create a dialog + Composing the Dialog Putting widgets into the dialog example + Creating a Layout Arranging widgets on a form + Signal and Slot Connections Making widget communicate with each other + +Using a Component in Your Application Generating code from forms + The Direct Approach Using a form without any adjustments + The Single Inheritance Approach Subclassing a form's base class + The Multiple Inheritance Approach Subclassing the form itself + Automatic Connections Connecting widgets using a naming scheme + A Dialog Without Auto-Connect How to connect widgets without a naming scheme + A Dialog With Auto-Connect Using automatic connections + +Form Editing Mode How to edit a form in Qt Designer + Managing Forms Loading and saving forms + Editing a Form Basic editing techniques + The Property Editor Changing widget properties + The Object Inspector Examining the hierarchy of objects on a form + Layouts Objects that arrange widgets on a form + Applying and Breaking Layouts Managing widgets in layouts + Horizontal and Vertical Layouts Standard row and column layouts + The Grid Layout Arranging widgets in a matrix + Previewing Forms Checking that the design works + +Using Containers How to group widgets together + General Features Common container features + Frames QFrame + Group Boxes QGroupBox + Stacked Widgets QStackedWidget + Tab Widgets QTabWidget + Toolbox Widgets QToolBox + +Connection Editing Mode Connecting widgets together with signals and slots + Connecting Objects Making connections in Qt Designer + Editing Connections Changing existing connections \ No newline at end of file From 9df4951a2ae4e9a38c20c77d86ae1f82cb510274 Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Thu, 1 Jul 2021 14:49:06 +0200 Subject: [PATCH 13/20] Adapt to the newest version of ifcImporter.h --- Core/src/IfcGeometryConverter/IfcImporter.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/src/IfcGeometryConverter/IfcImporter.h b/Core/src/IfcGeometryConverter/IfcImporter.h index b4f364271..aba99b7d0 100644 --- a/Core/src/IfcGeometryConverter/IfcImporter.h +++ b/Core/src/IfcGeometryConverter/IfcImporter.h @@ -77,7 +77,12 @@ class IfcImporterT georefConverter->init(expressModel); //store a pointer to the express model in the in the ifc model (used for the tree viewer) - ifcModel->setExpressModel(expressModel); + for (auto model : models) + { + model->setExpressModel(expressModel); + } + + // collect all geometries if (!collectGeometryData(expressModel)) From b112e1f82dd22ca3e17ecce18445ff2accfd6f45 Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Thu, 1 Jul 2021 15:45:45 +0200 Subject: [PATCH 14/20] Trying to exactly replicate the Qt 5.12 simple tree model example (not working) --- UserInterface/Dialogues/IfcTreeItem.cpp | 20 ++++++------ UserInterface/Dialogues/IfcTreeItem.h | 8 ++--- UserInterface/Dialogues/IfcTreeModel.cpp | 31 ++++++++++--------- UserInterface/Dialogues/IfcTreeModel.h | 2 +- testdata/default.txt | 39 +----------------------- 5 files changed, 34 insertions(+), 66 deletions(-) diff --git a/UserInterface/Dialogues/IfcTreeItem.cpp b/UserInterface/Dialogues/IfcTreeItem.cpp index e6bd76d6e..76e23c8a2 100644 --- a/UserInterface/Dialogues/IfcTreeItem.cpp +++ b/UserInterface/Dialogues/IfcTreeItem.cpp @@ -150,9 +150,11 @@ // std::vector value_; //}; -OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(const QVector &data, IfcTreeItem *parent) - : m_itemData(data), m_parentItem(parent) -{} +OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(const QList &data, IfcTreeItem *parent) +{ + m_parentItem = parent; + m_itemData = data; +} OpenInfraPlatform::UserInterface::IfcTreeItem::~IfcTreeItem() { @@ -166,9 +168,9 @@ void OpenInfraPlatform::UserInterface::IfcTreeItem::appendChild(IfcTreeItem *ite OpenInfraPlatform::UserInterface::IfcTreeItem *OpenInfraPlatform::UserInterface::IfcTreeItem::child(int row) { - if (row < 0 || row >= m_childItems.size()) - return nullptr; - return m_childItems.at(row); + //if (row < 0 || row >= m_childItems.size()) + // return nullptr; + return m_childItems.value(row); //QList provides default values in case row is out of range } int OpenInfraPlatform::UserInterface::IfcTreeItem::childCount() const @@ -183,9 +185,9 @@ int OpenInfraPlatform::UserInterface::IfcTreeItem::columnCount() const QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const { - if (column < 0 || column >= m_itemData.size()) - return QVariant(); - return m_itemData.at(column); + //if (column < 0 || column >= m_itemData.size()) + // return QVariant(); + return m_itemData.value(column); } OpenInfraPlatform::UserInterface::IfcTreeItem *OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() diff --git a/UserInterface/Dialogues/IfcTreeItem.h b/UserInterface/Dialogues/IfcTreeItem.h index 8bfc47f6a..7672b9258 100644 --- a/UserInterface/Dialogues/IfcTreeItem.h +++ b/UserInterface/Dialogues/IfcTreeItem.h @@ -20,7 +20,7 @@ #include "EXPRESS/EXPRESSReference.h" #include -#include +#include namespace OpenInfraPlatform { @@ -52,7 +52,7 @@ namespace OpenInfraPlatform { // //struct getAttributeDescription; public: - explicit IfcTreeItem(const QVector &data, IfcTreeItem *parentItem = nullptr); + explicit IfcTreeItem(const QList &data, IfcTreeItem *parentItem = 0); ~IfcTreeItem(); void appendChild(IfcTreeItem *child); @@ -65,8 +65,8 @@ namespace OpenInfraPlatform { IfcTreeItem *parentItem(); private: - QVector m_childItems; - QVector m_itemData; + QList m_childItems; + QList m_itemData; IfcTreeItem *m_parentItem; }; } diff --git a/UserInterface/Dialogues/IfcTreeModel.cpp b/UserInterface/Dialogues/IfcTreeModel.cpp index 14559adc7..1482b3f37 100644 --- a/UserInterface/Dialogues/IfcTreeModel.cpp +++ b/UserInterface/Dialogues/IfcTreeModel.cpp @@ -167,8 +167,10 @@ OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(const QString &data, QObject *parent) : QAbstractItemModel(parent) { - rootItem = new IfcTreeItem({ tr("Title"), tr("Summary") }); - setupModelData(data.split('\n'), rootItem); + QList rootData; + rootData << "Title" << "Summary"; + rootItem = new IfcTreeItem(rootData); + setupModelData(data.split(QString("\n")), rootItem); } OpenInfraPlatform::UserInterface::IfcTreeModel::~IfcTreeModel() @@ -180,7 +182,8 @@ int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelInde { if (parent.isValid()) return static_cast(parent.internalPointer())->columnCount(); - return rootItem->columnCount(); + else + return rootItem->columnCount(); } QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::data(const QModelIndex &index, int role) const @@ -199,7 +202,7 @@ QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::data(const QModelIndex Qt::ItemFlags OpenInfraPlatform::UserInterface::IfcTreeModel::flags(const QModelIndex &index) const { if (!index.isValid()) - return Qt::NoItemFlags; + return 0; return QAbstractItemModel::flags(index); } @@ -228,7 +231,8 @@ QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::index(int row, int c IfcTreeItem *childItem = parentItem->child(row); if (childItem) return createIndex(row, column, childItem); - return QModelIndex(); + else + return QModelIndex(); } QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::parent(const QModelIndex &index) const @@ -261,8 +265,8 @@ int OpenInfraPlatform::UserInterface::IfcTreeModel::rowCount(const QModelIndex & void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(const QStringList &lines, IfcTreeItem *parent) { - QVector parents; - QVector indentations; + QList parents; + QList indentations; parents << parent; indentations << 0; @@ -276,16 +280,14 @@ void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(const QStrin position++; } - const QString lineData = lines[number].mid(position).trimmed(); + QString lineData = lines[number].mid(position).trimmed(); if (!lineData.isEmpty()) { // Read the column data from the rest of the line. - const QStringList columnStrings = - lineData.split(QLatin1Char('\t'), QString::SkipEmptyParts); - QVector columnData; - columnData.reserve(columnStrings.count()); - for (const QString &columnString : columnStrings) - columnData << columnString; + QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); + QList columnData; + for (int column = 0; column < columnStrings.count(); ++column) + columnData << columnStrings[column]; if (position > indentations.last()) { // The last child of the current parent is now the new parent @@ -306,6 +308,7 @@ void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(const QStrin // Append a new item to the current parent's list of children. parents.last()->appendChild(new IfcTreeItem(columnData, parents.last())); } + ++number; } } \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeModel.h b/UserInterface/Dialogues/IfcTreeModel.h index 0cb49f9cb..625777b46 100644 --- a/UserInterface/Dialogues/IfcTreeModel.h +++ b/UserInterface/Dialogues/IfcTreeModel.h @@ -54,7 +54,7 @@ namespace OpenInfraPlatform // IfcTreeItem *rootItem_; public: - explicit IfcTreeModel(const QString &data, QObject *parent = nullptr); + explicit IfcTreeModel(const QString &data, QObject *parent = 0); ~IfcTreeModel(); QVariant data(const QModelIndex &index, int role) const override; diff --git a/testdata/default.txt b/testdata/default.txt index 4a97883ef..8c92181d4 100644 --- a/testdata/default.txt +++ b/testdata/default.txt @@ -1,40 +1,3 @@ Getting Started How to familiarize yourself with Qt Designer Launching Designer Running the Qt Designer application - The User Interface How to interact with Qt Designer - -Designing a Component Creating a GUI for your application - Creating a Dialog How to create a dialog - Composing the Dialog Putting widgets into the dialog example - Creating a Layout Arranging widgets on a form - Signal and Slot Connections Making widget communicate with each other - -Using a Component in Your Application Generating code from forms - The Direct Approach Using a form without any adjustments - The Single Inheritance Approach Subclassing a form's base class - The Multiple Inheritance Approach Subclassing the form itself - Automatic Connections Connecting widgets using a naming scheme - A Dialog Without Auto-Connect How to connect widgets without a naming scheme - A Dialog With Auto-Connect Using automatic connections - -Form Editing Mode How to edit a form in Qt Designer - Managing Forms Loading and saving forms - Editing a Form Basic editing techniques - The Property Editor Changing widget properties - The Object Inspector Examining the hierarchy of objects on a form - Layouts Objects that arrange widgets on a form - Applying and Breaking Layouts Managing widgets in layouts - Horizontal and Vertical Layouts Standard row and column layouts - The Grid Layout Arranging widgets in a matrix - Previewing Forms Checking that the design works - -Using Containers How to group widgets together - General Features Common container features - Frames QFrame - Group Boxes QGroupBox - Stacked Widgets QStackedWidget - Tab Widgets QTabWidget - Toolbox Widgets QToolBox - -Connection Editing Mode Connecting widgets together with signals and slots - Connecting Objects Making connections in Qt Designer - Editing Connections Changing existing connections \ No newline at end of file + The User Interface How to interact with Qt Designer \ No newline at end of file From 83a9654baa8afe2c9d3c8b63c68e1456005d2fc8 Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Thu, 1 Jul 2021 16:07:43 +0200 Subject: [PATCH 15/20] All it takes to get it to work --- UserInterface/Dialogues/IfcTreeDialog.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/UserInterface/Dialogues/IfcTreeDialog.cpp b/UserInterface/Dialogues/IfcTreeDialog.cpp index 842a04e64..fea905ae5 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.cpp +++ b/UserInterface/Dialogues/IfcTreeDialog.cpp @@ -42,14 +42,14 @@ OpenInfraPlatform::UserInterface::IfcTreeDialog::~IfcTreeDialog() void OpenInfraPlatform::UserInterface::IfcTreeDialog::show() { - ////for first testing just get last model, later this will be changed to selecting the model need + ////testing treeview with contents of IFC file //auto model = Core::DataManagement::DocumentManager::getInstance().getData().getLastModel(); //if (std::dynamic_pointer_cast(model)) //{ // auto ifcModel = std::static_pointer_cast(model); // auto expressModelShared = ifcModel->getExpressModel(); // OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel = expressModelShared.get(); - // auto treeModel = new IfcTreeModel(expressModel); + // IfcTreeModel *treeModel = new IfcTreeModel(expressModel); // ui_->ifcTreeView->setModel(treeModel); // ((QDialog*)this)->show(); //} @@ -59,18 +59,14 @@ void OpenInfraPlatform::UserInterface::IfcTreeDialog::show() // throw oip::UnhandledException("Last model is not a IFC model"); //} - //testing simple tree example - //QFile file(":/default.txt"); - //std::string cwd = _getcwd(NULL, 0); - //QFile file("..//..//Open-Infra-Platform//testdata//default.txt"); - //file.open(QIODevice::ReadOnly); - //IfcTreeModel model(file.readAll()); - //file.close(); + QFile file("..//..//Open-Infra-Platform//testdata//default.txt"); + file.open(QIODevice::ReadOnly); + IfcTreeModel *model = new IfcTreeModel(file.readAll()); + file.close(); - IfcTreeModel model(QString("May the stars align")); - ui_->ifcTreeView->setModel(&model); - ui_->ifcTreeView->setWindowTitle(QObject::tr("Title")); + ui_->ifcTreeView->setModel(model); + ui_->ifcTreeView->setWindowTitle(QObject::tr("Simple Tree Model")); ((QDialog*)this)->show(); ////testing with QFileSystemModel From 15d3a2f8b43abad1e2671c5109e2b06e55c7a349 Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Thu, 1 Jul 2021 17:19:25 +0200 Subject: [PATCH 16/20] Letting the treeviewer show the list of all IfcEntities within the loaded file --- Core/src/IfcGeometryConverter/IfcImporter.h | 14 +- UserInterface/Dialogues/IfcTreeDialog.cpp | 48 ++--- UserInterface/Dialogues/IfcTreeItem.cpp | 14 +- UserInterface/Dialogues/IfcTreeItem.h | 16 +- UserInterface/Dialogues/IfcTreeModel.cpp | 204 ++++++++++---------- UserInterface/Dialogues/IfcTreeModel.h | 29 +-- 6 files changed, 150 insertions(+), 175 deletions(-) diff --git a/Core/src/IfcGeometryConverter/IfcImporter.h b/Core/src/IfcGeometryConverter/IfcImporter.h index aba99b7d0..0ac33b92e 100644 --- a/Core/src/IfcGeometryConverter/IfcImporter.h +++ b/Core/src/IfcGeometryConverter/IfcImporter.h @@ -76,14 +76,6 @@ class IfcImporterT // get the georeferencingmetadata from the file georefConverter->init(expressModel); - //store a pointer to the express model in the in the ifc model (used for the tree viewer) - for (auto model : models) - { - model->setExpressModel(expressModel); - } - - - // collect all geometries if (!collectGeometryData(expressModel)) return models; @@ -103,6 +95,12 @@ class IfcImporterT if (!ifcModel->isEmpty()) models.push_back(ifcModel); + //store a pointer to the express model in the in the ifc model (used for the tree viewer) + for (auto& model : models) + { + model->setExpressModel(expressModel); + } + return models; } catch (const oip::InconsistentModellingException& ex) diff --git a/UserInterface/Dialogues/IfcTreeDialog.cpp b/UserInterface/Dialogues/IfcTreeDialog.cpp index fea905ae5..ca7b84984 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.cpp +++ b/UserInterface/Dialogues/IfcTreeDialog.cpp @@ -42,32 +42,32 @@ OpenInfraPlatform::UserInterface::IfcTreeDialog::~IfcTreeDialog() void OpenInfraPlatform::UserInterface::IfcTreeDialog::show() { - ////testing treeview with contents of IFC file - //auto model = Core::DataManagement::DocumentManager::getInstance().getData().getLastModel(); - //if (std::dynamic_pointer_cast(model)) - //{ - // auto ifcModel = std::static_pointer_cast(model); - // auto expressModelShared = ifcModel->getExpressModel(); - // OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel = expressModelShared.get(); - // IfcTreeModel *treeModel = new IfcTreeModel(expressModel); - // ui_->ifcTreeView->setModel(treeModel); - // ((QDialog*)this)->show(); - //} - //else - //{ - // //only for now till the selected model is properly handled - // throw oip::UnhandledException("Last model is not a IFC model"); - //} + //testing treeview with contents of IFC file + auto model = Core::DataManagement::DocumentManager::getInstance().getData().getLastModel(); + if (std::dynamic_pointer_cast(model)) + { + auto ifcModel = std::static_pointer_cast(model); + auto expressModelShared = ifcModel->getExpressModel(); + OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel = expressModelShared.get(); + IfcTreeModel *treeModel = new IfcTreeModel(expressModel); + ui_->ifcTreeView->setModel(treeModel); + ((QDialog*)this)->show(); + } + else + { + //only for now till the selected model is properly handled + throw oip::UnhandledException("Last model is not a IFC model"); + } - //testing simple tree example - QFile file("..//..//Open-Infra-Platform//testdata//default.txt"); - file.open(QIODevice::ReadOnly); - IfcTreeModel *model = new IfcTreeModel(file.readAll()); - file.close(); + ////testing simple tree example + //QFile file("..//..//Open-Infra-Platform//testdata//default.txt"); + //file.open(QIODevice::ReadOnly); + //IfcTreeModel *model = new IfcTreeModel(file.readAll()); + //file.close(); - ui_->ifcTreeView->setModel(model); - ui_->ifcTreeView->setWindowTitle(QObject::tr("Simple Tree Model")); - ((QDialog*)this)->show(); + //ui_->ifcTreeView->setModel(model); + //ui_->ifcTreeView->setWindowTitle(QObject::tr("Simple Tree Model")); + //((QDialog*)this)->show(); ////testing with QFileSystemModel //QFileSystemModel *model = new QFileSystemModel; diff --git a/UserInterface/Dialogues/IfcTreeItem.cpp b/UserInterface/Dialogues/IfcTreeItem.cpp index 76e23c8a2..e51aab882 100644 --- a/UserInterface/Dialogues/IfcTreeItem.cpp +++ b/UserInterface/Dialogues/IfcTreeItem.cpp @@ -23,13 +23,13 @@ #include "visit_struct\visit_struct.hpp" -//OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem) -//{ -// data_ = data; -// parentItem_ = parentItem; -// //itemData_.push_back(data_->getStepLine()); -// itemData_.push_back(data_->classname()); -//} +OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem) +{ + data_ = data; + m_parentItem = parentItem; + //itemData_.push_back(data_->getStepLine()); + m_itemData.push_back(QString::fromStdString(data_->classname())); +} // //OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem() //{ diff --git a/UserInterface/Dialogues/IfcTreeItem.h b/UserInterface/Dialogues/IfcTreeItem.h index 7672b9258..3fe182725 100644 --- a/UserInterface/Dialogues/IfcTreeItem.h +++ b/UserInterface/Dialogues/IfcTreeItem.h @@ -31,16 +31,6 @@ namespace OpenInfraPlatform { //public: // explicit IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem); // explicit IfcTreeItem(); - // ~IfcTreeItem(); - - // void appendchild(IfcTreeItem *child); - - // IfcTreeItem *child(int row); - // int childCount() const; - // int columnCount() const; - // QVariant data(int column) const; - // int row() const; - // IfcTreeItem *parentItem(); // QString getIfcClassName() const; //private: @@ -49,10 +39,9 @@ namespace OpenInfraPlatform { // std::vector itemData_; // IfcTreeItem *parentItem_; - // //struct getAttributeDescription; - public: explicit IfcTreeItem(const QList &data, IfcTreeItem *parentItem = 0); + explicit IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem); ~IfcTreeItem(); void appendChild(IfcTreeItem *child); @@ -66,8 +55,11 @@ namespace OpenInfraPlatform { private: QList m_childItems; + OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data_; QList m_itemData; IfcTreeItem *m_parentItem; + + //struct getAttributeDescription; }; } } diff --git a/UserInterface/Dialogues/IfcTreeModel.cpp b/UserInterface/Dialogues/IfcTreeModel.cpp index 1482b3f37..27ccc0ff0 100644 --- a/UserInterface/Dialogues/IfcTreeModel.cpp +++ b/UserInterface/Dialogues/IfcTreeModel.cpp @@ -25,14 +25,14 @@ #include -//OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent) -// : QAbstractItemModel(parent) -//{ -// //rootItem_ = std::make_shared(expressModel->entities.find(1)->second, nullptr); //make ifcProject the root item -// //std::string text = "Title"; -// rootItem_ = new IfcTreeItem(); -// setupModelData(expressModel, rootItem_); -//} +OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent) + : QAbstractItemModel(parent) +{ + QList rootData; + rootData << "Title" << "Summary"; + rootItem = new IfcTreeItem(rootData); + setupModelData(expressModel, rootItem); +} // //OpenInfraPlatform::UserInterface::IfcTreeModel::~IfcTreeModel() //{ @@ -132,47 +132,47 @@ // return item->data(index.column()); //} // -//void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent) -//{ -// //auto entities = expressModel->entities; -// -// //for (int i = 0; i < 10; i++) -// //{ -// // std::shared_ptr item = std::make_shared(entities.find(i)->second, parent); -// // parent->appendchild(item); -// //} -// -// for (auto entity : expressModel->entities) -// { -// parent->appendchild(new IfcTreeItem(entity.second.get(), parent)); -// } -// -// //for (int i = 3; i < 4; i++) -// //{ -// // std::shared_ptr item1 = std::make_shared(entities.find(i)->second, parent); -// // parent->appendchild(item1); -// // std::shared_ptr item2 = std::make_shared(entities.find(i + 1)->second, parent); -// // parent->appendchild(item2); -// // std::shared_ptr item3 = std::make_shared(entities.find(i + 2)->second, parent); -// // parent->appendchild(item3); -// //} -// //for (auto entity : entities) -// //{ -// // IfcTreeItem *item = new IfcTreeItem(entity.second); -// // std::shared_ptr itemShared(item); -// // rootItem_->appendchild(itemShared); -// //} -//} - -OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(const QString &data, QObject *parent) - : QAbstractItemModel(parent) +void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(const OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent) { - QList rootData; - rootData << "Title" << "Summary"; - rootItem = new IfcTreeItem(rootData); - setupModelData(data.split(QString("\n")), rootItem); + //auto entities = expressModel->entities; + + //for (int i = 0; i < 10; i++) + //{ + // IfcTreeItem *item = new IfcTreeItem(entities.find(i)->second.get(), parent); + // parent->appendChild(item); + //} + + for (auto entity : expressModel->entities) + { + parent->appendChild(new IfcTreeItem(entity.second.get(), parent)); + } + + //for (int i = 3; i < 4; i++) + //{ + // std::shared_ptr item1 = std::make_shared(entities.find(i)->second, parent); + // parent->appendchild(item1); + // std::shared_ptr item2 = std::make_shared(entities.find(i + 1)->second, parent); + // parent->appendchild(item2); + // std::shared_ptr item3 = std::make_shared(entities.find(i + 2)->second, parent); + // parent->appendchild(item3); + //} + //for (auto entity : entities) + //{ + // IfcTreeItem *item = new IfcTreeItem(entity.second); + // std::shared_ptr itemShared(item); + // rootItem_->appendchild(itemShared); + //} } +//OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(const QString &data, QObject *parent) +// : QAbstractItemModel(parent) +//{ +// QList rootData; +// rootData << "Title" << "Summary"; +// rootItem = new IfcTreeItem(rootData); +// setupModelData(data.split(QString("\n")), rootItem); +//} + OpenInfraPlatform::UserInterface::IfcTreeModel::~IfcTreeModel() { delete rootItem; @@ -199,13 +199,13 @@ QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::data(const QModelIndex return item->data(index.column()); } -Qt::ItemFlags OpenInfraPlatform::UserInterface::IfcTreeModel::flags(const QModelIndex &index) const -{ - if (!index.isValid()) - return 0; - - return QAbstractItemModel::flags(index); -} +//Qt::ItemFlags OpenInfraPlatform::UserInterface::IfcTreeModel::flags(const QModelIndex &index) const +//{ +// if (!index.isValid()) +// return 0; +// +// return QAbstractItemModel::flags(index); +//} QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -263,52 +263,52 @@ int OpenInfraPlatform::UserInterface::IfcTreeModel::rowCount(const QModelIndex & return parentItem->childCount(); } -void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(const QStringList &lines, IfcTreeItem *parent) -{ - QList parents; - QList indentations; - parents << parent; - indentations << 0; - - int number = 0; - - while (number < lines.count()) { - int position = 0; - while (position < lines[number].length()) { - if (lines[number].at(position) != ' ') - break; - position++; - } - - QString lineData = lines[number].mid(position).trimmed(); - - if (!lineData.isEmpty()) { - // Read the column data from the rest of the line. - QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); - QList columnData; - for (int column = 0; column < columnStrings.count(); ++column) - columnData << columnStrings[column]; - - if (position > indentations.last()) { - // The last child of the current parent is now the new parent - // unless the current parent has no children. - - if (parents.last()->childCount() > 0) { - parents << parents.last()->child(parents.last()->childCount() - 1); - indentations << position; - } - } - else { - while (position < indentations.last() && parents.count() > 0) { - parents.pop_back(); - indentations.pop_back(); - } - } - - // Append a new item to the current parent's list of children. - parents.last()->appendChild(new IfcTreeItem(columnData, parents.last())); - } - - ++number; - } -} \ No newline at end of file +//void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(const QStringList &lines, IfcTreeItem *parent) +//{ +// QList parents; +// QList indentations; +// parents << parent; +// indentations << 0; +// +// int number = 0; +// +// while (number < lines.count()) { +// int position = 0; +// while (position < lines[number].length()) { +// if (lines[number].at(position) != ' ') +// break; +// position++; +// } +// +// QString lineData = lines[number].mid(position).trimmed(); +// +// if (!lineData.isEmpty()) { +// // Read the column data from the rest of the line. +// QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); +// QList columnData; +// for (int column = 0; column < columnStrings.count(); ++column) +// columnData << columnStrings[column]; +// +// if (position > indentations.last()) { +// // The last child of the current parent is now the new parent +// // unless the current parent has no children. +// +// if (parents.last()->childCount() > 0) { +// parents << parents.last()->child(parents.last()->childCount() - 1); +// indentations << position; +// } +// } +// else { +// while (position < indentations.last() && parents.count() > 0) { +// parents.pop_back(); +// indentations.pop_back(); +// } +// } +// +// // Append a new item to the current parent's list of children. +// parents.last()->appendChild(new IfcTreeItem(columnData, parents.last())); +// } +// +// ++number; +// } +//} \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeModel.h b/UserInterface/Dialogues/IfcTreeModel.h index 625777b46..78b224fae 100644 --- a/UserInterface/Dialogues/IfcTreeModel.h +++ b/UserInterface/Dialogues/IfcTreeModel.h @@ -35,30 +35,14 @@ namespace OpenInfraPlatform { Q_OBJECT; - //public: - // explicit IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent = nullptr); - // ~IfcTreeModel(); - - ////override from QAbstractItemModel - // QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - // QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; - // QModelIndex parent(const QModelIndex &index) const override; - // int rowCount(const QModelIndex &parent = QModelIndex()) const override; - // int columnCount(const QModelIndex &parent = QModelIndex()) const override; - // QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - // Qt::ItemFlags flags(const QModelIndex &index) const override; - - //private: - // void setupModelData(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent); - - // IfcTreeItem *rootItem_; - public: - explicit IfcTreeModel(const QString &data, QObject *parent = 0); + //explicit IfcTreeModel(const QString &data, QObject *parent = nullptr); + explicit IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent = nullptr); ~IfcTreeModel(); - + + //override from QAbstractItemModel QVariant data(const QModelIndex &index, int role) const override; - Qt::ItemFlags flags(const QModelIndex &index) const override; + //Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QModelIndex index(int row, int column, @@ -68,7 +52,8 @@ namespace OpenInfraPlatform int columnCount(const QModelIndex &parent = QModelIndex()) const override; private: - void setupModelData(const QStringList &lines, IfcTreeItem *parent); + //void setupModelData(const QStringList &lines, IfcTreeItem *parent); + void setupModelData(const OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent); IfcTreeItem *rootItem; }; From 5a289615c344db2470df1482d6ee3f713982ff9b Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Thu, 1 Jul 2021 17:30:21 +0200 Subject: [PATCH 17/20] Clean up IfcTreeItem --- UserInterface/Dialogues/IfcTreeItem.cpp | 183 ++++++++---------------- UserInterface/Dialogues/IfcTreeItem.h | 20 +-- UserInterface/Forms/IfcTreeDialog.ui | 2 +- 3 files changed, 67 insertions(+), 138 deletions(-) diff --git a/UserInterface/Dialogues/IfcTreeItem.cpp b/UserInterface/Dialogues/IfcTreeItem.cpp index e51aab882..23f2be067 100644 --- a/UserInterface/Dialogues/IfcTreeItem.cpp +++ b/UserInterface/Dialogues/IfcTreeItem.cpp @@ -26,57 +26,50 @@ OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem) { data_ = data; - m_parentItem = parentItem; + parentItem_ = parentItem; //itemData_.push_back(data_->getStepLine()); - m_itemData.push_back(QString::fromStdString(data_->classname())); + itemData_.push_back(QString::fromStdString(data_->classname())); +} + +OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(const QList &data, IfcTreeItem *parent) +{ + parentItem_ = parent; + itemData_ = data; +} + +OpenInfraPlatform::UserInterface::IfcTreeItem::~IfcTreeItem() +{ + qDeleteAll(childItems_); +} + +void OpenInfraPlatform::UserInterface::IfcTreeItem::appendChild(IfcTreeItem *child) +{ + childItems_.append(child); +} + +OpenInfraPlatform::UserInterface::IfcTreeItem *OpenInfraPlatform::UserInterface::IfcTreeItem::child(int row) +{ + //if (row < 0 || row >= m_childItems.size()) + // return nullptr; + return childItems_.value(row); //QList provides default values in case row is out of range +} + +int OpenInfraPlatform::UserInterface::IfcTreeItem::childCount() const +{ + return childItems_.count(); +} + +int OpenInfraPlatform::UserInterface::IfcTreeItem::columnCount() const +{ + return itemData_.count(); +} + +QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const +{ + //if (column < 0 || column >= m_itemData.size()) + // return QVariant(); + return itemData_.value(column); //QList provides default values in case row is out of range } -// -//OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem() -//{ -// data_ = nullptr; -// parentItem_ = nullptr; -// std::string text = "Title"; -// itemData_.push_back(text); -//} -// -//OpenInfraPlatform::UserInterface::IfcTreeItem::~IfcTreeItem() -//{ -// //childItems_.clear(); -// qDeleteAll(childItems_); -//} -// -//void OpenInfraPlatform::UserInterface::IfcTreeItem::appendchild(IfcTreeItem *child) -//{ -// childItems_.append(child); -//} -// -//OpenInfraPlatform::UserInterface::IfcTreeItem* OpenInfraPlatform::UserInterface::IfcTreeItem::child(int row) -//{ -// if (row < 0 || row >= childItems_.size()) -// throw oip::UnhandledException("Child index out of range (IfcTreeItem::child)"); -// -// return childItems_.at(row); -//} -// -//int OpenInfraPlatform::UserInterface::IfcTreeItem::childCount() const -//{ -// int nrOfChilds = childItems_.count(); -// return nrOfChilds; -//} -// -//int OpenInfraPlatform::UserInterface::IfcTreeItem::columnCount() const -//{ -// int nrOfColumns = itemData_.size(); //size right here? -// return nrOfColumns; -//} -// -//QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const -//{ -// if (column < 0 || column >= itemData_.size()) -// return QVariant(); -// //QString text = QString::fromStdString(itemData_.at(column)); -// return QString("text"); -//} //QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const //{ @@ -99,25 +92,24 @@ OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(OpenInfraPlatform::Ea // return getIfcClassName(); //} -//int OpenInfraPlatform::UserInterface::IfcTreeItem::row() const -//{ -// if (parentItem_) -// { -// return parentItem_->childItems_.indexOf(const_cast(this)); -// } -// return 0; -//} -// -//OpenInfraPlatform::UserInterface::IfcTreeItem* OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() -//{ -// return parentItem_; -//} -// -//QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const -//{ -// std::string ifcClassName = data_->classname(); -// return QString::fromStdString(ifcClassName); -//} +OpenInfraPlatform::UserInterface::IfcTreeItem *OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() +{ + return parentItem_; +} + +int OpenInfraPlatform::UserInterface::IfcTreeItem::row() const +{ + if (parentItem_) + return parentItem_->childItems_.indexOf(const_cast(this)); + + return 0; +} + +QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const +{ + std::string ifcClassName = data_->classname(); + return QString::fromStdString(ifcClassName); +} //struct OpenInfraPlatform::UserInterface::IfcTreeItem::getAttributeDescription //{ @@ -148,57 +140,4 @@ OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(OpenInfraPlatform::Ea // std::vector names_; // std::vector typename_; // std::vector value_; -//}; - -OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(const QList &data, IfcTreeItem *parent) -{ - m_parentItem = parent; - m_itemData = data; -} - -OpenInfraPlatform::UserInterface::IfcTreeItem::~IfcTreeItem() -{ - qDeleteAll(m_childItems); -} - -void OpenInfraPlatform::UserInterface::IfcTreeItem::appendChild(IfcTreeItem *item) -{ - m_childItems.append(item); -} - -OpenInfraPlatform::UserInterface::IfcTreeItem *OpenInfraPlatform::UserInterface::IfcTreeItem::child(int row) -{ - //if (row < 0 || row >= m_childItems.size()) - // return nullptr; - return m_childItems.value(row); //QList provides default values in case row is out of range -} - -int OpenInfraPlatform::UserInterface::IfcTreeItem::childCount() const -{ - return m_childItems.count(); -} - -int OpenInfraPlatform::UserInterface::IfcTreeItem::columnCount() const -{ - return m_itemData.count(); -} - -QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const -{ - //if (column < 0 || column >= m_itemData.size()) - // return QVariant(); - return m_itemData.value(column); -} - -OpenInfraPlatform::UserInterface::IfcTreeItem *OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() -{ - return m_parentItem; -} - -int OpenInfraPlatform::UserInterface::IfcTreeItem::row() const -{ - if (m_parentItem) - return m_parentItem->m_childItems.indexOf(const_cast(this)); - - return 0; -} \ No newline at end of file +//}; \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeItem.h b/UserInterface/Dialogues/IfcTreeItem.h index 3fe182725..4842e832f 100644 --- a/UserInterface/Dialogues/IfcTreeItem.h +++ b/UserInterface/Dialogues/IfcTreeItem.h @@ -28,20 +28,9 @@ namespace OpenInfraPlatform { class IfcTreeItem { - //public: - // explicit IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem); - // explicit IfcTreeItem(); - // QString getIfcClassName() const; - - //private: - // QVector childItems_; - // OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data_; - // std::vector itemData_; - // IfcTreeItem *parentItem_; - public: - explicit IfcTreeItem(const QList &data, IfcTreeItem *parentItem = 0); explicit IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem); + explicit IfcTreeItem(const QList &data, IfcTreeItem *parentItem = 0); ~IfcTreeItem(); void appendChild(IfcTreeItem *child); @@ -52,12 +41,13 @@ namespace OpenInfraPlatform { QVariant data(int column) const; int row() const; IfcTreeItem *parentItem(); + QString getIfcClassName() const; private: - QList m_childItems; + QList childItems_; OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data_; - QList m_itemData; - IfcTreeItem *m_parentItem; + QList itemData_; + IfcTreeItem *parentItem_; //struct getAttributeDescription; }; diff --git a/UserInterface/Forms/IfcTreeDialog.ui b/UserInterface/Forms/IfcTreeDialog.ui index 580bb8406..e76f52269 100644 --- a/UserInterface/Forms/IfcTreeDialog.ui +++ b/UserInterface/Forms/IfcTreeDialog.ui @@ -6,7 +6,7 @@ 0 0 - 200 + 450 600 From a7d19f5188914cd6ce18b4e532c437b80dd6512b Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Thu, 1 Jul 2021 17:31:29 +0200 Subject: [PATCH 18/20] Clean up IfcTreeDialog --- UserInterface/Dialogues/IfcTreeDialog.cpp | 27 ----------------------- UserInterface/Dialogues/IfcTreeDialog.h | 2 +- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/UserInterface/Dialogues/IfcTreeDialog.cpp b/UserInterface/Dialogues/IfcTreeDialog.cpp index ca7b84984..c8123b586 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.cpp +++ b/UserInterface/Dialogues/IfcTreeDialog.cpp @@ -58,33 +58,6 @@ void OpenInfraPlatform::UserInterface::IfcTreeDialog::show() //only for now till the selected model is properly handled throw oip::UnhandledException("Last model is not a IFC model"); } - - ////testing simple tree example - //QFile file("..//..//Open-Infra-Platform//testdata//default.txt"); - //file.open(QIODevice::ReadOnly); - //IfcTreeModel *model = new IfcTreeModel(file.readAll()); - //file.close(); - - //ui_->ifcTreeView->setModel(model); - //ui_->ifcTreeView->setWindowTitle(QObject::tr("Simple Tree Model")); - //((QDialog*)this)->show(); - - ////testing with QFileSystemModel - //QFileSystemModel *model = new QFileSystemModel; - //model->setRootPath(QDir::currentPath()); - //ui_->ifcTreeView->setModel(model); - //ui_->ifcTreeView->setRootIndex(model->index(QDir::currentPath())); - //((QDialog*)this)->show(); - - ////testing with QTreeWidget (IfcTreeDialog.ui needs to be changed) - //ui_->ifcTreeView->setColumnCount(1); - //QList items; - //for (int i = 0; i < 10; i++) - //{ - // items.append(new QTreeWidgetItem(static_cast(nullptr), QStringList(QString("item: %1").arg(i)))); - //} - //ui_->ifcTreeView->insertTopLevelItems(0, items); - //((QDialog*)this)->show(); } diff --git a/UserInterface/Dialogues/IfcTreeDialog.h b/UserInterface/Dialogues/IfcTreeDialog.h index 8240e4408..167d550ce 100644 --- a/UserInterface/Dialogues/IfcTreeDialog.h +++ b/UserInterface/Dialogues/IfcTreeDialog.h @@ -44,7 +44,7 @@ namespace OpenInfraPlatform private: Ui::IfcTreeDialog* ui_; - //OpenInfraPlatform::UserInterface::View* view_; + }; // end class IfcTree } // end namespace UserInterface } // end namespace OpenInfraPlatform From 007fa6faecf3475cc44e7673827bd3e617f6c882 Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Thu, 1 Jul 2021 17:40:43 +0200 Subject: [PATCH 19/20] Clean up IfcTreeModel --- UserInterface/Dialogues/IfcTreeModel.cpp | 212 ++--------------------- UserInterface/Dialogues/IfcTreeModel.h | 4 - 2 files changed, 16 insertions(+), 200 deletions(-) diff --git a/UserInterface/Dialogues/IfcTreeModel.cpp b/UserInterface/Dialogues/IfcTreeModel.cpp index 27ccc0ff0..216cbab7d 100644 --- a/UserInterface/Dialogues/IfcTreeModel.cpp +++ b/UserInterface/Dialogues/IfcTreeModel.cpp @@ -33,145 +33,6 @@ OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(OpenInfraPlatform:: rootItem = new IfcTreeItem(rootData); setupModelData(expressModel, rootItem); } -// -//OpenInfraPlatform::UserInterface::IfcTreeModel::~IfcTreeModel() -//{ -// delete rootItem_; -//} -// -//QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::index(int row, int column, const QModelIndex &parent) const -//{ -// if (!hasIndex(row, column, parent)) -// return QModelIndex(); -// -// IfcTreeItem* parentItem; -// -// if (!parent.isValid()) -// parentItem = rootItem_; -// //return this->createIndex(row, column, nullptr); -// else -// parentItem = static_cast(parent.internalPointer()); -// -// IfcTreeItem *childItem = parentItem->child(row); -// if (childItem) -// { -// auto n = createIndex(row, column, childItem); -// return n; -// } -// //return createIndex(row, column, childItem); -// return QModelIndex(); -//} -// -//QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::headerData(int section, Qt::Orientation orientation, -// int role) const -//{ -// return rootItem_->data(section); -//} -// -//QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::parent(const QModelIndex &index) const -//{ -// if (!index.isValid()) -// return QModelIndex(); -// -// IfcTreeItem *child = static_cast(index.internalPointer()); -// IfcTreeItem *parentItem = child->parentItem(); -// -// if (parentItem == rootItem_) -// return QModelIndex(); -// -// return createIndex(parentItem->row(), 0, parentItem); -//} -// -//int OpenInfraPlatform::UserInterface::IfcTreeModel::rowCount(const QModelIndex &parent) const -//{ -// IfcTreeItem *parentItem; -// -// if (parent.column() > 0) -// return 0; -// -// if (!parent.isValid()) -// parentItem = rootItem_; -// else -// parentItem = static_cast(parent.internalPointer()); -// -// int nrOfRows = parentItem->childCount(); -// return nrOfRows; -//} -// -//int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const -//{ -// if (parent.isValid()) -// return static_cast(parent.internalPointer())->columnCount(); -// int nrOfColumns = rootItem_->columnCount(); -// return nrOfColumns; -//} - -//int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const -//{ -// if (!parent.isValid()) -// return 1; //correct for testing? -// else -// return 3; -//} - -//Qt::ItemFlags OpenInfraPlatform::UserInterface::IfcTreeModel::flags(const QModelIndex &index) const -//{ -// if (!index.isValid()) -// return Qt::NoItemFlags; -// -// return QAbstractItemModel::flags(index); -//} -// -//QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::data(const QModelIndex &index, int role) const -//{ -// if (!index.isValid()) -// return QVariant(); -// -// IfcTreeItem *item = static_cast(index.internalPointer()); -// -// return item->data(index.column()); -//} -// -void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(const OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent) -{ - //auto entities = expressModel->entities; - - //for (int i = 0; i < 10; i++) - //{ - // IfcTreeItem *item = new IfcTreeItem(entities.find(i)->second.get(), parent); - // parent->appendChild(item); - //} - - for (auto entity : expressModel->entities) - { - parent->appendChild(new IfcTreeItem(entity.second.get(), parent)); - } - - //for (int i = 3; i < 4; i++) - //{ - // std::shared_ptr item1 = std::make_shared(entities.find(i)->second, parent); - // parent->appendchild(item1); - // std::shared_ptr item2 = std::make_shared(entities.find(i + 1)->second, parent); - // parent->appendchild(item2); - // std::shared_ptr item3 = std::make_shared(entities.find(i + 2)->second, parent); - // parent->appendchild(item3); - //} - //for (auto entity : entities) - //{ - // IfcTreeItem *item = new IfcTreeItem(entity.second); - // std::shared_ptr itemShared(item); - // rootItem_->appendchild(itemShared); - //} -} - -//OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(const QString &data, QObject *parent) -// : QAbstractItemModel(parent) -//{ -// QList rootData; -// rootData << "Title" << "Summary"; -// rootItem = new IfcTreeItem(rootData); -// setupModelData(data.split(QString("\n")), rootItem); -//} OpenInfraPlatform::UserInterface::IfcTreeModel::~IfcTreeModel() { @@ -186,6 +47,15 @@ int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelInde return rootItem->columnCount(); } +//int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const +//{ +// if (!parent.isValid()) +// return 1; //correct for testing? +// else +// return 3; +//} + + QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) @@ -199,14 +69,6 @@ QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::data(const QModelIndex return item->data(index.column()); } -//Qt::ItemFlags OpenInfraPlatform::UserInterface::IfcTreeModel::flags(const QModelIndex &index) const -//{ -// if (!index.isValid()) -// return 0; -// -// return QAbstractItemModel::flags(index); -//} - QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::headerData(int section, Qt::Orientation orientation, int role) const { @@ -263,52 +125,10 @@ int OpenInfraPlatform::UserInterface::IfcTreeModel::rowCount(const QModelIndex & return parentItem->childCount(); } -//void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(const QStringList &lines, IfcTreeItem *parent) -//{ -// QList parents; -// QList indentations; -// parents << parent; -// indentations << 0; -// -// int number = 0; -// -// while (number < lines.count()) { -// int position = 0; -// while (position < lines[number].length()) { -// if (lines[number].at(position) != ' ') -// break; -// position++; -// } -// -// QString lineData = lines[number].mid(position).trimmed(); -// -// if (!lineData.isEmpty()) { -// // Read the column data from the rest of the line. -// QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); -// QList columnData; -// for (int column = 0; column < columnStrings.count(); ++column) -// columnData << columnStrings[column]; -// -// if (position > indentations.last()) { -// // The last child of the current parent is now the new parent -// // unless the current parent has no children. -// -// if (parents.last()->childCount() > 0) { -// parents << parents.last()->child(parents.last()->childCount() - 1); -// indentations << position; -// } -// } -// else { -// while (position < indentations.last() && parents.count() > 0) { -// parents.pop_back(); -// indentations.pop_back(); -// } -// } -// -// // Append a new item to the current parent's list of children. -// parents.last()->appendChild(new IfcTreeItem(columnData, parents.last())); -// } -// -// ++number; -// } -//} \ No newline at end of file +void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(const OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent) +{ + for (auto entity : expressModel->entities) + { + parent->appendChild(new IfcTreeItem(entity.second.get(), parent)); + } +} \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeModel.h b/UserInterface/Dialogues/IfcTreeModel.h index 78b224fae..8f1c72553 100644 --- a/UserInterface/Dialogues/IfcTreeModel.h +++ b/UserInterface/Dialogues/IfcTreeModel.h @@ -36,13 +36,11 @@ namespace OpenInfraPlatform Q_OBJECT; public: - //explicit IfcTreeModel(const QString &data, QObject *parent = nullptr); explicit IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent = nullptr); ~IfcTreeModel(); //override from QAbstractItemModel QVariant data(const QModelIndex &index, int role) const override; - //Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QModelIndex index(int row, int column, @@ -52,12 +50,10 @@ namespace OpenInfraPlatform int columnCount(const QModelIndex &parent = QModelIndex()) const override; private: - //void setupModelData(const QStringList &lines, IfcTreeItem *parent); void setupModelData(const OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent); IfcTreeItem *rootItem; }; - } } From 42bdceb575fbeea9066a4d856359342e31221e36 Mon Sep 17 00:00:00 2001 From: Jonas Schlenger Date: Mon, 12 Jul 2021 08:54:09 +0200 Subject: [PATCH 20/20] Some code from old tree viewer versions --- UserInterface/Dialogues/IfcTreeItem.cpp | 46 +++++- UserInterface/Dialogues/IfcTreeItem.h | 179 ++++++++++++++++++++++- UserInterface/Dialogues/IfcTreeModel.cpp | 23 +++ 3 files changed, 243 insertions(+), 5 deletions(-) diff --git a/UserInterface/Dialogues/IfcTreeItem.cpp b/UserInterface/Dialogues/IfcTreeItem.cpp index 23f2be067..b8009a4e3 100644 --- a/UserInterface/Dialogues/IfcTreeItem.cpp +++ b/UserInterface/Dialogues/IfcTreeItem.cpp @@ -31,6 +31,12 @@ OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(OpenInfraPlatform::Ea itemData_.push_back(QString::fromStdString(data_->classname())); } +//OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(std::shared_ptr &data, IfcTreeItem * parent) +// : m_managedData(data), m_parentItem(parent), parser_() +//{ +// parser_.thisPtr = this; +//} + OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(const QList &data, IfcTreeItem *parent) { parentItem_ = parent; @@ -87,9 +93,6 @@ QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const // // return attributes.typename_[row]; // // break; // //} -// -// //return QVariant(); -// return getIfcClassName(); //} OpenInfraPlatform::UserInterface::IfcTreeItem *OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() @@ -140,4 +143,39 @@ QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const // std::vector names_; // std::vector typename_; // std::vector value_; -//}; \ No newline at end of file +//}; + +//void OpenInfraPlatform::UserInterface::IfcTreeItem::createChildren() +//{ +// auto func = [&](auto item)->void { +// visit_struct::for_each(item, [&](const char* name, auto &value) { +// IfcTreeItem* child; +// //if(std::is_base_of::value) { +// // child = new TreeItem(value, this); +// //} +// //else { +// // child = new TreeItem(OpenInfraPlatform::IfcAlignment1x1::IfcAlignment1x1Object(), this); +// //} +// std::shared_ptr ptr = nullptr; +// child = new IfcTreeItem(ptr, this); +// QList itemData; +// itemData << QVariant(name) << QVariant("") << QVariant(typeid(value).name()); +// this->appendChild(child); +// }); +// }; +// +// auto parse = [&](auto item) { +// visit_struct::for_each(item, parser_); +// }; +// +// if (m_managedData && m_managedData.get() != nullptr) { +// if (std::dynamic_pointer_cast(m_managedData)) { +// //OpenInfraPlatform::IfcAlignment1x1::castToVisitableAndCall(std::dynamic_pointer_cast(m_managedData), parse); +// } +// } +//} + +//void OpenInfraPlatform::UserInterface::TreeItem::setItemData(QList itemData) +//{ +// itemData_ = itemData; +//} \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeItem.h b/UserInterface/Dialogues/IfcTreeItem.h index 4842e832f..5bdb37bec 100644 --- a/UserInterface/Dialogues/IfcTreeItem.h +++ b/UserInterface/Dialogues/IfcTreeItem.h @@ -43,6 +43,9 @@ namespace OpenInfraPlatform { IfcTreeItem *parentItem(); QString getIfcClassName() const; + //void setItemData(QList itemData); + //void createChildren(); + private: QList childItems_; OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data_; @@ -50,11 +53,185 @@ namespace OpenInfraPlatform { IfcTreeItem *parentItem_; //struct getAttributeDescription; + + //std::shared_ptr m_managedData = nullptr; + + ////Helper struct which parses the attributes of a derived entity which are IfcAlignment1x1Types and hold flat values. + //struct parseType { + + // void operator()(const char* name, std::string string) + // { + // std::shared_ptr ptr = nullptr; + // TreeItem* child = new TreeItem(ptr, thisPtr); + // QList itemData; + // itemData << QVariant(name) << QVariant(string.data()) << QVariant("std::string"); + // child->setItemData(itemData); + // thisPtr->appendChild(child); + // } + + // //Function operator() which creates a statement from a boolean value. + // void operator()(const char* name, bool value) + // { + // std::shared_ptr ptr = nullptr; + // TreeItem* child = new TreeItem(ptr, thisPtr); + // QList itemData; + // itemData << QVariant(name) << QVariant(value) << QVariant("bool"); + // child->setItemData(itemData); + // thisPtr->appendChild(child); + // } + + // void operator()(const char* name, std::shared_ptr value) + // { + // TreeItem* child = new TreeItem(std::static_pointer_cast(value), thisPtr); + // QList itemData; + // itemData << QVariant(name) << QVariant(value ? value->getId() : -1); //<< QVariant(value ? value->classname() : "nullptr"); + // child->setItemData(itemData); + // thisPtr->appendChild(child); + // } + + // //TODO: Get value stored in type + // void operator()(const char* name, std::shared_ptr value) + // { + // TreeItem* child = new TreeItem(std::static_pointer_cast(value), thisPtr); + // QList itemData; + + // //std::stringstream ss; + // if (value) + // //readStepData(std::string& arg) + // //value->getStepData(ss); + + + // //auto classname = value->classname(); //Gibt z.B. IfcLabel o.ä. zurück + // //static_cast(value); + // //auto castedValue = value.m_value; //gibt m_value zurück aus IfcLabel, also den eigentlichen Wert, der als String o.ö. gespeichert ist + // //auto castedType = typeid(castedValue).name(); //gibt den Typ von m_value zurück, also z.B. String + // // + // //if (castedType == "string" || "char") + // // QVariant value2 = QVariant(castedValue.data()); + // // return value2; + // //if (castedType == "bool" || "int" || "float" || "double") + // // QVariant value2 = QVariant(castedValue); + // // return value2; + + // //itemData << QVariant(name) << QVariant(ss.str().data()) << QVariant(value ? value->classname() : "nullptr"); + // itemData << QVariant(name) << QVariant("m_type"); //<< QVariant(value ? value->classname() : "nullptr"); + // //itemData << QVariant(name) << QVariant("m_type") << QVariant(value ? value->classname() : "nullptr"); + + // child->setItemData(itemData); + // thisPtr->appendChild(child); + // } + + // //template typename std::enable_if::value && !std::is_base_of::value, void>::type + // //operator()(const char* name, std::shared_ptr value) + // //{ + // // std::shared_ptr ptr = nullptr; + // // TreeItem* child = new TreeItem(ptr, thisPtr); + // // QList itemData; + // // itemData << QVariant(name) << QVariant("m_select") << QVariant(typeid(T).name()); + // // child->setItemData(itemData); + // // thisPtr->appendChild(child); + // //} + + // //template typename std::enable_if::value && !std::is_base_of::value && !std::is_base_of::value, void>::type + // // operator()(const char* name, std::shared_ptr value) + // template typename std::enable_if::value && !std::is_base_of::value, void>::type + // operator()(const char* name, std::shared_ptr value) + // { + // std::shared_ptr ptr = nullptr; + // TreeItem* child = new TreeItem(ptr, thisPtr); + // QList itemData; + + // //if !std::is_base_of::value, void>::type + // //{ + // //std::stringstream ss; + // //if(value) + // // value->getStepData(ss); + // //return ss; + // //} + + // //itemData << QVariant(name) << QVariant(ss.str().data()) << QVariant(typeid(T).name()); + // itemData << QVariant(name) << QVariant("m_select") << QVariant(typeid(T).name()); + // child->setItemData(itemData); + // thisPtr->appendChild(child); + // } + + // //void operator()(const char* name, std::shared_ptr value) + // //{ + // // std::shared_ptr ptr = nullptr; + // // TreeItem* child = new TreeItem(ptr, thisPtr); + // // QList itemData; + // // itemData << QVariant(name) << QVariant("m_enum") << QVariant(value->classname()); + // // child->setItemData(itemData); + // // thisPtr->appendChild(child); + // //} + + // template typename std::enable_if::value || std::is_same::value || std::is_same::value, void>::type + // operator()(const char* name, T value) + // { + // std::shared_ptr ptr = nullptr; + // TreeItem* child = new TreeItem(ptr, thisPtr); + // QList itemData; + // itemData << QVariant(name) << QVariant(value) << QVariant(typeid(value).name()); + // child->setItemData(itemData); + // thisPtr->appendChild(child); + // } + + + // //Function operator() which covers std::shared_ptr. + // //template + // //void operator()(const char* name, std::shared_ptr &ptr) + // //{ + // //} + + // //Function operator() which covers std::vector. + // template + // void operator()(const char* name, std::vector vector) + // { + // std::shared_ptr ptr = nullptr; + // TreeItem* child = new TreeItem(ptr, thisPtr); + // QList itemData; + // itemData << QVariant(name) << QVariant("vector") << QVariant(typeid(T).name()); + // child->setItemData(itemData); + // thisPtr->appendChild(child); + + // int i = 0; + // for (T it : vector) { + // TreeItem* vectorChild = new TreeItem(ptr, child); + // QList vectorData; + // //doesn't work yet since it is of type T and that requires the parser again (rekusiver aufruf) + // //T value = it; + // // + // //auto parse = [&](auto item) { + // // visit_struct::for_each(item, parser_); + // //}; + // // + // //if(ptr && ptr.get() != nullptr) { + // // if(std::dynamic_pointer_cast(ptr)) + // // OpenInfraPlatform::IfcAlignment1x1::castToVisitableAndCall(std::dynamic_pointer_cast(ptr), parse); + // //} + // //vectorData << QVariant(i++) << QVariant(value) << QVariant(typeid(value).name()); + // vectorData << QVariant(i++) << QVariant("") << QVariant(""); + // vectorChild->setItemData(vectorData); + // child->appendChild(vectorChild); + // } + // } + + // //Function operator() which covers everything that is not an int, float/double, string, boolean, pointer or vector. + // //This function also takes enums, since alot of classes derived from IfcAlignment1x1Type have a corresponding enum class, which is derived from it. + // //template typename std::enable_if::value && !std::is_same::value, void>::type + // // operator()(const char* name, T t) + // //{ + // // + // //} + + // TreeItem* thisPtr = nullptr; + + //} parser_; + }; } } - #endif //IFCTREEITEM_H namespace oip diff --git a/UserInterface/Dialogues/IfcTreeModel.cpp b/UserInterface/Dialogues/IfcTreeModel.cpp index 216cbab7d..13d0a7b2a 100644 --- a/UserInterface/Dialogues/IfcTreeModel.cpp +++ b/UserInterface/Dialogues/IfcTreeModel.cpp @@ -25,6 +25,28 @@ #include +//template T cast(S s) +//{ +// return dynamic_cast(s); +//} +// +//OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent) +// : QAbstractItemModel(parent) +//{ +// QList rootData; +// rootData << "Title" << "Summary"; +// rootItem = new IfcTreeItem(rootData); +// +// for (auto entity : expressModel->entities) { +// IfcTreeItem* child = new IfcTreeItem(entity.second.get(), rootItem); +// QList itemData; +// itemData << QVariant(entity.first);// << QVariant(entity.second->classname()) << QVariant(""); +// child->setItemData(itemData); +// child->createChildren(); +// rootItem->appendChild(child); +// } +//} + OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent) : QAbstractItemModel(parent) { @@ -127,6 +149,7 @@ int OpenInfraPlatform::UserInterface::IfcTreeModel::rowCount(const QModelIndex & void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(const OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent) { + //ignoring tree structure for now for (auto entity : expressModel->entities) { parent->appendChild(new IfcTreeItem(entity.second.get(), parent));