summaryrefslogtreecommitdiff
path: root/tikzit/graphelementdata.cpp
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2017-01-20 11:05:36 +0100
committerAleks Kissinger <aleks0@gmail.com>2017-01-20 11:05:36 +0100
commit36ccd03c70c305e155e00e663da725546f8f2fd9 (patch)
treeb50684a657657f00acb613cbedf6289db0f59525 /tikzit/graphelementdata.cpp
parent716aadc00c1a03e43c246a72be4758fcdf809fe0 (diff)
added GraphElementProperty
Diffstat (limited to 'tikzit/graphelementdata.cpp')
-rw-r--r--tikzit/graphelementdata.cpp110
1 files changed, 104 insertions, 6 deletions
diff --git a/tikzit/graphelementdata.cpp b/tikzit/graphelementdata.cpp
index 7240ea8..04c7760 100644
--- a/tikzit/graphelementdata.cpp
+++ b/tikzit/graphelementdata.cpp
@@ -1,37 +1,135 @@
#include "graphelementdata.h"
-GraphElementData::GraphElementData(QObject *parent) : QObject(parent)
+#include <QDebug>
+
+GraphElementData::GraphElementData(QObject *parent) : QAbstractItemModel(parent)
{
+ root = new GraphElementProperty();
+}
+GraphElementData::~GraphElementData()
+{
+ delete root;
}
void GraphElementData::setProperty(QString key, QString value)
{
-
+ GraphElementProperty m(key, true);
+ int i = _properties.indexOf(m);
+ if (i != -1) {
+ _properties[i].setValue(value);
+ } else {
+ GraphElementProperty p(key, value);
+ _properties << p;
+ }
}
void GraphElementData::unsetProperty(QString key)
{
-
+ GraphElementProperty m(key, true);
+ int i = _properties.indexOf(m);
+ if (i != -1)
+ _properties.remove(i);
}
void GraphElementData::setAtom(QString atom)
{
-
+ GraphElementProperty a(atom);
+ int i = _properties.indexOf(a);
+ if (i == -1)
+ _properties << a;
}
void GraphElementData::unsetAtom(QString atom)
{
-
+ GraphElementProperty a(atom);
+ int i = _properties.indexOf(a);
+ if (i != -1)
+ _properties.remove(i);
}
QString GraphElementData::property(QString key)
{
+ GraphElementProperty m(key, true);
+ int i = _properties.indexOf(m);
+ if (i != -1) {
+ return _properties[i].value();
+ } else {
+ return 0;
+ }
+}
+
+bool GraphElementData::atom(QString atom)
+{
+ GraphElementProperty a(atom);
+ return (_properties.indexOf(a) != -1);
+}
+
+QVariant GraphElementData::data(const QModelIndex &index, int role) const
+{
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ if (index.row() >= 0 && index.row() < _properties.length()) {
+ const GraphElementProperty &p = _properties[index.row()];
+ QString s = (index.column() == 0) ? p.key() : p.value();
+ return QVariant(s);
+ }
+}
+
+QVariant GraphElementData::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
+ if (section == 0) return QVariant("Key/Atom");
+ else return QVariant("Value");
+ }
+ return QVariant();
}
-QString GraphElementData::atom(QString atom)
+QModelIndex GraphElementData::index(int row, int column, const QModelIndex &parent) const
{
+ return createIndex(row, column, (void*)0);
+}
+QModelIndex GraphElementData::parent(const QModelIndex &index) const
+{
+ GraphElementProperty *p = static_cast<GraphElementProperty*>(index.internalPointer());
+ if (p == root) return QModelIndex();
+ else return createIndex(0,0,static_cast<void*>(root));
+}
+
+int GraphElementData::rowCount(const QModelIndex &parent) const
+{
+ if (parent.isValid()) {
+ return 0;
+ } else {
+ return _properties.size();
+ }
}
+int GraphElementData::columnCount(const QModelIndex &parent) const
+{
+ return 2;
+}
+
+Qt::ItemFlags GraphElementData::flags(const QModelIndex &index) const
+{
+ return QAbstractItemModel::flags(index);
+}
+
+//bool GraphElementData::setData(const QModelIndex &index, const QVariant &value, int role)
+//{
+
+//}
+
+//bool GraphElementData::insertRows(int position, int rows, const QModelIndex &parent)
+//{
+
+//}
+
+//bool GraphElementData::removeRows(int position, int rows, const QModelIndex &parent)
+//{
+
+//}
+