1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-09 12:22:34 +01:00

clang-format files in rwviewer/models

This commit is contained in:
Daniel Evans 2016-09-09 21:13:21 +01:00
parent d1c33af268
commit 4ca99c380a
4 changed files with 180 additions and 209 deletions

View File

@ -2,34 +2,31 @@
#include <data/Model.hpp> #include <data/Model.hpp>
#include <data/Skeleton.hpp> #include <data/Skeleton.hpp>
DFFFramesTreeModel::DFFFramesTreeModel(Model *m, Skeleton* skel, QObject* parent) DFFFramesTreeModel::DFFFramesTreeModel(Model* m, Skeleton* skel,
: QAbstractItemModel(parent), model(m), skeleton(skel) QObject* parent)
{ : QAbstractItemModel(parent), model(m), skeleton(skel) {
} }
int DFFFramesTreeModel::columnCount(const QModelIndex& parent) const int DFFFramesTreeModel::columnCount(const QModelIndex& parent) const {
{
return 1; return 1;
} }
int DFFFramesTreeModel::rowCount(const QModelIndex& parent) const int DFFFramesTreeModel::rowCount(const QModelIndex& parent) const {
{
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer()); ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
if(f) { if (f) {
return f->getChildren().size(); return f->getChildren().size();
} }
if(parent.row() == -1) { if (parent.row() == -1) {
return 1; return 1;
} }
return 0; return 0;
} }
QModelIndex DFFFramesTreeModel::index(int row, int column, const QModelIndex& parent) const QModelIndex DFFFramesTreeModel::index(int row, int column,
{ const QModelIndex& parent) const {
if(parent.row() == -1 && parent.column() == -1) { if (parent.row() == -1 && parent.column() == -1) {
return createIndex(row, column, model->frames[model->rootFrameIdx]); return createIndex(row, column, model->frames[model->rootFrameIdx]);
} }
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer()); ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
@ -37,66 +34,53 @@ QModelIndex DFFFramesTreeModel::index(int row, int column, const QModelIndex& pa
return createIndex(row, column, p); return createIndex(row, column, p);
} }
QModelIndex DFFFramesTreeModel::parent(const QModelIndex& child) const QModelIndex DFFFramesTreeModel::parent(const QModelIndex& child) const {
{
ModelFrame* c = static_cast<ModelFrame*>(child.internalPointer()); ModelFrame* c = static_cast<ModelFrame*>(child.internalPointer());
if(c->getParent()) { if (c->getParent()) {
auto cp = c->getParent(); auto cp = c->getParent();
if(cp->getParent()) { if (cp->getParent()) {
for(size_t i = 0; i < cp->getParent()->getChildren().size(); ++i) { for (size_t i = 0; i < cp->getParent()->getChildren().size(); ++i) {
if(cp->getParent()->getChildren()[i] == c->getParent()) { if (cp->getParent()->getChildren()[i] == c->getParent()) {
return createIndex(i, 0, c->getParent()); return createIndex(i, 0, c->getParent());
} }
} }
} } else {
else { return createIndex(0, 0, cp);
return createIndex(0,0, cp);
} }
} }
return QModelIndex(); return QModelIndex();
} }
QVariant DFFFramesTreeModel::data(const QModelIndex& index, int role) const QVariant DFFFramesTreeModel::data(const QModelIndex& index, int role) const {
{
ModelFrame* f = static_cast<ModelFrame*>(index.internalPointer()); ModelFrame* f = static_cast<ModelFrame*>(index.internalPointer());
if(role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
if(index.column() == 0) { if (index.column() == 0) {
return QString(f->getName().c_str()); return QString(f->getName().c_str());
} }
} } else if (role == Qt::CheckStateRole) {
else if( role == Qt::CheckStateRole ) if (index.column() == 0) {
{ if (skeleton) {
if( index.column() == 0 ) return skeleton->getData(f->getIndex()).enabled ? Qt::Checked
{ : Qt::Unchecked;
if( skeleton )
{
return skeleton->getData(f->getIndex()).enabled ?
Qt::Checked : Qt::Unchecked;
} }
} }
} }
return QVariant(); return QVariant();
} }
bool DFFFramesTreeModel::setData(const QModelIndex& index, const QVariant& value, int role) bool DFFFramesTreeModel::setData(const QModelIndex& index,
{ const QVariant& value, int role) {
if(! index.isValid() ) if (!index.isValid()) {
{
return false; return false;
} }
ModelFrame* f = static_cast<ModelFrame*>(index.internalPointer()); ModelFrame* f = static_cast<ModelFrame*>(index.internalPointer());
if( role == Qt::CheckStateRole ) if (role == Qt::CheckStateRole) {
{ if (index.column() == 0 && skeleton) {
if( index.column() == 0 && skeleton ) if ((Qt::CheckState)value.toInt() == Qt::Checked) {
{
if( (Qt::CheckState)value.toInt() == Qt::Checked )
{
skeleton->setEnabled(f, true); skeleton->setEnabled(f, true);
} } else {
else
{
skeleton->setEnabled(f, false); skeleton->setEnabled(f, false);
} }
return true; return true;
@ -106,30 +90,27 @@ bool DFFFramesTreeModel::setData(const QModelIndex& index, const QVariant& value
return false; return false;
} }
Qt::ItemFlags DFFFramesTreeModel::flags(const QModelIndex& index) const Qt::ItemFlags DFFFramesTreeModel::flags(const QModelIndex& index) const {
{ if (!index.isValid()) {
if(! index.isValid() )
{
return 0; return 0;
} }
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable; Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if( index.column() == 0 && skeleton ) if (index.column() == 0 && skeleton) {
{
flags |= Qt::ItemIsUserCheckable; flags |= Qt::ItemIsUserCheckable;
} }
return flags; return flags;
} }
QVariant DFFFramesTreeModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant DFFFramesTreeModel::headerData(int section,
{ Qt::Orientation orientation,
if(orientation == Qt::Horizontal) { int role) const {
if(role == Qt::DisplayRole) { if (orientation == Qt::Horizontal) {
if (role == Qt::DisplayRole) {
return "Name"; return "Name";
} }
} }
return QVariant(); return QVariant();
} }

View File

@ -7,29 +7,32 @@
class Model; class Model;
class Skeleton; class Skeleton;
class DFFFramesTreeModel : public QAbstractItemModel class DFFFramesTreeModel : public QAbstractItemModel {
{
Model* model; Model* model;
Skeleton* skeleton; Skeleton* skeleton;
public:
public:
explicit DFFFramesTreeModel(Model* m, Skeleton* skel, QObject* parent = 0); explicit DFFFramesTreeModel(Model* m, Skeleton* skel, QObject* parent = 0);
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const;
virtual bool setData(const QModelIndex& index, const QVariant& value, int role); virtual bool setData(const QModelIndex& index, const QVariant& value,
int role);
virtual Qt::ItemFlags flags(const QModelIndex& index) const; virtual Qt::ItemFlags flags(const QModelIndex& index) const;
virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; virtual QModelIndex index(int row, int column,
const QModelIndex& parent = QModelIndex()) const;
virtual QModelIndex parent(const QModelIndex& child) const; virtual QModelIndex parent(const QModelIndex& child) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
}; };
#endif #endif

View File

@ -1,61 +1,44 @@
#include "ObjectListModel.hpp" #include "ObjectListModel.hpp"
ObjectListModel::ObjectListModel(GameData *dat, QObject *parent) : ObjectListModel::ObjectListModel(GameData *dat, QObject *parent)
QAbstractTableModel(parent), _gameData( dat ) : QAbstractTableModel(parent), _gameData(dat) {
{
} }
int ObjectListModel::rowCount(const QModelIndex &parent) const int ObjectListModel::rowCount(const QModelIndex &parent) const {
{
return _gameData->objectTypes.size(); return _gameData->objectTypes.size();
} }
int ObjectListModel::columnCount(const QModelIndex &parent) const int ObjectListModel::columnCount(const QModelIndex &parent) const {
{
return 3; return 3;
} }
static std::map<ObjectInformation::ObjectClass, QString> gDataType = static std::map<ObjectInformation::ObjectClass, QString> gDataType = {
{ {ObjectInformation::_class("OBJS"), "Object"},
{ ObjectInformation::_class("OBJS"), "Object" }, {ObjectInformation::_class("CARS"), "Vehicle"},
{ ObjectInformation::_class("CARS"), "Vehicle" }, {ObjectInformation::_class("PEDS"), "Pedestrian"},
{ ObjectInformation::_class("PEDS"), "Pedestrian" }, {ObjectInformation::_class("HIER"), "Cutscene"}};
{ ObjectInformation::_class("HIER"), "Cutscene" }
};
QVariant ObjectListModel::data(const QModelIndex &index, int role) const QVariant ObjectListModel::data(const QModelIndex &index, int role) const {
{ if (role == Qt::DisplayRole) {
if ( role == Qt::DisplayRole ) {
auto id = index.internalId(); auto id = index.internalId();
if( id == -1 ) return QVariant::Invalid; if (id == -1) return QVariant::Invalid;
if( index.column() == 0 ) if (index.column() == 0) {
{
return id; return id;
} } else if (index.column() == 1) {
else if ( index.column() == 1 )
{
auto object = _gameData->objectTypes[id]; auto object = _gameData->objectTypes[id];
if( gDataType[object->class_type].isEmpty() ) if (gDataType[object->class_type].isEmpty()) {
{
return QString("Unknown"); return QString("Unknown");
} }
return gDataType[object->class_type]; return gDataType[object->class_type];
} } else if (index.column() == 2) {
else if( index.column() == 2 )
{
auto object = _gameData->objectTypes[id]; auto object = _gameData->objectTypes[id];
if(object->class_type == ObjectData::class_id) if (object->class_type == ObjectData::class_id) {
{
auto v = std::static_pointer_cast<ObjectData>(object); auto v = std::static_pointer_cast<ObjectData>(object);
return QString::fromStdString(v->modelName); return QString::fromStdString(v->modelName);
} } else if (object->class_type == VehicleData::class_id) {
else if(object->class_type == VehicleData::class_id)
{
auto v = std::static_pointer_cast<VehicleData>(object); auto v = std::static_pointer_cast<VehicleData>(object);
return QString::fromStdString(v->modelName); return QString::fromStdString(v->modelName);
} } else if (object->class_type == CharacterData::class_id) {
else if(object->class_type == CharacterData::class_id)
{
auto v = std::static_pointer_cast<CharacterData>(object); auto v = std::static_pointer_cast<CharacterData>(object);
return QString::fromStdString(v->modelName); return QString::fromStdString(v->modelName);
} }
@ -64,10 +47,10 @@ QVariant ObjectListModel::data(const QModelIndex &index, int role) const
return QVariant::Invalid; return QVariant::Invalid;
} }
QVariant ObjectListModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant ObjectListModel::headerData(int section, Qt::Orientation orientation,
{ int role) const {
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
switch(section) { switch (section) {
case 0: case 0:
return "ID"; return "ID";
case 1: case 1:
@ -79,11 +62,12 @@ QVariant ObjectListModel::headerData(int section, Qt::Orientation orientation, i
return QVariant::Invalid; return QVariant::Invalid;
} }
QModelIndex ObjectListModel::index(int row, int column, const QModelIndex &parent) const QModelIndex ObjectListModel::index(int row, int column,
{ const QModelIndex &parent) const {
auto it = _gameData->objectTypes.begin(); auto it = _gameData->objectTypes.begin();
for(int i = 0; i < row; i++) it++; for (int i = 0; i < row; i++) it++;
auto id = it->second->ID; auto id = it->second->ID;
return hasIndex(row, column, parent) ? createIndex(row, column, id) : QModelIndex(); return hasIndex(row, column, parent) ? createIndex(row, column, id)
: QModelIndex();
} }

View File

@ -5,26 +5,29 @@
#include <engine/GameData.hpp> #include <engine/GameData.hpp>
class ObjectListModel : public QAbstractTableModel class ObjectListModel : public QAbstractTableModel {
{
Q_OBJECT Q_OBJECT
GameData* _gameData; GameData* _gameData;
public: public:
explicit ObjectListModel(GameData* gameDat, QObject *parent = 0); explicit ObjectListModel(GameData* gameDat, QObject* parent = 0);
GameData* gameData() const { return _gameData; } GameData* gameData() const {
return _gameData;
}
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent) const; QModelIndex index(int row, int column, const QModelIndex& parent) const;
}; };
#endif // _OBJECTLISTMODEL_HPP_ #endif // _OBJECTLISTMODEL_HPP_