1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 10:22:52 +01:00
openrw/rwviewer/models/DFFFramesTreeModel.cpp
2018-09-16 00:52:41 +02:00

110 lines
3.1 KiB
C++

#include "DFFFramesTreeModel.hpp"
#include <data/Clump.hpp>
DFFFramesTreeModel::DFFFramesTreeModel(ClumpPtr m,
QObject* parent)
: QAbstractItemModel(parent), model(m) {
}
int DFFFramesTreeModel::columnCount(const QModelIndex&) const {
return 1;
}
int DFFFramesTreeModel::rowCount(const QModelIndex& parent) const {
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
if (f) {
return static_cast<int>(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->getFrame().get());
}
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
ModelFrame* p = f->getChildren()[row].get();
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].get() == c->getParent()) {
return createIndex(static_cast<int>(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) {
return true;
}
}
return QVariant();
}
bool DFFFramesTreeModel::setData(const QModelIndex& index,
const QVariant& value, int role) {
if (!index.isValid()) {
return false;
}
if (role == Qt::CheckStateRole) {
if (index.column() == 0) {
if (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked) {
RW_UNIMPLEMENTED("Hiding Frames");
} else {
}
return true;
}
}
return false;
}
Qt::ItemFlags DFFFramesTreeModel::flags(const QModelIndex& index) const {
if (!index.isValid()) {
return 0;
}
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if (index.column() == 0) {
flags |= Qt::ItemIsUserCheckable;
}
return flags;
}
QVariant DFFFramesTreeModel::headerData(int,
Qt::Orientation orientation,
int role) const {
if (orientation == Qt::Horizontal) {
if (role == Qt::DisplayRole) {
return "Name";
}
}
return QVariant();
}