2014-02-12 07:42:07 +01:00
|
|
|
#include "DFFFramesTreeModel.hpp"
|
2017-01-03 15:18:06 +01:00
|
|
|
#include <data/Clump.hpp>
|
2014-02-12 07:42:07 +01:00
|
|
|
|
rwlib: Use ClumpPtr instead of Clump*
Should fix these memory leaks:
==22737== 14,598,040 (131,472 direct, 14,466,568 indirect) bytes in 2,739 blocks are definitely lost in loss record 3,124 of 3,126
==22737== at 0x4C2F1CA: operator new(unsigned long) (vg_replace_malloc.c:334)
==22737== by 0x90FE4B: LoaderDFF::loadFromMemory(std::shared_ptr<FileContentsInfo>) (LoaderDFF.cpp:443)
==22737== by 0x7BCC86: GameData::loadModel(unsigned short) (GameData.cpp:474)
==22737== by 0x7DF7BC: GameWorld::createInstance(unsigned short, glm::tvec3<float, (glm::precision)0> const&, glm::tquat<float, (glm::precision)0> const&) (GameWorld.cpp:144)
==22737== by 0x7DF44C: GameWorld::placeItems(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (GameWorld.cpp:120)
==22737== by 0x758D38: RWGame::newGame() (RWGame.cpp:116)
==22737== by 0x786389: LoadingState::enter() (LoadingState.cpp:9)
==22737== by 0x75DC59: void StateManager::enter<LoadingState, RWGame*, RWGame::RWGame(Logger&, int, char**)::{lambda()#1}>(RWGame*&&, RWGame::RWGame(Logger&, int, char**)::{lambda()#1}&&) (StateManager.hpp:40)
==22737== by 0x758484: RWGame::RWGame(Logger&, int, char**) (RWGame.cpp:81)
==22737== by 0x747815: main (main.cpp:13)
2017-09-13 00:47:22 +02:00
|
|
|
DFFFramesTreeModel::DFFFramesTreeModel(ClumpPtr m,
|
2016-09-09 22:13:21 +02:00
|
|
|
QObject* parent)
|
2017-01-08 20:46:00 +01:00
|
|
|
: QAbstractItemModel(parent), model(m) {
|
2014-02-12 07:42:07 +01:00
|
|
|
}
|
|
|
|
|
2017-10-27 17:38:36 +02:00
|
|
|
int DFFFramesTreeModel::columnCount(const QModelIndex&) const {
|
2016-09-09 22:13:21 +02:00
|
|
|
return 1;
|
2014-02-12 07:42:07 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
int DFFFramesTreeModel::rowCount(const QModelIndex& parent) const {
|
|
|
|
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
|
|
|
|
if (f) {
|
2018-08-30 02:19:38 +02:00
|
|
|
return static_cast<int>(f->getChildren().size());
|
2016-09-09 22:13:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parent.row() == -1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-02-12 07:42:07 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
QModelIndex DFFFramesTreeModel::index(int row, int column,
|
|
|
|
const QModelIndex& parent) const {
|
|
|
|
if (parent.row() == -1 && parent.column() == -1) {
|
2017-01-08 21:43:18 +01:00
|
|
|
return createIndex(row, column, model->getFrame().get());
|
2016-09-09 22:13:21 +02:00
|
|
|
}
|
|
|
|
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
|
2017-01-08 21:43:18 +01:00
|
|
|
ModelFrame* p = f->getChildren()[row].get();
|
2016-09-09 22:13:21 +02:00
|
|
|
return createIndex(row, column, p);
|
2014-02-12 07:42:07 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
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) {
|
2017-01-08 21:43:18 +01:00
|
|
|
if (cp->getParent()->getChildren()[i].get() == c->getParent()) {
|
2018-08-30 02:19:38 +02:00
|
|
|
return createIndex(static_cast<int>(i), 0, c->getParent());
|
2016-09-09 22:13:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return createIndex(0, 0, cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QModelIndex();
|
2014-02-12 07:42:07 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
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) {
|
2017-01-08 20:46:00 +01:00
|
|
|
return true;
|
2016-09-09 22:13:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
2014-02-12 07:42:07 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
bool DFFFramesTreeModel::setData(const QModelIndex& index,
|
|
|
|
const QVariant& value, int role) {
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (role == Qt::CheckStateRole) {
|
2017-01-08 20:46:00 +01:00
|
|
|
if (index.column() == 0) {
|
2018-07-27 22:53:35 +02:00
|
|
|
if (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked) {
|
2017-01-08 20:46:00 +01:00
|
|
|
RW_UNIMPLEMENTED("Hiding Frames");
|
2016-09-09 22:13:21 +02:00
|
|
|
} else {
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-04-14 02:06:50 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
Qt::ItemFlags DFFFramesTreeModel::flags(const QModelIndex& index) const {
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-04-14 02:06:50 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
2015-04-14 02:06:50 +02:00
|
|
|
|
2017-01-08 20:46:00 +01:00
|
|
|
if (index.column() == 0) {
|
2016-09-09 22:13:21 +02:00
|
|
|
flags |= Qt::ItemIsUserCheckable;
|
|
|
|
}
|
2015-04-14 02:06:50 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
return flags;
|
2015-04-14 02:06:50 +02:00
|
|
|
}
|
|
|
|
|
2017-10-27 17:38:36 +02:00
|
|
|
QVariant DFFFramesTreeModel::headerData(int,
|
2016-09-09 22:13:21 +02:00
|
|
|
Qt::Orientation orientation,
|
|
|
|
int role) const {
|
|
|
|
if (orientation == Qt::Horizontal) {
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
return "Name";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
2014-02-12 07:42:07 +01:00
|
|
|
}
|