initial commit

This commit is contained in:
kazu
2016-05-24 16:55:19 +02:00
commit 13a89df8d6
77 changed files with 7454 additions and 0 deletions

120
tree/MapTreeModel.h Normal file
View File

@@ -0,0 +1,120 @@
#ifndef MAPTREE_H
#define MAPTREE_H
#include <QAbstractItemModel>
#include "../mapview/model/MapModel.h"
// http://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html
class MapTreeModel : public QAbstractItemModel {
Q_OBJECT
private:
MapModel* mdl;
public:
/** ctor */
MapTreeModel(MapModel* mdl) : mdl(mdl) {
connect(mdl, SIGNAL(reset()), this, SLOT(onMapModelReset()));
}
virtual ~MapTreeModel() {;}
virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override {
MapLayer* _parent = nullptr;
if (!parent.isValid()) {
_parent = mdl->getRootLayer();
} else {
_parent = static_cast<MapLayer*>(parent.internalPointer());
}
return createIndex(row, column, _parent->getSubLayers().at(row));
}
virtual QModelIndex parent(const QModelIndex& child) const override {
MapLayer* _child = static_cast<MapLayer*>(child.internalPointer());
if (!_child) {return QModelIndex();}
return createIndex(0,0,_child->getParent());
}
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override {
// if (parent.column() > 0) {
// return 0;
// }
MapLayer* _parent = nullptr;
if (!parent.isValid()) { // root
_parent = mdl->getRootLayer();
} else { // deeper layer
_parent = static_cast<MapLayer*>(parent.internalPointer());
}
return _parent->getSubLayers().size();
}
virtual int columnCount(const QModelIndex& parent) const override {
if (!parent.isValid()) {
return 1; // root
} else {
return 1; // TODO
}
}
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override {
MapLayer* _elem = static_cast<MapLayer*>(index.internalPointer());
if (index.column() == 0) {
if (role == Qt::DisplayRole) {return _elem->getLayerName().c_str();}
if (role == Qt::CheckStateRole) {return _elem->isVisible() ? Qt::Checked : Qt::Unchecked;}
}
return QVariant();
}
Qt::ItemFlags flags(const QModelIndex &index) const override {
(void) index;
// each item is selectable, enable, and has an editable checkbox
int flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
return (Qt::ItemFlags) flags;
}
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override {
// checking / unchecking a layer (visibility)
if (role == Qt::CheckStateRole) {
MapLayer* _elem = static_cast<MapLayer*>(index.internalPointer());
_elem->setVisible( value != 0 );
return true;
}
return false;
}
public slots:
/** the underlying map-model has changed */
void onMapModelReset() {
//emit dataChanged(QModelIndex(), QModelIndex(-1));
//emit modelReset(QPrivateSignal());
endResetModel();
}
};
#endif // MAPTREE_H