Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Editing SimpleTreeModel and SimpleTreeItem #208

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions UserInterface/Dialogues/Ifc4x1TreeItem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
Copyright (c) 2018 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 <http://www.gnu.org/licenses/>.
*/

#include <QStringList>
#include <type_traits>
#include <cstdlib>

#include "Ifc4x1TreeItem.h"
#include "Ifc4x1TreeModel.h"
#include "OpenInfraPlatform/Infrastructure/Export/IfcAlignment1x1Caster.h"

#include <BlueFramework\Core\Exception.h>
#include <BlueFramework\Core\memory.h>



OpenInfraPlatform::UserInterface::Ifc4x1TreeItem::Ifc4x1TreeItem(std::pair<int, std::shared_ptr<OpenInfraPlatform::IfcAlignment1x1::IfcAlignment1x1Entity>> data, std::shared_ptr<Ifc4x1TreeItem> parentItem)
{
parentItem_ = parentItem;
data_ = data;
//auto attributes = getAttributeDescription();
//auto entity = data_.find(parent.row() + 1)->second;
//OpenInfraPlatform::IfcAlignment1x1::castAndCall(entity, attributes);
//hier cast and call verwenden und den getattributedesciption struct �bergeben
}

struct OpenInfraPlatform::UserInterface::Ifc4x1TreeItem::getAttributeDescription {

template <class T> typename std::enable_if<visit_struct::traits::is_visitable<T>::value && std::is_base_of<OpenInfraPlatform::IfcAlignment1x1::IfcAlignment1x1Entity, T>::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 <class T> typename std::enable_if<!std::is_base_of<OpenInfraPlatform::IfcAlignment1x1::IfcAlignment1x1Entity, T>::value, void>::type
operator()(T& entity) const
{
std::string message = "Invalid function call. " + std::string(typeid(entity).name()) + " isn't a member of IfcAlignment1x1Entity.";
throw buw::Exception(message.data());
}

//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::IfcAlignment1x1::IfcAlignment1x1Entity& entity) const
{
std::string message = "Invalid function call.";
throw buw::Exception(message.data());
}

std::vector<const char*> names_;
std::vector<const char*> typename_;
std::vector <QVariant> value_;

};



OpenInfraPlatform::UserInterface::Ifc4x1TreeItem::~Ifc4x1TreeItem()
{
childItems_.clear();
}

void OpenInfraPlatform::UserInterface::Ifc4x1TreeItem::appendChild(std::shared_ptr<Ifc4x1TreeItem> item)
{
childItems_.append(item);
}

std::shared_ptr<OpenInfraPlatform::UserInterface::Ifc4x1TreeItem> OpenInfraPlatform::UserInterface::Ifc4x1TreeItem::child(int row)
{
return childItems_.value(row);
}

int OpenInfraPlatform::UserInterface::Ifc4x1TreeItem::childCount() const
{
return childItems_.count();
}

int OpenInfraPlatform::UserInterface::Ifc4x1TreeItem::columnCount() const
{
return 3;
}

QVariant OpenInfraPlatform::UserInterface::Ifc4x1TreeItem::data(int column, int row) const
{
auto attributes = getAttributeDescription();

switch (column)
{
case 0:
return attributes.names_[row];
break;
case 1:
return attributes.value_[row];//data_.value(column);//value of the object
break;
case 2:
return attributes.typename_[row];//type of the object
break;
}

}

std::shared_ptr<OpenInfraPlatform::UserInterface::Ifc4x1TreeItem> OpenInfraPlatform::UserInterface::Ifc4x1TreeItem::parentItem()
{
if (parentItem_)
return parentItem_;

return std::shared_ptr<OpenInfraPlatform::UserInterface::Ifc4x1TreeItem>();
}

std::string OpenInfraPlatform::UserInterface::Ifc4x1TreeItem::getIfcClassName()
{
return std::string(data_.second->classname());
}


int OpenInfraPlatform::UserInterface::Ifc4x1TreeItem::row() const
{
// if (parentItem_)
// return parentItem_->childItems_.indexOf(const_cast<shared_ptr<Ifc4x1TreeItem>>(this));

return 0;
}
61 changes: 61 additions & 0 deletions UserInterface/Dialogues/Ifc4x1TreeItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright (c) 2018 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 <http://www.gnu.org/licenses/>.
*/

#ifndef Ifc4X1TREEITEM_H
#define Ifc4X1TREEITEM_H

#include <QList>
#include <QVariant>
#include "OpenInfraPlatform/IfcAlignment1x1/model/Object.h"
#include "OpenInfraPlatform\IfcAlignment1x1\model\Model.h"


