summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-10-01 17:46:11 +0200
committerAleks Kissinger <aleks0@gmail.com>2018-10-01 17:46:11 +0200
commitf085393232f29237e7d6bfb1469d77a78e4a511a (patch)
tree7a7f47a659963f0a8b117982c1e85e1df59fbfe9
parente7a10091b64ddeb1d3e21e3f36abbf412021c815 (diff)
moving properties up and down
-rw-r--r--.gitignore5
-rw-r--r--src/data/graphelementdata.cpp36
-rw-r--r--src/data/graphelementdata.h5
-rw-r--r--src/gui/styleeditor.cpp35
4 files changed, 78 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index e86ac94..8485ec0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,8 @@ src/data/tikzlexer.lexer.cpp
src/data/tikzparser.parser.cpp
src/data/tikzparser.parser.hpp
*.o
+moc_*.cpp
+moc_*.h
+ui_*.h
+qrc_*.cpp
+tikzit
diff --git a/src/data/graphelementdata.cpp b/src/data/graphelementdata.cpp
index 25ba08e..b478842 100644
--- a/src/data/graphelementdata.cpp
+++ b/src/data/graphelementdata.cpp
@@ -110,6 +110,42 @@ int GraphElementData::indexOfKey(QString key)
return -1;
}
+bool GraphElementData::removeRows(int row, int /*count*/, const QModelIndex &parent)
+{
+ if (row >= 0 && row < _properties.length()) {
+ beginRemoveRows(parent, row, row+1);
+ _properties.remove(row);
+ endRemoveRows();
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool GraphElementData::moveRows(const QModelIndex &sourceParent,
+ int sourceRow,
+ int /*count*/,
+ const QModelIndex &destinationParent,
+ int destinationRow)
+{
+ if (sourceRow >= 0 && sourceRow < _properties.length() &&
+ destinationRow >= 0 && destinationRow <= _properties.length())
+ {
+ beginMoveRows(sourceParent, sourceRow, sourceRow, destinationParent, destinationRow);
+ GraphElementProperty p = _properties[sourceRow];
+ _properties.remove(sourceRow);
+ if (sourceRow < destinationRow) {
+ _properties.insert(destinationRow - 1, p);
+ } else {
+ _properties.insert(destinationRow, p);
+ }
+ endMoveRows();
+ return true;
+ } else {
+ return false;
+ }
+}
+
QVariant GraphElementData::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole || role == Qt::EditRole) {
diff --git a/src/data/graphelementdata.h b/src/data/graphelementdata.h
index acaada7..f48f228 100644
--- a/src/data/graphelementdata.h
+++ b/src/data/graphelementdata.h
@@ -43,6 +43,11 @@ public:
QString property(QString key);
bool atom(QString atom);
int indexOfKey(QString key);
+ bool removeRows(int row, int count, const QModelIndex &parent) override;
+ bool moveRows(const QModelIndex &sourceParent,
+ int sourceRow, int,
+ const QModelIndex &destinationParent,
+ int destinationRow) override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation,
diff --git a/src/gui/styleeditor.cpp b/src/gui/styleeditor.cpp
index fbf73a9..f6e3f48 100644
--- a/src/gui/styleeditor.cpp
+++ b/src/gui/styleeditor.cpp
@@ -447,17 +447,46 @@ void StyleEditor::on_addAtom_clicked()
void StyleEditor::on_removeProperty_clicked()
{
-
+ Style *s = activeStyle();
+ if (s != 0) {
+ QModelIndexList sel = ui->properties->selectionModel()->selectedRows();
+ if (!sel.isEmpty()) {
+ s->data()->removeRows(sel[0].row(), 1, sel[0].parent());
+ _dirty = true;
+ }
+ }
}
void StyleEditor::on_propertyUp_clicked()
{
-
+ Style *s = activeStyle();
+ if (s != 0) {
+ QModelIndexList sel = ui->properties->selectionModel()->selectedRows();
+ if (!sel.isEmpty()) {
+ s->data()->moveRows(
+ sel[0].parent(),
+ sel[0].row(), 1,
+ sel[0].parent(),
+ sel[0].row() - 1);
+ _dirty = true;
+ }
+ }
}
void StyleEditor::on_propertyDown_clicked()
{
-
+ Style *s = activeStyle();
+ if (s != 0) {
+ QModelIndexList sel = ui->properties->selectionModel()->selectedRows();
+ if (!sel.isEmpty()) {
+ s->data()->moveRows(
+ sel[0].parent(),
+ sel[0].row(), 1,
+ sel[0].parent(),
+ sel[0].row() + 2);
+ _dirty = true;
+ }
+ }
}
void StyleEditor::on_save_clicked()