22#include <QXmlStreamWriter>
31#include "aeongames/ResourceId.hpp"
32#include "aeongames/Component.hpp"
33#include "aeongames/ToString.hpp"
34#include "aeongames/StringId.hpp"
36#include "ComponentModel.h"
37#include "WorldEditor.h"
49 if ( mComponent && row <
static_cast<int> ( mComponent->GetPropertyCount() ) )
51 return createIndex ( row, column );
58 if ( mComponent && !
index.isValid() )
60 return static_cast<int> ( mComponent->GetPropertyCount() );
66 template<
typename... Types>
67 static inline QVariant fromStdVariant (
const std::variant<Types...> &value )
69#if QT_VERSION >= QT_VERSION_CHECK ( 5, 11, 0 )
70 return QVariant::fromStdVariant ( value );
72 if ( value.valueless_by_exception() )
76 return std::visit ( [] (
const auto & arg )
78 return QVariant::fromValue ( arg );
85 if ( mComponent &&
index.isValid() )
87 if ( role == Qt::EditRole || role == Qt::DisplayRole )
88 switch (
index.column() )
91 if ( role == Qt::DisplayRole )
93 return QString ( mComponent->GetPropertyInfoArray() [
index.row()].GetString() );
98 Property property{ mComponent->GetProperty ( mComponent->GetPropertyInfoArray() [
index.row()] ) };
99 if ( std::holds_alternative<std::string> ( property ) )
101 return QString::fromStdString ( std::get<std::string> ( property ) );
103 else if ( std::holds_alternative<std::filesystem::path> ( property ) )
105 return QString::fromStdString ( std::get<std::filesystem::path> ( property ).
string() );
109 return fromStdVariant ( property );
119 if ( ( role == Qt::EditRole ) && (
index.isValid() ) && ( value.isValid() ) && (
index.column() == 1 ) )
122 int user_type{value.userType() };
126 property = value.value<
int>();
128 case QMetaType::UInt:
129 property = value.value<
unsigned int>();
131 case QMetaType::Double:
132 property = value.value<
double>();
134 case QMetaType::Long:
135 property = value.value<
long>();
137 case QMetaType::LongLong:
138 property = value.value<
long long>();
140 case QMetaType::ULong:
141 property = value.value<
unsigned long>();
143 case QMetaType::ULongLong:
144 property = value.value<
unsigned long long>();
146 case QMetaType::Float:
147 property = value.value<
float>();
149 case QMetaType::QString:
150 property = value.value<QString>().toStdString();
158 mComponent->SetProperty ( mComponent->GetPropertyInfoArray() [
index.row()], property );
160 catch (
const std::runtime_error& e )
174 mComponent = aComponent;
Defines log severity levels and stream output for the AeonGames engine.
Abstract base class for node components.
virtual ~ComponentModel()
Destructor.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Return the index of the item at the given row and column under parent.
int rowCount(const QModelIndex &index=QModelIndex()) const override
Return the number of rows under the given parent.
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Set the data for the given index and role.
void SetComponent(Component *aComponent)
Set the component whose properties are represented by this model.
ComponentModel(QObject *parent=nullptr)
Construct the component model.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Return the data for the given index and role.
QModelIndex parent(const QModelIndex &index) const override
Return the parent of the given model index.
PropertyModel(QObject *parent=nullptr)
Construct the property model.
<- This is here just for the literals
std::variant< int, long, long long, unsigned, unsigned long, unsigned long long, float, double, std::string, std::filesystem::path > Property
A variant type that can hold any commonly used property value.
@ Warning
Potential issues that may need attention.