namespace OpenInfraPlatform {
namespace UserInterface {

class Ifc4x1TreeItem
{
public:
explicit Ifc4x1TreeItem(std::pair<int, shared_ptr<OpenInfraPlatform::IfcAlignment1x1::IfcAlignment1x1Entity> > data, std::shared_ptr<Ifc4x1TreeItem> parentItem = nullptr);
~Ifc4x1TreeItem();

void appendChild(shared_ptr<Ifc4x1TreeItem> child);

shared_ptr<Ifc4x1TreeItem> child(int row);
int childCount() const;
int columnCount() const;
QVariant data(int column, int row) const;
int row() const;
shared_ptr<Ifc4x1TreeItem> parentItem();
std::string getIfcClassName();

private:
QList<shared_ptr<Ifc4x1TreeItem>> childItems_;
std::pair<int, shared_ptr<OpenInfraPlatform::IfcAlignment1x1::IfcAlignment1x1Entity> > data_;
shared_ptr<Ifc4x1TreeItem> parentItem_;

struct getAttributeDescription;
};

}
}
#endif // TREEITEM_H

namespace buw
{
using OpenInfraPlatform::UserInterface::Ifc4x1TreeItem;
}
144 changes: 144 additions & 0 deletions UserInterface/Dialogues/Ifc4x1TreeModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
Copyright (c) 2018 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 <http://www.gnu.org/licenses/>.
*/

#include "Ifc4x1TreeModel.h"
#include "OpenInfraPlatform/Infrastructure/Export/IfcAlignment1x1Caster.h"
#include "Ifc4x1TreeItem.h"

#include <BlueFramework\Core\Exception.h>
#include <BlueFramework\Core\memory.h>


#include <type_traits>
#include <cstdlib>
#include <QStringList>

OpenInfraPlatform::UserInterface::Ifc4x1TreeModel::Ifc4x1TreeModel(std::map<int, shared_ptr<OpenInfraPlatform::IfcAlignment1x1::IfcAlignment1x1Entity>>& entities)
:
QAbstractItemModel()
{
for (auto it : entities) {
shared_ptr<Ifc4x1TreeItem> item = std::make_shared<Ifc4x1TreeItem>(it);
data_.push_back(item);

}
}

OpenInfraPlatform::UserInterface::Ifc4x1TreeModel::~Ifc4x1TreeModel()
{
data_.clear();
}

QModelIndex OpenInfraPlatform::UserInterface::Ifc4x1TreeModel::index(int row, int column, const QModelIndex & parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();

if (!parent.isValid())
return this->createIndex(row, column, nullptr);
else {
return this->createIndex(row, column, nullptr);

}

//from Qt documentation

shared_ptr<Ifc4x1TreeItem> parentItem;
if (!parent.isValid())
parentItem = nullptr;
//else
// parentItem = static_cast<shared_ptr<Ifc4x1TreeItem>>(parent.internalPointer());

shared_ptr<Ifc4x1TreeItem> childItem = parentItem->child(row);
//if (childItem)
//return createIndex(row, column, childItem);
//else
return QModelIndex();
}


QModelIndex OpenInfraPlatform::UserInterface::Ifc4x1TreeModel::parent(const QModelIndex & child) const
{
if(child.internalPointer() != nullptr) {
return this->createIndex(0, 0, nullptr);
}
else {
return QModelIndex();
}

//from Qt documentation
//shared_ptr<Ifc4x1TreeItem> childItem = static_cast<shared_ptr<Ifc4x1TreeItem>>(child.internalPointer());
//shared_ptr<Ifc4x1TreeItem> parentItem = childItem->parentItem();

//if (parentItem==nullptr)
// return QModelIndex();

// return createIndex(parentItem->row(), 0, parentItem);
}


//int OpenInfraPlatform::UserInterface::Ifc4x1TreeModel::rowCount(const QModelIndex & parent) const
//{
// if (!parent.isValid())
// return data_.size();
// else {
// auto entity = data_.find(parent.row() + 1)->second;
// auto counter = countRows {};
// OpenInfraPlatform::IfcAlignment1x1::castToDerivedAndCall<countRows, void>(entity, counter);
// return counter.rows_;
// }
//
// //Menge der Attribute des Objekts data_.size(index) oder data_[parent].size()?oder mit visit struct?
// //w�rde das hier auch mit childCount() gehen?
//}


int OpenInfraPlatform::UserInterface::Ifc4x1TreeModel::columnCount(const QModelIndex & parent) const
{
if (!parent.isValid())
return 1;
else
return 3;
}


//QVariant OpenInfraPlatform::UserInterface::Ifc4x1TreeModel::data(const QModelIndex & index, int role) const
//{
// if (!index.isValid())
// return QVariant();
//
// if (role != Qt::DisplayRole)
// return QVariant();
//
// if (!index.parent().isValid())
// return QVariant(data_[index.row()]->getIfcClassName().data());
// else {
//
// auto ptr = std::static_pointer_cast<OpenInfraPlatform::IfcAlignment1x1::IfcAlignment1x1Entity>(buw::claimOwnership(index.internalPointer()));
// auto name = getName();
// OpenInfraPlatform::IfcAlignment1x1::castToDerivedAndCall<getName, void>(ptr, name);
// return QVariant(name.names_[index.row()]);
// }
//}

bool OpenInfraPlatform::UserInterface::Ifc4x1TreeModel::insertRows(int row, int count, const QModelIndex & parent)
{
beginInsertRows(parent, row, row + count);

endInsertRows();
return true;
}
Loading