1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 15:02:34 +02: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,134 +2,115 @@
#include <data/Model.hpp>
#include <data/Skeleton.hpp>
DFFFramesTreeModel::DFFFramesTreeModel(Model *m, Skeleton* skel, QObject* parent)
: QAbstractItemModel(parent), model(m), skeleton(skel)
{
DFFFramesTreeModel::DFFFramesTreeModel(Model* m, Skeleton* skel,
QObject* parent)
: QAbstractItemModel(parent), model(m), skeleton(skel) {
}
int DFFFramesTreeModel::columnCount(const QModelIndex& parent) const
{
return 1;
int DFFFramesTreeModel::columnCount(const QModelIndex& parent) const {
return 1;
}
int DFFFramesTreeModel::rowCount(const QModelIndex& parent) const
{
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
if(f) {
return f->getChildren().size();
}
if(parent.row() == -1) {
return 1;
}
return 0;
int DFFFramesTreeModel::rowCount(const QModelIndex& parent) const {
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
if (f) {
return f->getChildren().size();
}
if (parent.row() == -1) {
return 1;
}
return 0;
}
QModelIndex DFFFramesTreeModel::index(int row, int column, const QModelIndex& parent) const
{
if(parent.row() == -1 && parent.column() == -1) {
return createIndex(row, column, model->frames[model->rootFrameIdx]);
}
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
ModelFrame* p = f->getChildren()[row];
return createIndex(row, column, p);
QModelIndex DFFFramesTreeModel::index(int row, int column,
const QModelIndex& parent) const {
if (parent.row() == -1 && parent.column() == -1) {
return createIndex(row, column, model->frames[model->rootFrameIdx]);
}
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
ModelFrame* p = f->getChildren()[row];
return createIndex(row, column, p);
}
QModelIndex DFFFramesTreeModel::parent(const QModelIndex& child) const
{
ModelFrame* c = static_cast<ModelFrame*>(child.internalPointer());
if(c->getParent()) {
auto cp = c->getParent();
if(cp->getParent()) {
for(size_t i = 0; i < cp->getParent()->getChildren().size(); ++i) {
if(cp->getParent()->getChildren()[i] == c->getParent()) {
return createIndex(i, 0, c->getParent());
}
}
}
else {
return createIndex(0,0, cp);
}
}
return QModelIndex();
QModelIndex DFFFramesTreeModel::parent(const QModelIndex& child) const {
ModelFrame* c = static_cast<ModelFrame*>(child.internalPointer());
if (c->getParent()) {
auto cp = c->getParent();
if (cp->getParent()) {
for (size_t i = 0; i < cp->getParent()->getChildren().size(); ++i) {
if (cp->getParent()->getChildren()[i] == c->getParent()) {
return createIndex(i, 0, c->getParent());
}
}
} else {
return createIndex(0, 0, cp);
}
}
return QModelIndex();
}
QVariant DFFFramesTreeModel::data(const QModelIndex& index, int role) const
{
ModelFrame* f = static_cast<ModelFrame*>(index.internalPointer());
if(role == Qt::DisplayRole) {
if(index.column() == 0) {
return QString(f->getName().c_str());
}
}
else if( role == Qt::CheckStateRole )
{
if( index.column() == 0 )
{
if( skeleton )
{
return skeleton->getData(f->getIndex()).enabled ?
Qt::Checked : Qt::Unchecked;
}
}
}
return QVariant();
QVariant DFFFramesTreeModel::data(const QModelIndex& index, int role) const {
ModelFrame* f = static_cast<ModelFrame*>(index.internalPointer());
if (role == Qt::DisplayRole) {
if (index.column() == 0) {
return QString(f->getName().c_str());
}
} else if (role == Qt::CheckStateRole) {
if (index.column() == 0) {
if (skeleton) {
return skeleton->getData(f->getIndex()).enabled ? Qt::Checked
: Qt::Unchecked;
}
}
}
return QVariant();
}
bool DFFFramesTreeModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
if(! index.isValid() )
{
return false;
}
bool DFFFramesTreeModel::setData(const QModelIndex& index,
const QVariant& value, int role) {
if (!index.isValid()) {
return false;
}
ModelFrame* f = static_cast<ModelFrame*>(index.internalPointer());
ModelFrame* f = static_cast<ModelFrame*>(index.internalPointer());
if( role == Qt::CheckStateRole )
{
if( index.column() == 0 && skeleton )
{
if( (Qt::CheckState)value.toInt() == Qt::Checked )
{
skeleton->setEnabled(f, true);
}
else
{
skeleton->setEnabled(f, false);
}
return true;
}
}
if (role == Qt::CheckStateRole) {
if (index.column() == 0 && skeleton) {
if ((Qt::CheckState)value.toInt() == Qt::Checked) {
skeleton->setEnabled(f, true);
} else {
skeleton->setEnabled(f, false);
}
return true;
}
}
return false;
return false;
}
Qt::ItemFlags DFFFramesTreeModel::flags(const QModelIndex& index) const
{
if(! index.isValid() )
{
return 0;
}
Qt::ItemFlags DFFFramesTreeModel::flags(const QModelIndex& index) const {
if (!index.isValid()) {
return 0;
}
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if( index.column() == 0 && skeleton )
{
flags |= Qt::ItemIsUserCheckable;
}
if (index.column() == 0 && skeleton) {
flags |= Qt::ItemIsUserCheckable;
}
return flags;
return flags;
}
QVariant DFFFramesTreeModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(orientation == Qt::Horizontal) {
if(role == Qt::DisplayRole) {
return "Name";
}
}
return QVariant();
QVariant DFFFramesTreeModel::headerData(int section,
Qt::Orientation orientation,
int role) const {
if (orientation == Qt::Horizontal) {
if (role == Qt::DisplayRole) {
return "Name";
}
}
return QVariant();
}

View File

@ -7,29 +7,32 @@
class Model;
class Skeleton;
class DFFFramesTreeModel : public QAbstractItemModel
{
Model* model;
Skeleton* skeleton;
class DFFFramesTreeModel : public QAbstractItemModel {
Model* model;
Skeleton* skeleton;
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 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 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

View File

@ -1,89 +1,73 @@
#include "ObjectListModel.hpp"
ObjectListModel::ObjectListModel(GameData *dat, QObject *parent) :
QAbstractTableModel(parent), _gameData( dat )
{
ObjectListModel::ObjectListModel(GameData *dat, QObject *parent)
: QAbstractTableModel(parent), _gameData(dat) {
}
int ObjectListModel::rowCount(const QModelIndex &parent) const
{
return _gameData->objectTypes.size();
int ObjectListModel::rowCount(const QModelIndex &parent) const {
return _gameData->objectTypes.size();
}
int ObjectListModel::columnCount(const QModelIndex &parent) const
{
return 3;
int ObjectListModel::columnCount(const QModelIndex &parent) const {
return 3;
}
static std::map<ObjectInformation::ObjectClass, QString> gDataType =
{
{ ObjectInformation::_class("OBJS"), "Object" },
{ ObjectInformation::_class("CARS"), "Vehicle" },
{ ObjectInformation::_class("PEDS"), "Pedestrian" },
{ ObjectInformation::_class("HIER"), "Cutscene" }
};
static std::map<ObjectInformation::ObjectClass, QString> gDataType = {
{ObjectInformation::_class("OBJS"), "Object"},
{ObjectInformation::_class("CARS"), "Vehicle"},
{ObjectInformation::_class("PEDS"), "Pedestrian"},
{ObjectInformation::_class("HIER"), "Cutscene"}};
QVariant ObjectListModel::data(const QModelIndex &index, int role) const
{
if ( role == Qt::DisplayRole ) {
auto id = index.internalId();
if( id == -1 ) return QVariant::Invalid;
if( index.column() == 0 )
{
return id;
}
else if ( index.column() == 1 )
{
auto object = _gameData->objectTypes[id];
if( gDataType[object->class_type].isEmpty() )
{
return QString("Unknown");
}
return gDataType[object->class_type];
}
else if( index.column() == 2 )
{
auto object = _gameData->objectTypes[id];
if(object->class_type == ObjectData::class_id)
{
auto v = std::static_pointer_cast<ObjectData>(object);
return QString::fromStdString(v->modelName);
}
else if(object->class_type == VehicleData::class_id)
{
auto v = std::static_pointer_cast<VehicleData>(object);
return QString::fromStdString(v->modelName);
}
else if(object->class_type == CharacterData::class_id)
{
auto v = std::static_pointer_cast<CharacterData>(object);
return QString::fromStdString(v->modelName);
}
}
}
return QVariant::Invalid;
QVariant ObjectListModel::data(const QModelIndex &index, int role) const {
if (role == Qt::DisplayRole) {
auto id = index.internalId();
if (id == -1) return QVariant::Invalid;
if (index.column() == 0) {
return id;
} else if (index.column() == 1) {
auto object = _gameData->objectTypes[id];
if (gDataType[object->class_type].isEmpty()) {
return QString("Unknown");
}
return gDataType[object->class_type];
} else if (index.column() == 2) {
auto object = _gameData->objectTypes[id];
if (object->class_type == ObjectData::class_id) {
auto v = std::static_pointer_cast<ObjectData>(object);
return QString::fromStdString(v->modelName);
} else if (object->class_type == VehicleData::class_id) {
auto v = std::static_pointer_cast<VehicleData>(object);
return QString::fromStdString(v->modelName);
} else if (object->class_type == CharacterData::class_id) {
auto v = std::static_pointer_cast<CharacterData>(object);
return QString::fromStdString(v->modelName);
}
}
}
return QVariant::Invalid;
}
QVariant ObjectListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) {
switch(section) {
case 0:
return "ID";
case 1:
return "Type";
case 2:
return "Model";
}
}
return QVariant::Invalid;
QVariant ObjectListModel::headerData(int section, Qt::Orientation orientation,
int role) const {
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
switch (section) {
case 0:
return "ID";
case 1:
return "Type";
case 2:
return "Model";
}
}
return QVariant::Invalid;
}
QModelIndex ObjectListModel::index(int row, int column, const QModelIndex &parent) const
{
auto it = _gameData->objectTypes.begin();
for(int i = 0; i < row; i++) it++;
auto id = it->second->ID;
QModelIndex ObjectListModel::index(int row, int column,
const QModelIndex &parent) const {
auto it = _gameData->objectTypes.begin();
for (int i = 0; i < row; i++) it++;
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>
class ObjectListModel : public QAbstractTableModel
{
Q_OBJECT
class ObjectListModel : public QAbstractTableModel {
Q_OBJECT
GameData* _gameData;
GameData* _gameData;
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_