diff options
-rw-r--r-- | tikzit/graphelementdata.cpp | 110 | ||||
-rw-r--r-- | tikzit/graphelementdata.h | 43 | ||||
-rw-r--r-- | tikzit/graphelementproperty.cpp | 35 | ||||
-rw-r--r-- | tikzit/graphelementproperty.h | 17 | ||||
-rw-r--r-- | tikzit/main.cpp | 6 | ||||
-rw-r--r-- | tikzit/propertypalette.cpp | 26 | ||||
-rw-r--r-- | tikzit/propertypalette.h | 22 | ||||
-rw-r--r-- | tikzit/propertypalette.ui | 30 | ||||
-rw-r--r-- | tikzit/tikzit.pro | 9 |
9 files changed, 264 insertions, 34 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) +//{ + +//} + diff --git a/tikzit/graphelementdata.h b/tikzit/graphelementdata.h index e67d740..fee65e7 100644 --- a/tikzit/graphelementdata.h +++ b/tikzit/graphelementdata.h @@ -1,24 +1,61 @@ #ifndef GRAPHELEMENTDATA_H #define GRAPHELEMENTDATA_H -#include <QObject> +#include "graphelementproperty.h" + +#include <QAbstractItemModel> #include <QString> +#include <QVariant> +#include <QModelIndex> +#include <QVector> -class GraphElementData : public QObject +class GraphElementData : public QAbstractItemModel { Q_OBJECT public: explicit GraphElementData(QObject *parent = 0); + ~GraphElementData(); void setProperty(QString key, QString value); void unsetProperty(QString key); void setAtom(QString atom); void unsetAtom(QString atom); QString property(QString key); - QString atom(QString atom); + bool atom(QString atom); + + QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; + + int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + + Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; + +// bool setData(const QModelIndex &index, const QVariant &value, +// int role = Qt::EditRole) Q_DECL_OVERRIDE; +// bool setHeaderData(int section, Qt::Orientation orientation, +// const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE; + +// bool insertColumns(int position, int columns, +// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; +// bool removeColumns(int position, int columns, +// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; +// bool insertRows(int position, int rows, +// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; +// bool removeRows(int position, int rows, +// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE; signals: public slots: + +private: + QVector<GraphElementProperty> _properties; + GraphElementProperty *root; }; #endif // GRAPHELEMENTDATA_H diff --git a/tikzit/graphelementproperty.cpp b/tikzit/graphelementproperty.cpp index 7602b1c..9cc6b00 100644 --- a/tikzit/graphelementproperty.cpp +++ b/tikzit/graphelementproperty.cpp @@ -1,16 +1,19 @@ #include "graphelementproperty.h" -GraphElementProperty::GraphElementProperty(QString key, QString value, - bool atom, bool keyMatch, QObject *parent) : - QObject(parent), _key(key), _value(value), _atom(atom), _keyMatch(keyMatch) +GraphElementProperty::GraphElementProperty (): + _key(""), _value(""), _atom(false), _keyMatch(false) {} -GraphElementProperty::GraphElementProperty(QString key, QString value, QObject *parent) : - QObject(parent), _key(key), _value(value), _atom(false), _keyMatch(false) +GraphElementProperty::GraphElementProperty(QString key, QString value, bool atom, bool keyMatch) : + _key(key), _value(value), _atom(atom), _keyMatch(keyMatch) {} -GraphElementProperty::GraphElementProperty(QString key, QObject *parent) : - QObject(parent), _key(key), _value(""), _atom(true), _keyMatch(false) +GraphElementProperty::GraphElementProperty(QString key, QString value) : + _key(key), _value(value), _atom(false), _keyMatch(false) +{} + +GraphElementProperty::GraphElementProperty(QString key, bool keyMatch) : + _key(key), _value(""), _atom(!keyMatch), _keyMatch(keyMatch) {} QString GraphElementProperty::key() const @@ -19,16 +22,24 @@ QString GraphElementProperty::key() const QString GraphElementProperty::value() const { return _value; } +void GraphElementProperty::setValue(const QString &value) +{ _value = value; } + bool GraphElementProperty::atom() const { return _atom; } bool GraphElementProperty::keyMatch() const { return _keyMatch; } -bool GraphElementProperty::matches(GraphElementProperty *p) +bool GraphElementProperty::matches(const GraphElementProperty &p) +{ + if (p.atom()) return _atom && _key == p.key(); + if (p.keyMatch()) return !_atom && _key == p.key(); + if (_keyMatch) return !p.atom() && _key == p.key(); + return !_atom && _key == p.key() && _value == p.value(); +} + +bool GraphElementProperty::operator==(const GraphElementProperty &p) { - if (p->atom()) return _atom && _key == p->key(); - if (p->keyMatch()) return !_atom && _key == p->key(); - if (_keyMatch) return !p->atom() && _key == p->key(); - return !_atom && _key == p->key() && _value == p->value(); + return matches(p); } diff --git a/tikzit/graphelementproperty.h b/tikzit/graphelementproperty.h index 56d20e9..4e8bbd1 100644 --- a/tikzit/graphelementproperty.h +++ b/tikzit/graphelementproperty.h @@ -3,24 +3,27 @@ #include <QObject> -class GraphElementProperty : public QObject +class GraphElementProperty { - Q_OBJECT public: - GraphElementProperty(QString key, QString value, bool atom, bool keyMatch, QObject *parent = 0); + GraphElementProperty(); + GraphElementProperty(QString key, QString value, bool atom, bool keyMatch); // construct a property - GraphElementProperty(QString key, QString value, QObject *parent = 0); + GraphElementProperty(QString key, QString value); - // construct an atom - GraphElementProperty(QString key, QObject *parent = 0); + // construct an atom or keymatch + GraphElementProperty(QString key, bool keyMatch = false); QString key() const; QString value() const; + void setValue(const QString &value); bool atom() const; bool keyMatch() const; - bool matches(GraphElementProperty *p); + bool matches(const GraphElementProperty &p); + bool operator==(const GraphElementProperty &p); + signals: public slots: diff --git a/tikzit/main.cpp b/tikzit/main.cpp index 50c6978..c6b6ecd 100644 --- a/tikzit/main.cpp +++ b/tikzit/main.cpp @@ -1,5 +1,6 @@ #include "mainwindow.h" #include "toolpalette.h" +#include "propertypalette.h" #include "graph.h" #include <QApplication> @@ -14,9 +15,8 @@ int main(int argc, char *argv[]) tp->show(); //w->addToolBar(Qt::LeftToolBarArea, tp); - Graph *g = new Graph; - Node *n = g->addNode(); - delete g; + PropertyPalette *pp = new PropertyPalette; + pp->show(); return a.exec(); } diff --git a/tikzit/propertypalette.cpp b/tikzit/propertypalette.cpp new file mode 100644 index 0000000..6fc9ef9 --- /dev/null +++ b/tikzit/propertypalette.cpp @@ -0,0 +1,26 @@ +#include "propertypalette.h" +#include "graphelementdata.h" +#include "ui_propertypalette.h" + +#include <QModelIndex> +#include <QDebug> + +PropertyPalette::PropertyPalette(QWidget *parent) : + QDockWidget(parent), + ui(new Ui::PropertyPalette) +{ + ui->setupUi(this); + GraphElementData *d = new GraphElementData(); + d->setProperty("key 1", "value 1"); + d->setAtom("atom 1"); + d->setProperty("key 2", "value 2"); + + QModelIndex i = d->index(0,0); + qDebug() << "data: " << i.data(); + ui->treeView->setModel(d); +} + +PropertyPalette::~PropertyPalette() +{ + delete ui; +} diff --git a/tikzit/propertypalette.h b/tikzit/propertypalette.h new file mode 100644 index 0000000..8e8e5b3 --- /dev/null +++ b/tikzit/propertypalette.h @@ -0,0 +1,22 @@ +#ifndef PROPERTYPALETTE_H +#define PROPERTYPALETTE_H + +#include <QDockWidget> + +namespace Ui { +class PropertyPalette; +} + +class PropertyPalette : public QDockWidget +{ + Q_OBJECT + +public: + explicit PropertyPalette(QWidget *parent = 0); + ~PropertyPalette(); + +private: + Ui::PropertyPalette *ui; +}; + +#endif // PROPERTYPALETTE_H diff --git a/tikzit/propertypalette.ui b/tikzit/propertypalette.ui new file mode 100644 index 0000000..83d586e --- /dev/null +++ b/tikzit/propertypalette.ui @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PropertyPalette</class> + <widget class="QDockWidget" name="PropertyPalette"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>194</width> + <height>341</height> + </rect> + </property> + <property name="windowTitle"> + <string>Properties</string> + </property> + <widget class="QWidget" name="dockWidgetContents"> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QTreeView" name="treeView"> + <property name="indentation"> + <number>0</number> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tikzit/tikzit.pro b/tikzit/tikzit.pro index 2762908..fd70729 100644 --- a/tikzit/tikzit.pro +++ b/tikzit/tikzit.pro @@ -32,7 +32,8 @@ SOURCES += main.cpp\ edge.cpp \ tikzgraphassembler.cpp \ graphelementdata.cpp \ - graphelementproperty.cpp + graphelementproperty.cpp \ + propertypalette.cpp HEADERS += mainwindow.h \ toolpalette.h \ @@ -42,9 +43,11 @@ HEADERS += mainwindow.h \ edge.h \ tikzgraphassembler.h \ graphelementdata.h \ - graphelementproperty.h + graphelementproperty.h \ + propertypalette.h -FORMS += mainwindow.ui +FORMS += mainwindow.ui \ + propertypalette.ui DISTFILES += |