diff --git a/MinetestMapperGui.pro b/MinetestMapperGui.pro
index 3636810..0c8de00 100644
--- a/MinetestMapperGui.pro
+++ b/MinetestMapperGui.pro
@@ -16,17 +16,26 @@ TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
colorlineedit.cpp \
+ geometry.cpp \
geometrywidget.cpp \
configdialog.cpp \
colorstxtassistant.cpp \
- makecolors.cpp
+ makecolors.cpp \
+ drawmapfigure.cpp \
+ drawmapfiguretablemodel.cpp \
+ figuredelegate.cpp
+
HEADERS += mainwindow.h \
colorlineedit.h \
+ geometry.h \
geometrywidget.h \
configdialog.h \
colorstxtassistant.h \
- makecolors.h
+ makecolors.h \
+ drawmapfigure.h \
+ drawmapfiguretablemodel.h \
+ figuredelegate.h
FORMS += mainwindow.ui \
geometrywidget.ui \
diff --git a/doc/drawfigure.html b/doc/drawfigure.html
new file mode 100644
index 0000000..8f661d4
--- /dev/null
+++ b/doc/drawfigure.html
@@ -0,0 +1,104 @@
+
+
+ Draw a figure on the map, with the given geometry and color.
+ Possible figures are:
+
+ circle
+ ellipse (which is a synonym for circle)
+ line
+ arrow
+ point (which uses simple coordinates (x,y) instead of a geometry)
+ rectangle
+ text (which uses simple coordinates (x,y) instead of a geometry)
+
+ If --draw<figure>
is used, the geometry specifies world coordinates; if --drawmap<figure>
is used, the geometry specifies map (i.e. image) coordinates, where 0,0 is the top-left corner of the map-part of
+ the image, and coordinates increase to the right and down. Any points in the left and top scale area (if present)
+ have negative coordinates.
+ Note that the combination of geometry and color (and text if applicable) must be a single argument. This means that they
+ must be enclosed in quotes together on the command-line, else they will be misinterpreted as two or more
+ command-line arguments.
+ Example:
+ minetestmapper --drawcircle "10,10:6x6 red"
+ For the color of figures, an alpha value can be specified. Note that due to a bug in the drawing library, this has not
+ the expected effect when drawing circles and ellipses.
+ See also Geometry Syntax_ and Color Syntax_.
+ Interaction of figure geometry and map scaling
+ If the map is scaled, figures could either keep the same size in pixels, or the same size relative to the world, which
+ would make them appear smaller like the entire map. Whether they scale of not depends on how they are drawn:
+
+
+ Figures which are drawn using map (i.e. image) coordinates are never scaled. It is assumed that it was the intention
+ to draw them on the image to begin with, and not in the world.
+
+
+ At the moment, figures which are drawn using world coordinates may or may not scale with the world.
+
+ If the geometry of a figure is specified using 2 corners, then the distance between the coordinates obviously scales
+ with the world, and the resulting figure will be visually smaller as well.
+ If the geometry of a figure is specified using a corner or the center and dimensions, then the corner or center is
+ obviously also interpreted as world-coordinates, but the dimensions will be interpreted relative to the image.
+ I.e. they won't scale with the map.
+ If the geometry is specified using an angle and length, and if the length is specified in nodes (e.g. '20n'), the
+ size will scale. If the length is specified in pixels (e.g. '20p') or if no unit is specified, then the size
+ will not scale.
+
+ In practise this means that two identically-sized figures in a full-scale map, may have different sizes after scaling,
+ depending on how their geometry was specified. The jury is still out as to whether this is a bug or a feature.
+
+--draw[map]circle "<geometry> <color>"
+
+ Draw a circle on the map, with the given geometry and color.
+ If the geometry does not specify equal horizontal and vertical dimensions, then an ellipse will be drawn.
+ See --draw[map] for details.
+ An example circle:
+
+
+--draw[map]ellipse "<geometry> <color>"
+
+ Draw an ellipse on the map. This is a synonym for --draw[map]circle
.
+ See --draw[map] for details.
+
+--draw[map]line "<geometry> <color>"
+
+ Draw a line on the map, with the given geometry and color.
+ See --draw[map] for details.
+ An example line:
+
+
+--draw[map]arrow "<geometry> <color>"
+
+ Draw an arrow on the map, with the given geometry and color.
+ See --draw[map] for details.
+ An example arrow:
+
+
+--draw[map]point "<x>,<y> <color>"
+
+ Draw a point on the map, at the given location, using the given color.
+ See --draw[map] for details.
+ An example point (red, in te white area):
+
+
+--draw[map]rectangle "<geometry> <color>"
+
+ Draw a reactangle on the map, with the given geometry and color.
+ See --draw[map] for details.
+ An example rectangle:
+
+
+--draw[map]text "<x>,<y> <color> <text>"
+
+ Write text on the map, at the specified location, using the given color.
+ The text can consist of any number of words. Be careful when using characters that the command shell may interpret, like
+ '"
', '$
', etc. On unix-like systems, use single quotes to avoid interpretation of
+ most characters (except for '
itself).
+ Due to a limitation of the drawing library, currently only text that can be represented in (i.e. converted to) the ISO8859-2
+ character set is supported. Text that uses non-compatible characters will not be rendered correctly.
+ Note that the combination of geometry, color and text should be a single argument. This means that they must be enclosed
+ in quotes together on the command-line, else they will be misinterpreted as three command-line arguments.
+ Example:
+ minetestmapper --drawtext "20,-10 red This text will be on the map"
+ See also --draw[map] for more details.
+ Example text:
+
+
\ No newline at end of file
diff --git a/drawmapfigure.cpp b/drawmapfigure.cpp
new file mode 100644
index 0000000..97eba50
--- /dev/null
+++ b/drawmapfigure.cpp
@@ -0,0 +1,227 @@
+#include "drawmapfigure.h"
+
+DrawMapFigure::DrawMapFigure(QObject *parent) :
+ QObject(parent)
+{
+ geometry = new Geometry();
+}
+
+DrawMapFigure::DrawMapFigure(const QString &str, QObject *parent) :
+ QObject(parent)
+{
+ const QRegularExpression parser = QRegularExpression("^--draw(?map)?(?\\w+) \"(?.+)*\"$");
+ QRegularExpressionMatch match = parser.match(str);
+
+ QStringList xy;
+ if(match.hasMatch()){
+ useImageCoordinates = (match.captured("map")=="map");
+ QString params = match.captured("params");
+
+ color.setNamedColor(params.section(' ', 1, 1));
+ bool ok;
+ figure = getFigure(match.captured("type"));
+ if(color.isValid() && ok){
+ switch (figure) {
+ case Text:
+ //parse text and fall through for point
+ text = params.section(' ', 2);// everything after the 3rd whitespace
+ case Point:
+ //parse point and color
+ xy = params.section(' ', 0, 0).split(',');
+ point.setX(xy[0].toInt());
+ point.setY(xy[1].toInt());
+ break;
+ case Circle:
+ case Arrow:
+ case Line:
+ case Rectangle:
+ case Ellipse:
+ //parse geometry
+ geometry = new Geometry(params.section(' ', 0, 0));
+ break;
+ default:
+ figure = Unknown;
+ geometry = new Geometry();
+ break;
+ }
+ }
+ else{
+ geometry = new Geometry();
+ figure = Unknown;
+ }
+
+
+ }
+ else{
+ geometry = new Geometry();
+ figure = Unknown;
+ }
+}
+
+bool DrawMapFigure::requiresPoint() const
+{
+ return (figure == Text || figure == Point);
+}
+
+bool DrawMapFigure::requiresGeometry() const
+{
+ return (figure != Text && figure != Point);
+}
+
+bool DrawMapFigure::requiresText() const
+{
+ return (figure == Text);
+}
+
+QString DrawMapFigure::getString() const
+{
+ QStringList splitted = getSplittedString();
+
+ return QString("%1 \"%2\"").arg(splitted.at(0)).arg(splitted.at(1));
+
+}
+
+QStringList DrawMapFigure::getSplittedString() const
+{
+ QString param;
+ QString argument;
+
+ param = "--draw";
+ if(useImageCoordinates)
+ param += "map";
+ param += QString(metaFigure.key(figure)).toLower();
+
+ if(requiresGeometry())
+ argument += geometry->getString();
+ if(requiresPoint())
+ argument += QString("%1,%2").arg(point.x()).arg(point.y());
+ argument += ' '+ color.name();
+ if(requiresText())
+ argument += ' '+text;
+
+ return QStringList()< (metaFigure.keyToValue(temp.toUtf8().constData()));
+}
+
+int DrawMapFigure::getFigureIndex() const
+{
+ QMetaEnum metaEnum = QMetaEnum::fromType();
+ return metaEnum.value(figure);
+}
+
+QPoint DrawMapFigure::getPoint() const
+{
+ return point;
+}
+
+QString DrawMapFigure::getText() const
+{
+ return text;
+}
+
+QColor DrawMapFigure::getColor() const
+{
+ return color;
+}
+
+QStringList DrawMapFigure::getFigureList()
+{
+ QMetaEnum metaEnum = QMetaEnum::fromType();
+ QStringList list;
+ for(int i =0; i(value);
+}
+
+void DrawMapFigure::setText(const QString &value)
+{
+ text = value;
+}
+
+void DrawMapFigure::setColor(const QColor &value)
+{
+ color = value;
+}
+
+Geometry *DrawMapFigure::getGeometry()
+{
+ return this->geometry;
+}
+
+void DrawMapFigure::setGeometry(Geometry *value)
+{
+ geometry = value;
+}
+
+void DrawMapFigure::setUseImageCoordinates(bool value)
+{
+ useImageCoordinates = value;
+}
+
+void DrawMapFigure::setPoint(const QPoint &value)
+{
+ point = value;
+}
+
+void DrawMapFigure::setPoint(const QVariant &value)
+{
+ point = value.toPoint();
+}
+
+void DrawMapFigure::setPoint(const QString &value)
+{
+ static const QRegularExpression regex("(\\-?\\d+)[ |,](\\-?\\d+)");
+ QRegularExpressionMatch match = regex.match(value);
+ if(match.hasMatch()){
+ point = QPoint(match.captured(1).toInt(), match.captured(2).toInt());
+ }
+ else{
+ qDebug() <<"Could not match point from String "<().key(figure);
+ return QIcon(QString(":/images/draw-%1").arg(a).toLower());
+}
+
+
+
+
+
+
diff --git a/drawmapfigure.h b/drawmapfigure.h
new file mode 100644
index 0000000..1b4a4db
--- /dev/null
+++ b/drawmapfigure.h
@@ -0,0 +1,106 @@
+#ifndef DRAWMAPFIGURE_H
+#define DRAWMAPFIGURE_H
+
+#include
+#include
+#include
+#include
+#include
+
+#include "geometry.h"
+
+class DrawMapFigure : public QObject
+{
+ Q_OBJECT
+public:
+ enum Figure{
+ Unknown,
+ Arrow,
+ Circle,
+ Ellipse,
+ Line,
+ Point,
+ Rectangle,
+ Text
+
+ };
+ Q_ENUM(Figure)
+
+ explicit DrawMapFigure(QObject *parent = 0);
+ /**
+ * @brief DrawMapFigure
+ * @param str QString to convert to DrawMapFigure
+ * @param parent
+ */
+ explicit DrawMapFigure(const QString &str, QObject *parent = 0);
+
+ explicit DrawMapFigure(QColor color, QObject *parent = 0) :
+ color(color), QObject(parent) { }
+
+ explicit DrawMapFigure(QPoint point, QColor color, QObject *parent = 0) :
+ point(point), color(color), QObject(parent) {}
+
+ explicit DrawMapFigure(Geometry *geometry, QColor color, QObject *parent = 0) :
+ geometry(geometry), color(color), QObject(parent) { }
+
+ //DrawMapFigure(const DrawMapFigure &f) {}
+ bool requiresPoint(void) const;
+ bool requiresGeometry(void) const;
+ bool requiresText(void) const;
+
+ QString getString(void) const;
+ QStringList getSplittedString(void) const;
+ bool getUseImageCoordinates() const;
+
+ int getFigureIndex() const;
+
+ QPoint getPoint() const;
+
+ QString getText() const;
+ /**
+ * @brief getColor
+ * @return
+ */
+ QColor getColor() const;
+
+ static QStringList getFigureList();
+
+ void setFigure(const Figure &value);
+ void setFigure(int value);
+
+ void setText(const QString &value);
+
+ void setColor(const QColor &value);
+
+ Geometry* getGeometry();
+ void setGeometry(Geometry *value);
+
+ void setUseImageCoordinates(bool value);
+ void setPoint(const QString &value);
+ void setPoint(const QPoint &value);
+
+ QIcon getIcon() const;
+ static QIcon getIcon(Figure figure);
+
+ void setPoint(const QVariant &value);
+
+ Figure getFigure() const;
+ Figure getFigure(const QString &str) const;
+
+signals:
+
+public slots:
+
+protected:
+ bool useImageCoordinates;
+ Figure figure = Unknown;
+ QPoint point;
+ Geometry *geometry;
+ QString text;
+ QColor color;
+ QMetaEnum metaFigure = QMetaEnum::fromType();
+private:
+
+};
+
+#endif // DRAWMAPFIGURE_H
diff --git a/drawmapfiguretablemodel.cpp b/drawmapfiguretablemodel.cpp
new file mode 100644
index 0000000..ec79a4f
--- /dev/null
+++ b/drawmapfiguretablemodel.cpp
@@ -0,0 +1,248 @@
+#include "drawmapfiguretablemodel.h"
+
+#include
+
+DrawMapFigureTableModel::DrawMapFigureTableModel(QObject *parent)
+ : QAbstractTableModel(parent)
+{
+ list = new QList;
+ header <<"Figure"<<"Use image coordinates"<<"Point"<<"Geometry"<<"Color"<<"Text";
+}
+
+DrawMapFigureTableModel::DrawMapFigureTableModel(QList *list, QObject *parent)
+ : QAbstractTableModel(parent)
+{
+ this->list = list;
+ header <<"Figure"<<"Use image coordinates"<<"Point"<<"Geometry"<<"Color"<<"Text";
+}
+
+QVariant DrawMapFigureTableModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role == Qt::DisplayRole && orientation == Qt::Horizontal && section <= header.size())
+ {
+ return header[section];
+ }
+ else if(role == Qt::DisplayRole && orientation == Qt::Vertical){
+ return section+1;
+ }
+ return QVariant();
+}
+
+bool DrawMapFigureTableModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
+{
+ if (value != headerData(section, orientation, role) && role == Qt::DisplayRole && orientation == Qt::Horizontal)
+ {
+ header[section] = value.toString();
+ emit headerDataChanged(orientation, section, section);
+ return true;
+ }
+
+
+ return false;
+}
+
+
+int DrawMapFigureTableModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ if (parent.isValid())
+ return 0;
+
+
+ return list->size();
+}
+
+int DrawMapFigureTableModel::columnCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ if (parent.isValid())
+ return 0;
+
+ return header.size();
+ // FIXME: Implement me!
+}
+
+QVariant DrawMapFigureTableModel::data(const QModelIndex &index, int role) const
+{
+ if (index.isValid()){
+ int row = index.row();
+ int col = index.column();
+ DrawMapFigure *item = list->at(row);
+ QPoint p = item->getPoint();
+ QMetaEnum metaEnum = QMetaEnum::fromType();
+ if(role == Qt::DecorationRole && col ==0)
+ {
+ return item->getIcon();
+ }
+ else if(role == Qt::BackgroundRole)
+ {
+ if(item->getFigure()==DrawMapFigure::Unknown){
+ return QBrush(Qt::red);
+ }
+ else if(col == 2 && !item->requiresPoint()){
+ return QBrush(Qt::lightGray);
+ }
+ else if (col == 3 && !item->requiresGeometry()){
+ return QBrush(Qt::lightGray);
+ }
+ else if(col == 5 && !item->requiresText()){
+ return QBrush(Qt::lightGray);
+ }
+ }
+ else if(role == Qt::EditRole ||role == Qt::DisplayRole){
+
+ switch(col){
+ case 0:
+ return (role == Qt::EditRole) ? QVariant(item->getFigure()) : QString(metaEnum.key(item->getFigure()));
+ break;
+
+ case 1:
+ return item->getUseImageCoordinates();
+ break;
+ case 2:
+ return (item->requiresPoint()) ? QString("(%1,%2)").arg(p.x()).arg(p.y()) : QVariant();
+ break;
+ case 3:
+ return item->requiresGeometry() ? item->getGeometry()->getString() : QVariant();
+ break;
+ case 4:
+ return item->getColor();
+ break;
+ case 5:
+ return item->getText();
+ break;
+ default:
+ return QVariant();
+ }
+
+ // FIXME: Implement me!
+ return QVariant();
+ }
+ else if(role == Qt::DecorationRole && col==4){
+ return item->getColor();
+ }
+ }
+ return QVariant();
+}
+
+bool DrawMapFigureTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ if (index.isValid() && role == Qt::EditRole && data(index, role) != value) {
+ int row = index.row();
+ int col = index.column();
+ DrawMapFigure *item = list->at(row);
+ switch(col){
+ case 0:
+ item->setFigure(value.toInt());
+ break;
+ case 1:
+ item->setUseImageCoordinates(value.toBool());
+ break;
+ case 2:
+ item->setPoint(value.toString());
+ break;
+ case 3:
+ item->getGeometry()->set(value.toString());
+ break;
+ case 4:
+ item->setColor(QColor(value.toString()));
+ break;
+ case 5:
+ item->setText(value.toString());
+ default:
+ break;
+ }
+ // FIXME: Implement me!
+ emit dataChanged(index, index, QVector() << role);
+ return true;
+ }
+ return false;
+}
+
+Qt::ItemFlags DrawMapFigureTableModel::flags(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return Qt::NoItemFlags;
+ Qt::ItemFlags flag = QAbstractItemModel::flags(index);
+ int col = index.column();
+ DrawMapFigure *item = list->at(index.row());
+ if(col == 0)
+ flag |= Qt::ItemIsEnabled|Qt::ItemIsEditable;
+ else if(col == 1)
+ flag |= Qt::ItemIsEditable;
+ else if (col == 2 && item->requiresPoint())
+ flag |= Qt::ItemIsEditable;
+ else if (col == 3 && item->requiresGeometry())
+ flag |= Qt::ItemIsEditable;
+ else if (col == 4)
+ flag |= Qt::ItemIsEditable;
+ else if(col == 5 && item->requiresText())
+ flag |= Qt::ItemIsEditable;
+
+ return flag;
+}
+
+bool DrawMapFigureTableModel::insertRows(int position, int count, const QModelIndex &parent)
+{
+ beginInsertRows(parent, position, position + count - 1);
+ for (int row = 0; row < count; ++row) {
+ list->insert(position, new DrawMapFigure());
+ }
+ endInsertRows();
+ return true;
+}
+
+bool DrawMapFigureTableModel::insertColumns(int column, int count, const QModelIndex &parent)
+{
+ beginInsertColumns(parent, column, column + count - 1);
+ // FIXME: Implement me!
+ endInsertColumns();
+ return false;
+}
+
+bool DrawMapFigureTableModel::removeRows(int position, int count, const QModelIndex &parent)
+{
+ beginRemoveRows(parent, position, position + count - 1);
+ for (int row = 0; row < count; ++row) {
+ list->removeAt(position);
+ }
+ endRemoveRows();
+ return true;
+}
+
+bool DrawMapFigureTableModel::removeColumns(int column, int count, const QModelIndex &parent)
+{
+ beginRemoveColumns(parent, column, column + count - 1);
+ // FIXME: Implement me!
+ endRemoveColumns();
+ return false;
+}
+
+QStringList DrawMapFigureTableModel::getStringList() const
+{
+ QStringList retval;
+ for (int i = 0; i < list->size(); ++i)
+ retval << list->at(i)->getString();
+ return retval;
+}
+
+QStringList DrawMapFigureTableModel::getArguments() const
+{
+ QStringList retval;
+ for (int i = 0; i < list->size(); ++i)
+ retval << list->at(i)->getSplittedString();
+ return retval;
+}
+
+void DrawMapFigureTableModel::insertStringList(const QStringList &other)
+{
+ if(other.length() > 0){
+ int leng = other.length();
+ beginInsertRows(QModelIndex() , list->length(), list->length()+leng - 1);
+ //insertRows(0, other.length(),QModelIndex());
+ for(int i = 0; i < leng; ++i){
+ list->append(new DrawMapFigure(other.at(i)));
+ }
+ endInsertRows();
+ }
+}
diff --git a/drawmapfiguretablemodel.cpp.autosave b/drawmapfiguretablemodel.cpp.autosave
new file mode 100644
index 0000000..ec79a4f
--- /dev/null
+++ b/drawmapfiguretablemodel.cpp.autosave
@@ -0,0 +1,248 @@
+#include "drawmapfiguretablemodel.h"
+
+#include
+
+DrawMapFigureTableModel::DrawMapFigureTableModel(QObject *parent)
+ : QAbstractTableModel(parent)
+{
+ list = new QList;
+ header <<"Figure"<<"Use image coordinates"<<"Point"<<"Geometry"<<"Color"<<"Text";
+}
+
+DrawMapFigureTableModel::DrawMapFigureTableModel(QList *list, QObject *parent)
+ : QAbstractTableModel(parent)
+{
+ this->list = list;
+ header <<"Figure"<<"Use image coordinates"<<"Point"<<"Geometry"<<"Color"<<"Text";
+}
+
+QVariant DrawMapFigureTableModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role == Qt::DisplayRole && orientation == Qt::Horizontal && section <= header.size())
+ {
+ return header[section];
+ }
+ else if(role == Qt::DisplayRole && orientation == Qt::Vertical){
+ return section+1;
+ }
+ return QVariant();
+}
+
+bool DrawMapFigureTableModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
+{
+ if (value != headerData(section, orientation, role) && role == Qt::DisplayRole && orientation == Qt::Horizontal)
+ {
+ header[section] = value.toString();
+ emit headerDataChanged(orientation, section, section);
+ return true;
+ }
+
+
+ return false;
+}
+
+
+int DrawMapFigureTableModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ if (parent.isValid())
+ return 0;
+
+
+ return list->size();
+}
+
+int DrawMapFigureTableModel::columnCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ if (parent.isValid())
+ return 0;
+
+ return header.size();
+ // FIXME: Implement me!
+}
+
+QVariant DrawMapFigureTableModel::data(const QModelIndex &index, int role) const
+{
+ if (index.isValid()){
+ int row = index.row();
+ int col = index.column();
+ DrawMapFigure *item = list->at(row);
+ QPoint p = item->getPoint();
+ QMetaEnum metaEnum = QMetaEnum::fromType();
+ if(role == Qt::DecorationRole && col ==0)
+ {
+ return item->getIcon();
+ }
+ else if(role == Qt::BackgroundRole)
+ {
+ if(item->getFigure()==DrawMapFigure::Unknown){
+ return QBrush(Qt::red);
+ }
+ else if(col == 2 && !item->requiresPoint()){
+ return QBrush(Qt::lightGray);
+ }
+ else if (col == 3 && !item->requiresGeometry()){
+ return QBrush(Qt::lightGray);
+ }
+ else if(col == 5 && !item->requiresText()){
+ return QBrush(Qt::lightGray);
+ }
+ }
+ else if(role == Qt::EditRole ||role == Qt::DisplayRole){
+
+ switch(col){
+ case 0:
+ return (role == Qt::EditRole) ? QVariant(item->getFigure()) : QString(metaEnum.key(item->getFigure()));
+ break;
+
+ case 1:
+ return item->getUseImageCoordinates();
+ break;
+ case 2:
+ return (item->requiresPoint()) ? QString("(%1,%2)").arg(p.x()).arg(p.y()) : QVariant();
+ break;
+ case 3:
+ return item->requiresGeometry() ? item->getGeometry()->getString() : QVariant();
+ break;
+ case 4:
+ return item->getColor();
+ break;
+ case 5:
+ return item->getText();
+ break;
+ default:
+ return QVariant();
+ }
+
+ // FIXME: Implement me!
+ return QVariant();
+ }
+ else if(role == Qt::DecorationRole && col==4){
+ return item->getColor();
+ }
+ }
+ return QVariant();
+}
+
+bool DrawMapFigureTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ if (index.isValid() && role == Qt::EditRole && data(index, role) != value) {
+ int row = index.row();
+ int col = index.column();
+ DrawMapFigure *item = list->at(row);
+ switch(col){
+ case 0:
+ item->setFigure(value.toInt());
+ break;
+ case 1:
+ item->setUseImageCoordinates(value.toBool());
+ break;
+ case 2:
+ item->setPoint(value.toString());
+ break;
+ case 3:
+ item->getGeometry()->set(value.toString());
+ break;
+ case 4:
+ item->setColor(QColor(value.toString()));
+ break;
+ case 5:
+ item->setText(value.toString());
+ default:
+ break;
+ }
+ // FIXME: Implement me!
+ emit dataChanged(index, index, QVector() << role);
+ return true;
+ }
+ return false;
+}
+
+Qt::ItemFlags DrawMapFigureTableModel::flags(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return Qt::NoItemFlags;
+ Qt::ItemFlags flag = QAbstractItemModel::flags(index);
+ int col = index.column();
+ DrawMapFigure *item = list->at(index.row());
+ if(col == 0)
+ flag |= Qt::ItemIsEnabled|Qt::ItemIsEditable;
+ else if(col == 1)
+ flag |= Qt::ItemIsEditable;
+ else if (col == 2 && item->requiresPoint())
+ flag |= Qt::ItemIsEditable;
+ else if (col == 3 && item->requiresGeometry())
+ flag |= Qt::ItemIsEditable;
+ else if (col == 4)
+ flag |= Qt::ItemIsEditable;
+ else if(col == 5 && item->requiresText())
+ flag |= Qt::ItemIsEditable;
+
+ return flag;
+}
+
+bool DrawMapFigureTableModel::insertRows(int position, int count, const QModelIndex &parent)
+{
+ beginInsertRows(parent, position, position + count - 1);
+ for (int row = 0; row < count; ++row) {
+ list->insert(position, new DrawMapFigure());
+ }
+ endInsertRows();
+ return true;
+}
+
+bool DrawMapFigureTableModel::insertColumns(int column, int count, const QModelIndex &parent)
+{
+ beginInsertColumns(parent, column, column + count - 1);
+ // FIXME: Implement me!
+ endInsertColumns();
+ return false;
+}
+
+bool DrawMapFigureTableModel::removeRows(int position, int count, const QModelIndex &parent)
+{
+ beginRemoveRows(parent, position, position + count - 1);
+ for (int row = 0; row < count; ++row) {
+ list->removeAt(position);
+ }
+ endRemoveRows();
+ return true;
+}
+
+bool DrawMapFigureTableModel::removeColumns(int column, int count, const QModelIndex &parent)
+{
+ beginRemoveColumns(parent, column, column + count - 1);
+ // FIXME: Implement me!
+ endRemoveColumns();
+ return false;
+}
+
+QStringList DrawMapFigureTableModel::getStringList() const
+{
+ QStringList retval;
+ for (int i = 0; i < list->size(); ++i)
+ retval << list->at(i)->getString();
+ return retval;
+}
+
+QStringList DrawMapFigureTableModel::getArguments() const
+{
+ QStringList retval;
+ for (int i = 0; i < list->size(); ++i)
+ retval << list->at(i)->getSplittedString();
+ return retval;
+}
+
+void DrawMapFigureTableModel::insertStringList(const QStringList &other)
+{
+ if(other.length() > 0){
+ int leng = other.length();
+ beginInsertRows(QModelIndex() , list->length(), list->length()+leng - 1);
+ //insertRows(0, other.length(),QModelIndex());
+ for(int i = 0; i < leng; ++i){
+ list->append(new DrawMapFigure(other.at(i)));
+ }
+ endInsertRows();
+ }
+}
diff --git a/drawmapfiguretablemodel.h b/drawmapfiguretablemodel.h
new file mode 100644
index 0000000..df0a3c9
--- /dev/null
+++ b/drawmapfiguretablemodel.h
@@ -0,0 +1,51 @@
+#ifndef DRAWMAPFIGURETABLEMODEL_H
+#define DRAWMAPFIGURETABLEMODEL_H
+
+#include
+#include
+#include "drawmapfigure.h"
+#include "geometry.h"
+
+class DrawMapFigureTableModel : public QAbstractTableModel
+{
+ Q_OBJECT
+
+public:
+ explicit DrawMapFigureTableModel(QObject *parent = 0);
+ explicit DrawMapFigureTableModel(QList *list, QObject *parent = 0);
+
+ // Header:
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
+
+ bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
+
+ // Basic functionality:
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const override;
+
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+
+ // Editable:
+ bool setData(const QModelIndex &index, const QVariant &value,
+ int role = Qt::EditRole) override;
+
+ Qt::ItemFlags flags(const QModelIndex& index) const override;
+
+ // Add data:
+ bool insertRows(int position, int count, const QModelIndex &parent = QModelIndex()) override;
+ bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
+
+ // Remove data:
+ bool removeRows(int position, int count, const QModelIndex &parent = QModelIndex()) override;
+ bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
+
+ QStringList getStringList(void) const;
+ QStringList getArguments(void) const;
+ void insertStringList(const QStringList &other);
+
+private:
+ QList *list;
+ QStringList header;
+};
+
+#endif // DRAWMAPFIGURETABLEMODEL_H
diff --git a/figuredelegate.cpp b/figuredelegate.cpp
new file mode 100644
index 0000000..91d0a76
--- /dev/null
+++ b/figuredelegate.cpp
@@ -0,0 +1,55 @@
+#include "figuredelegate.h"
+
+#include
+
+FigureDelegate::FigureDelegate(QObject *parent)
+ : QStyledItemDelegate(parent)
+{
+list = DrawMapFigure::getFigureList();
+}
+
+QWidget *FigureDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem &/* option */,
+ const QModelIndex &/* index */) const
+{
+ QComboBox *editor = new QComboBox(parent);
+ editor->setFrame(false);
+ QMetaEnum figureEnum = QMetaEnum::fromType();
+ for(int i = 0; i(figureEnum.value(i));
+ editor->addItem(DrawMapFigure::getIcon(f), list.at(i), f);
+ }
+
+ return editor;
+}
+
+void FigureDelegate::setEditorData(QWidget *editor,
+ const QModelIndex &index) const
+{
+ int value = index.model()->data(index, Qt::EditRole).toInt();
+
+ QComboBox *comboBox = static_cast(editor);
+ comboBox->setCurrentIndex(value);
+}
+
+void FigureDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const
+{
+ QComboBox *comboBox = static_cast(editor);
+
+ model->setData(index, comboBox->currentData(), Qt::EditRole);
+}
+
+void FigureDelegate::updateEditorGeometry(QWidget *editor,
+ const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
+{
+ editor->setGeometry(option.rect);
+}
+
+/*void FigureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ QStyle* style = QApplication::style();
+ QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &option);
+ painter->drawText(textRect, option.displayAlignment, list.at(index.data().toInt()));
+ QStyledItemDelegate::paint(painter, option, index);
+}*/
diff --git a/figuredelegate.h b/figuredelegate.h
new file mode 100644
index 0000000..30f42f0
--- /dev/null
+++ b/figuredelegate.h
@@ -0,0 +1,35 @@
+#ifndef FIGUREDELEGATE_H
+#define FIGUREDELEGATE_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "drawmapfigure.h"
+
+class FigureDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+
+public:
+ FigureDelegate(QObject *parent = 0);
+
+ QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
+
+ void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
+ void setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const Q_DECL_OVERRIDE;
+
+ void updateEditorGeometry(QWidget *editor,
+ const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
+
+ //void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE ;
+private:
+ QStringList list;
+};
+
+#endif // FIGUREDELEGATE_H
diff --git a/geometry.cpp b/geometry.cpp
new file mode 100644
index 0000000..c59fb11
--- /dev/null
+++ b/geometry.cpp
@@ -0,0 +1,256 @@
+#include "geometry.h"
+
+
+QMap Geometry::geometryIdNameMap;
+QMap Geometry::geometryNameIdMap;
+const Geometry::InitStatics initStatics;
+
+Geometry::InitStatics::InitStatics()
+{
+ Geometry::geometryIdNameMap[Geometry::FormatUnknown] = "unknown";
+ Geometry::geometryIdNameMap[Geometry::FormatNone] = "none";
+ Geometry::geometryIdNameMap[Geometry::CenterDimensions] = "center-dimensions";
+ Geometry::geometryIdNameMap[Geometry::CornerDimensions] = "corner-dimensions";
+ Geometry::geometryIdNameMap[Geometry::Corners] = "corners";
+ Geometry::geometryIdNameMap[Geometry::FormatCustom] = "custom";
+
+ for (int i = Geometry::FormatNone; i < Geometry::FormatMax; i++)
+ Geometry::geometryNameIdMap[Geometry::geometryIdNameMap[static_cast(i)]] = static_cast(i);
+
+}
+
+const QString &Geometry::formatName(Geometry::Format id)
+{
+ if (id < Geometry::FormatNone || id >= Geometry::FormatMax)
+ id = Geometry::FormatUnknown;
+ return geometryIdNameMap[id];
+}
+
+Geometry::Format Geometry::formatId(const QString &name)
+{
+ if (geometryNameIdMap.find(name) == geometryNameIdMap.end())
+ return Geometry::FormatUnknown;
+ else
+ return geometryNameIdMap[name];
+}
+
+Geometry::Format Geometry::set(QString str)
+{
+ qDebug()<<"Trying to detect format of "<x[<+|-xoffset><+|-yoffset>]";
+ if(match.lastCapturedIndex() ==2){
+ qDebug() << "format is CenterDimensions with center =0,0";
+ center[0] = 0;
+ center[1] = 0;
+ dimension[0] = match.captured(1).toInt();
+ dimension[1] = match.captured(2).toInt();
+ computeCorner0();
+ computeCorner1();
+ if (adjustCorners()) {
+ // Order is important here!
+ computeDimensions();
+ computeCenter();
+ }
+ return Geometry::CenterDimensions;
+ }
+ else if(match.lastCapturedIndex() ==4){
+ qDebug() << "format is CornerDimensions";
+ corner[0][0] = match.captured(3).toInt();
+ corner[0][1] = match.captured(4).toInt();
+ dimension[0] = match.captured(1).toInt();
+ dimension[1] = match.captured(2).toInt();
+ computeCenter();
+ computeCorner1();
+ if (adjustCorners()) {
+ // Order is important here!
+ computeDimensions();
+ computeCenter();
+ }
+ return Geometry::CornerDimensions;
+ }
+ else return Geometry::FormatCustom;
+ }
+ else {
+ qDebug()<<"Warning: Could not parse format of string: "< 32767) {
+ corner[j][i] = 32767;
+ adjusted = true;
+ }
+ }
+ }
+ return adjusted;
+}
+
+void Geometry::setCenterDimensions(int cx, int cy, int dx, int dy)
+{
+ center[0] = cx;
+ center[1] = cy;
+ dimension[0] = dx;
+ dimension[1] = dy;
+ computeCorner0();
+ computeCorner1();
+}
+
+void Geometry::setCornerDimensions(int cx, int cy, int dx, int dy)
+{
+ corner[0][0] = cx;
+ corner[0][1] = cy;
+ dimension[0] = dx;
+ dimension[1] = dy;
+ computeCenter();
+ computeCorner1();
+}
+
+void Geometry::setCorners(int c0x, int c0y, int c1x, int c1y)
+{
+ corner[0][0] = c0x;
+ corner[0][1] = c0y;
+ corner[1][0] = c1x;
+ corner[1][1] = c1y;
+ computeDimensions();
+ computeCenter();
+}
+
+QString Geometry::getString(Geometry::Format format)
+{
+ switch (format) {
+ case CenterDimensions:
+ if(center[0]==0 && center[1] ==0)
+ return QString("%1x%2")
+ .arg(dimension[0])
+ .arg(dimension[1]);
+ return QString("%1,%2:%3x%4")
+ .arg(center[0])
+ .arg(center[1])
+ .arg(dimension[0])
+ .arg(dimension[1]);
+ break;
+ case CornerDimensions:
+ return QString("%1,%2+%3+%4")
+ .arg(corner[0][0])
+ .arg(corner[0][1])
+ .arg(dimension[0])
+ .arg(dimension[1]);
+ break;
+ case Corners:
+ default:
+ return QString("%1,%2:%3,%4")
+ .arg(corner[0][0])
+ .arg(corner[0][1])
+ .arg(corner[1][0])
+ .arg(corner[1][1]);
+ break;
+ }
+
+}
+
+void Geometry::computeCorner0(void)
+{
+ for (int i = 0; i < 2; i++) {
+ if (dimension[i] < 0)
+ corner[0][i] = center[i] + (-dimension[i]) / 2;
+ else
+ corner[0][i] = center[i] - dimension[i] / 2;
+ }
+}
+
+void Geometry::computeCorner1(void)
+{
+ for (int i = 0; i < 2; i++) {
+ if (dimension[i] < 0)
+ corner[1][i] = corner[0][i] + dimension[i] + 1;
+ else
+ corner[1][i] = corner[0][i] + dimension[i] - 1;
+ }
+}
+
+void Geometry::computeCenter(void)
+{
+ for (int i = 0; i < 2; i++) {
+ if (corner[0][i] > corner[1][i])
+ center[i] = corner[0][i] - (-dimension[i]) / 2;
+ else
+ center[i] = corner[0][i] + dimension[i] / 2;
+ }
+}
+
+void Geometry::computeDimensions(void)
+{
+ for (int i = 0; i < 2; i++) {
+ if (corner[0][i] > corner[1][i])
+ dimension[i] = corner[1][i] - corner[0][i] - 1;
+ else
+ dimension[i] = corner[1][i] - corner[0][i] + 1;
+ }
+}
diff --git a/geometry.h b/geometry.h
new file mode 100644
index 0000000..d328843
--- /dev/null
+++ b/geometry.h
@@ -0,0 +1,57 @@
+#ifndef GEOMETRY_H
+#define GEOMETRY_H
+
+#include
+#include
+#include
+
+class Geometry
+{
+public:
+ enum Format {
+ FormatKeep = -2, // Special value used when setting geometry: don't change current format.
+ FormatUnknown = -1,
+ FormatNone = 0,
+ CenterDimensions = 1,
+ CornerDimensions = 2,
+ Corners = 3,
+ FormatCustom,
+ FormatMax
+ };
+ static QMap geometryIdNameMap;
+ static QMap geometryNameIdMap;
+
+ static const QString &formatName(Geometry::Format id);
+ static Geometry::Format formatId(const QString &name);
+ struct InitStatics { InitStatics(void); };
+ static const InitStatics initStatics;
+ friend struct InitStatics;
+
+ int center[2];
+ int dimension[2];
+ int corner[2][2];
+
+ Geometry(void) { setMax(); }
+ Geometry(const char *s) { set(s); }
+ Geometry(const QString &s) { set(s); }
+ //Geometry(const Geometry &g);
+
+ Geometry::Format set(QString str);
+ void setMax(void);
+ void setCenterDimensions(int cx, int cy, int dx, int dy);
+ void setCornerDimensions(int cx, int cy, int dx, int dy);
+ void setCorners(int c0x, int c0y, int c1x, int c1y);
+ QString getString(Geometry::Format format = Geometry::FormatNone);
+private:
+ const QRegularExpression corners = QRegularExpression("(-?\\d*),(-?\\d*):(-?\\d*),(-?\\d*)");
+ const QRegularExpression centerDimension = QRegularExpression("(-?\\d*),(-?\\d*):(-?\\d*)x(-?\\d*)");
+ const QRegularExpression cornerDimension = QRegularExpression("(-?\\d*)[,:](-?\\d*)[+-](-?\\d*)[+-](-?\\d*)");
+ const QRegularExpression cornerDimensionAlternate = QRegularExpression("(\\d*)x(\\d*)[+]?(-?\\d+)?[+]?(-?\\d+)?");
+ bool adjustCorners(void);
+ void computeCorner0(void);
+ void computeCorner1(void);
+ void computeCenter(void); // Depends dimensions to be correct !
+ void computeDimensions(void);
+};
+
+#endif // GEOMETRY_H
diff --git a/geometrywidget.cpp b/geometrywidget.cpp
index fc1adb1..8b81480 100644
--- a/geometrywidget.cpp
+++ b/geometrywidget.cpp
@@ -2,259 +2,6 @@
#include "ui_geometrywidget.h"
-QMap Geometry::geometryIdNameMap;
-QMap Geometry::geometryNameIdMap;
-const Geometry::InitStatics initStatics;
-
-Geometry::InitStatics::InitStatics()
-{
- Geometry::geometryIdNameMap[Geometry::FormatUnknown] = "unknown";
- Geometry::geometryIdNameMap[Geometry::FormatNone] = "none";
- Geometry::geometryIdNameMap[Geometry::CenterDimensions] = "center-dimensions";
- Geometry::geometryIdNameMap[Geometry::CornerDimensions] = "corner-dimensions";
- Geometry::geometryIdNameMap[Geometry::Corners] = "corners";
- Geometry::geometryIdNameMap[Geometry::FormatCustom] = "custom";
-
- for (int i = Geometry::FormatNone; i < Geometry::FormatMax; i++)
- Geometry::geometryNameIdMap[Geometry::geometryIdNameMap[static_cast(i)]] = static_cast(i);
-
-}
-
-const QString &Geometry::formatName(Geometry::Format id)
-{
- if (id < Geometry::FormatNone || id >= Geometry::FormatMax)
- id = Geometry::FormatUnknown;
- return geometryIdNameMap[id];
-}
-
-Geometry::Format Geometry::formatId(const QString &name)
-{
- if (geometryNameIdMap.find(name) == geometryNameIdMap.end())
- return Geometry::FormatUnknown;
- else
- return geometryNameIdMap[name];
-}
-
-Geometry::Format Geometry::set(QString str)
-{
- qDebug()<<"Trying to detect format of "<x[<+|-xoffset><+|-yoffset>]";
- if(match.lastCapturedIndex() ==2){
- qDebug() << "format is CenterDimensions with center =0,0";
- center[0] = 0;
- center[1] = 0;
- dimension[0] = match.captured(1).toInt();
- dimension[1] = match.captured(2).toInt();
- computeCorner0();
- computeCorner1();
- if (adjustCorners()) {
- // Order is important here!
- computeDimensions();
- computeCenter();
- }
- return Geometry::CenterDimensions;
- }
- else if(match.lastCapturedIndex() ==4){
- qDebug() << "format is CornerDimensions";
- corner[0][0] = match.captured(3).toInt();
- corner[0][1] = match.captured(4).toInt();
- dimension[0] = match.captured(1).toInt();
- dimension[1] = match.captured(2).toInt();
- computeCenter();
- computeCorner1();
- if (adjustCorners()) {
- // Order is important here!
- computeDimensions();
- computeCenter();
- }
- return Geometry::CornerDimensions;
- }
- else return Geometry::FormatCustom;
- }
- else {
- qDebug()<<"Warning: Could not parse format of string: "< 32767) {
- corner[j][i] = 32767;
- adjusted = true;
- }
- }
- }
- return adjusted;
-}
-
-void Geometry::setCenterDimensions(int cx, int cy, int dx, int dy)
-{
- center[0] = cx;
- center[1] = cy;
- dimension[0] = dx;
- dimension[1] = dy;
- computeCorner0();
- computeCorner1();
-}
-
-void Geometry::setCornerDimensions(int cx, int cy, int dx, int dy)
-{
- corner[0][0] = cx;
- corner[0][1] = cy;
- dimension[0] = dx;
- dimension[1] = dy;
- computeCenter();
- computeCorner1();
-}
-
-void Geometry::setCorners(int c0x, int c0y, int c1x, int c1y)
-{
- corner[0][0] = c0x;
- corner[0][1] = c0y;
- corner[1][0] = c1x;
- corner[1][1] = c1y;
- computeDimensions();
- computeCenter();
-}
-
-QString Geometry::getString(Geometry::Format format)
-{
- switch (format) {
- case CenterDimensions:
- if(center[0]==0 && center[1] ==0)
- return QString("%1x%2")
- .arg(dimension[0])
- .arg(dimension[1]);
- return QString("%1,%2:%3x%4")
- .arg(center[0])
- .arg(center[1])
- .arg(dimension[0])
- .arg(dimension[1]);
- break;
- case CornerDimensions:
- return QString("%1,%2+%3+%4")
- .arg(corner[0][0])
- .arg(corner[0][1])
- .arg(dimension[0])
- .arg(dimension[1]);
- break;
- case Corners:
- default:
- return QString("%1,%2:%3,%4")
- .arg(corner[0][0])
- .arg(corner[0][1])
- .arg(corner[1][0])
- .arg(corner[1][1]);
- break;
- }
-
-}
-
-void Geometry::computeCorner0(void)
-{
- for (int i = 0; i < 2; i++) {
- if (dimension[i] < 0)
- corner[0][i] = center[i] + (-dimension[i]) / 2;
- else
- corner[0][i] = center[i] - dimension[i] / 2;
- }
-}
-
-void Geometry::computeCorner1(void)
-{
- for (int i = 0; i < 2; i++) {
- if (dimension[i] < 0)
- corner[1][i] = corner[0][i] + dimension[i] + 1;
- else
- corner[1][i] = corner[0][i] + dimension[i] - 1;
- }
-}
-
-void Geometry::computeCenter(void)
-{
- for (int i = 0; i < 2; i++) {
- if (corner[0][i] > corner[1][i])
- center[i] = corner[0][i] - (-dimension[i]) / 2;
- else
- center[i] = corner[0][i] + dimension[i] / 2;
- }
-}
-
-void Geometry::computeDimensions(void)
-{
- for (int i = 0; i < 2; i++) {
- if (corner[0][i] > corner[1][i])
- dimension[i] = corner[1][i] - corner[0][i] - 1;
- else
- dimension[i] = corner[1][i] - corner[0][i] + 1;
- }
-}
template
static void setQWidgetValue(Q *object, V value)
@@ -345,7 +92,7 @@ bool GeometryWidget::set(const QString geomStr, Geometry::Format requestedFormat
return true;
}
-QString GeometryWidget::getGeometry()
+QString GeometryWidget::getGeometry(void) const
{
Geometry geometry;
Geometry::Format format = getFormat();
@@ -393,7 +140,7 @@ bool GeometryWidget::setFormat(Geometry::Format format)
return true;
}
-Geometry::Format GeometryWidget::getFormat(void)
+Geometry::Format GeometryWidget::getFormat(void) const
{
Geometry::Format format = static_cast(ui->geometryStackedWidget->currentIndex());
// Usage of '0' instead of a symbolic value is intentional. The currentIndex() should never be less than 0.
@@ -419,6 +166,7 @@ void GeometryWidget::on_geometry_CD_CenterX_editingFinished()
ui->geometry_CD_DimensionX->setValue(65536 - 2 * center);
else if (center + (dimension - 1)/2 < -32768)
ui->geometry_CD_DimensionX->setValue(65536 + 2 * (center - 1));
+ emit editingFinished();
}
void GeometryWidget::on_geometry_CD_CenterY_editingFinished()
@@ -429,6 +177,7 @@ void GeometryWidget::on_geometry_CD_CenterY_editingFinished()
ui->geometry_CD_DimensionY->setValue(65536 - 2 * center);
else if (center + (dimension - 1)/2 < -32768)
ui->geometry_CD_DimensionY->setValue(65536 + 2 * (center - 1));
+ emit editingFinished();
}
void GeometryWidget::on_geometry_CD_DimensionX_editingFinished()
@@ -439,6 +188,7 @@ void GeometryWidget::on_geometry_CD_DimensionX_editingFinished()
ui->geometry_CD_DimensionX->setValue(65536 - 2 * center);
else if (center + (dimension - 1)/2 < -32768)
ui->geometry_CD_DimensionX->setValue(65536 + 2 * (center - 1));
+ emit editingFinished();
}
void GeometryWidget::on_geometry_CD_DimensionY_editingFinished()
@@ -449,6 +199,7 @@ void GeometryWidget::on_geometry_CD_DimensionY_editingFinished()
ui->geometry_CD_DimensionY->setValue(65536 - 2 * center);
else if (center + (dimension - 1)/2 < -32768)
ui->geometry_CD_DimensionY->setValue(65536 + 2 * (center - 1));
+ emit editingFinished();
}
void GeometryWidget::on_geometry_C0D_CornerX_editingFinished()
@@ -459,6 +210,7 @@ void GeometryWidget::on_geometry_C0D_CornerX_editingFinished()
ui->geometry_C0D_DimensionX->setValue(32767 + 1 - corner);
else if (corner + dimension - 1 < -32768)
ui->geometry_C0D_DimensionX->setValue(-32768 + 1 - corner);
+ emit editingFinished();
}
void GeometryWidget::on_geometry_C0D_CornerY_editingFinished()
@@ -469,6 +221,7 @@ void GeometryWidget::on_geometry_C0D_CornerY_editingFinished()
ui->geometry_C0D_DimensionY->setValue(32767 + 1 - corner);
else if (corner + dimension - 1 < -32768)
ui->geometry_C0D_DimensionY->setValue(-32768 + 1 - corner);
+ emit editingFinished();
}
void GeometryWidget::on_geometry_C0D_DimensionX_editingFinished()
@@ -479,6 +232,7 @@ void GeometryWidget::on_geometry_C0D_DimensionX_editingFinished()
ui->geometry_C0D_DimensionX->setValue(32767 + 1 - corner);
else if (corner + dimension - 1 < -32768)
ui->geometry_C0D_DimensionX->setValue(-32768 + 1 - corner);
+ emit editingFinished();
}
void GeometryWidget::on_geometry_C0D_DimensionY_editingFinished()
@@ -489,6 +243,7 @@ void GeometryWidget::on_geometry_C0D_DimensionY_editingFinished()
ui->geometry_C0D_DimensionY->setValue(32767 + 1 - corner);
else if (corner + dimension - 1 < -32768)
ui->geometry_C0D_DimensionY->setValue(-32768 + 1 - corner);
+ emit editingFinished();
}
void GeometryWidget::on_geometry_parse_clicked()
diff --git a/geometrywidget.h b/geometrywidget.h
index 2923b27..0a5ffcc 100644
--- a/geometrywidget.h
+++ b/geometrywidget.h
@@ -5,64 +5,19 @@
#include
#include
-class Geometry;
+#include "geometry.h"
+
class GeometryWidget;
namespace Ui {
class GeometryWidget;
}
-class Geometry
-{
-public:
- enum Format {
- FormatKeep = -2, // Special value used when setting geometry: don't change current format.
- FormatUnknown = -1,
- FormatNone = 0,
- CenterDimensions = 1,
- CornerDimensions = 2,
- Corners = 3,
- FormatCustom,
- FormatMax
- };
- static QMap geometryIdNameMap;
- static QMap geometryNameIdMap;
- static const QString &formatName(Geometry::Format id);
- static Geometry::Format formatId(const QString &name);
- struct InitStatics { InitStatics(void); };
- static const InitStatics initStatics;
- friend struct InitStatics;
-
- int center[2];
- int dimension[2];
- int corner[2][2];
-
- Geometry(void) { setMax(); }
- Geometry(const char *s) { set(s); }
- Geometry(const QString &s) { set(s); }
- Geometry(const Geometry &g);
-
- Geometry::Format set(QString str);
- void setMax(void);
- void setCenterDimensions(int cx, int cy, int dx, int dy);
- void setCornerDimensions(int cx, int cy, int dx, int dy);
- void setCorners(int c0x, int c0y, int c1x, int c1y);
- QString getString(Geometry::Format format = Geometry::FormatNone);
-private:
- const QRegularExpression corners = QRegularExpression("(-?\\d*),(-?\\d*):(-?\\d*),(-?\\d*)");
- const QRegularExpression centerDimension = QRegularExpression("(-?\\d*),(-?\\d*):(-?\\d*)x(-?\\d*)");
- const QRegularExpression cornerDimension = QRegularExpression("(-?\\d*)[,:](-?\\d*)[+-](-?\\d*)[+-](-?\\d*)");
- const QRegularExpression cornerDimensionAlternate = QRegularExpression("(\\d*)x(\\d*)[+]?(-?\\d+)?[+]?(-?\\d+)?");
- bool adjustCorners(void);
- void computeCorner0(void);
- void computeCorner1(void);
- void computeCenter(void); // Depends dimensions to be correct !
- void computeDimensions(void);
-};
class GeometryWidget : public QWidget
{
Q_OBJECT
+ Q_PROPERTY(QString geometry READ getGeometry WRITE set NOTIFY editingFinished USER true)
public:
explicit GeometryWidget(QWidget *parent = 0);
@@ -73,9 +28,9 @@ public:
bool setFormat(int i) { return setFormat(static_cast(i)); }
bool setFormat(Geometry::Format format);
bool setFormat(QString formatStr) { return setFormat(Geometry::formatId(formatStr)); }
- Geometry::Format getFormat(void);
+ Geometry::Format getFormat(void) const;
QString getFormatStr(void) { return Geometry::formatName(getFormat()); }
- QString getGeometry();
+ QString getGeometry(void) const;
private slots:
void on_geometryFormat_currentIndexChanged(int index);
@@ -99,6 +54,8 @@ private:
QSpinBox *m_ui_C0D_corner[2];
QSpinBox *m_ui_C0D_dimension[2];
QSpinBox *m_ui_C01_corner[2][2];
+signals:
+ void editingFinished(void);
};
diff --git a/images/desktop.ini b/images/desktop.ini
new file mode 100644
index 0000000..1ccb9a2
--- /dev/null
+++ b/images/desktop.ini
@@ -0,0 +1,3 @@
+[LocalizedFileNames]
+draw-arrow-up.png=@draw-arrow-up.png,0
+draw-text-2.png=@draw-text-2.png,0
diff --git a/images/draw-arrow.svg b/images/draw-arrow.svg
new file mode 100644
index 0000000..4c017e9
--- /dev/null
+++ b/images/draw-arrow.svg
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+
+
+
+ image/svg+xml
+
+
+
+
+
+
+
+
+
diff --git a/images/draw-circle.svg b/images/draw-circle.svg
new file mode 100644
index 0000000..da6f8a7
--- /dev/null
+++ b/images/draw-circle.svg
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ image/svg+xml
+
+
+
+
+
+
+
+
+
diff --git a/images/draw-ellipse.svg b/images/draw-ellipse.svg
new file mode 100644
index 0000000..9362670
--- /dev/null
+++ b/images/draw-ellipse.svg
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ image/svg+xml
+
+
+
+
+
+
+
+
+
diff --git a/images/draw-line.svg b/images/draw-line.svg
new file mode 100644
index 0000000..974eb6e
--- /dev/null
+++ b/images/draw-line.svg
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+ image/svg+xml
+
+
+
+
+
+
+
+
+
diff --git a/images/draw-point.svg b/images/draw-point.svg
new file mode 100644
index 0000000..01bcdd5
--- /dev/null
+++ b/images/draw-point.svg
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ image/svg+xml
+
+
+
+
+
+
+
+
+
diff --git a/images/draw-rectangle.svg b/images/draw-rectangle.svg
new file mode 100644
index 0000000..4398213
--- /dev/null
+++ b/images/draw-rectangle.svg
@@ -0,0 +1,92 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ image/svg+xml
+
+
+
+
+
+
+
+
+
diff --git a/images/draw-text.svg b/images/draw-text.svg
new file mode 100644
index 0000000..074a392
--- /dev/null
+++ b/images/draw-text.svg
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+ image/svg+xml
+
+
+
+
+
+
+ T
+
+
diff --git a/images/draw-unknown.svg b/images/draw-unknown.svg
new file mode 100644
index 0000000..e94b03f
--- /dev/null
+++ b/images/draw-unknown.svg
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+
+
+
+ image/svg+xml
+
+
+
+
+
+
+
+
+
diff --git a/images/drawarrow.png b/images/drawarrow.png
new file mode 100644
index 0000000..4f60478
Binary files /dev/null and b/images/drawarrow.png differ
diff --git a/images/drawcircle.png b/images/drawcircle.png
new file mode 100644
index 0000000..1192047
Binary files /dev/null and b/images/drawcircle.png differ
diff --git a/images/drawline.png b/images/drawline.png
new file mode 100644
index 0000000..ae7801e
Binary files /dev/null and b/images/drawline.png differ
diff --git a/images/drawpoint.png b/images/drawpoint.png
new file mode 100644
index 0000000..9240c68
Binary files /dev/null and b/images/drawpoint.png differ
diff --git a/images/drawrectangle.png b/images/drawrectangle.png
new file mode 100644
index 0000000..691868b
Binary files /dev/null and b/images/drawrectangle.png differ
diff --git a/images/drawtext.png b/images/drawtext.png
new file mode 100644
index 0000000..39f8139
Binary files /dev/null and b/images/drawtext.png differ
diff --git a/mainwindow.cpp b/mainwindow.cpp
index b758cff..d1a1d41 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -78,7 +78,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);
finishUiInitialisation();
readSettings();
- readProfile(currentProfile);
+
progressBar = new QProgressBar(ui->statusBar);
progressBar->setAlignment(Qt::AlignRight);
progressBar->setMaximumSize(180, 19);
@@ -92,11 +92,34 @@ MainWindow::MainWindow(QWidget *parent) :
createLanguageMenu();
createProfilesMenu();
+ ui->figureSelect->addItems(DrawMapFigure::getFigureList());
+
+ drawMapFigureTable = new DrawMapFigureTableModel(this);
+
+ ui->figures_list->setModel(drawMapFigureTable);
+
+ ui->figures_list->setItemDelegateForColumn(0, new FigureDelegate(this));
+ drawMapFigureTableMapper = new QDataWidgetMapper(this);
+ readProfile(currentProfile);
+ drawMapFigureTableMapper->setModel(drawMapFigureTable);
+ drawMapFigureTableMapper->addMapping(ui->figureSelect, 0, "currentIndex");
+ drawMapFigureTableMapper->addMapping(ui->figureUseImageCoordinates,1);
+ drawMapFigureTableMapper->addMapping(ui->figure_point,2);
+ drawMapFigureTableMapper->addMapping(ui->figure_geometry, 3, "geometry");
+ drawMapFigureTableMapper->addMapping(ui->figure_color,4);
+ drawMapFigureTableMapper->addMapping(ui->figure_text,5);
+ connect(ui->figures_list->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
+ drawMapFigureTableMapper, SLOT(setCurrentModelIndex(QModelIndex)));
+ ui->figures_list->setSelectionBehavior(QAbstractItemView::SelectRows);
+ ui->figures_list->resizeColumnsToContents();
QCompleter *completer = new QCompleter(this);
QDirModel *model =new QDirModel(completer);
model->setFilter(QDir::Dirs|QDir::NoDotAndDotDot|QDir::Drives);
completer->setModel(model);
ui->path_World->setCompleter(completer);
+
+
+
}
void MainWindow::finishUiInitialisation(void)
@@ -428,6 +451,9 @@ void MainWindow::on_button_generate_clicked()
}
}
+ // Draw figures tab
+ arguments << drawMapFigureTable->getArguments();
+
ui->button_generate->setDisabled(true);
if(ui->actionExpert_Mode->isChecked()){
@@ -543,6 +569,18 @@ void MainWindow::mapperFinisched(int exit)
ui->statusBar->showMessage(tr("minetestmapper terminated"));
}
else{//something was wrong
+ QMessageBox errBox;
+ errBox.setText(tr("Minetest Mapper failed "));
+ errBox.setSizeGripEnabled(true);
+ errBox.setMinimumSize(800,600);
+ errBox.resize(800,600);
+ errBox.setIcon(QMessageBox::Icon::Critical);
+ errBox.setInformativeText(tr("Exit code: %1").arg(exit));
+ errBox.setDetailedText(ui->statusBar->currentMessage());
+ errBox.setStandardButtons(QMessageBox::Close);
+ errBox.setDefaultButton(QMessageBox::Close);
+ errBox.exec();
+
QMessageBox::critical(this, tr("Minetest Mapper failed"),
tr("ERROR minetestmapper failed "
"Exit code: %1 "
@@ -811,7 +849,10 @@ void MainWindow::writeProfile(QString strProfile)
/*
* Todo: also save and restore other tiles
*/
+ profile.endGroup();
+ profile.beginGroup("drawFigures"); //tab7 Draw Figures
+ profile.setValue("drawMapFigures", drawMapFigureTable->getStringList());
profile.endGroup();
}
@@ -911,6 +952,10 @@ void MainWindow::readProfile(QString strProfile)
ui->tiles_coordinateX->setValue(profile.value("tiles_coordinateX",0).toInt());
ui->tiles_coordinateY->setValue(profile.value("tiles_coordinateY",0).toInt());
profile.endGroup();
+
+ profile.beginGroup("drawFigures");
+ drawMapFigureTable->insertStringList(profile.value("drawMapFigures",QStringList()).toStringList());
+ profile.endGroup();
}
void MainWindow::closeEvent(QCloseEvent *event)
@@ -1187,3 +1232,29 @@ QString MainWindow::getColorsTxtFilePath(QDir *appDir, QDir *worldDir)
}
return retval;
}
+
+void MainWindow::on_button_addFigure_clicked()
+{
+ drawMapFigureTable->insertRow(0);
+}
+
+void MainWindow::on_figure_geometry_apply_clicked()
+{
+ drawMapFigureTableMapper->submit();
+}
+
+void MainWindow::on_button_deleteFigure_clicked()
+{
+ QModelIndexList indexes;
+ while((indexes = ui->figures_list->selectionModel()->selectedIndexes()).size()) {
+ drawMapFigureTable->removeRow(indexes.first().row());
+ }
+}
+
+void MainWindow::on_figureSelect_currentIndexChanged(int index)
+{
+ QStringList lookup = QStringList()<<"figure"
+ << "drawmaparrow" << "drawmapcircle" << "drawmapellipse"
+ << "drawmapline" << "drawmappoint" << "drawmaprectangle" << "drawmaptext";
+ui->figureInformation->scrollToAnchor(lookup.at(index));
+}
diff --git a/mainwindow.h b/mainwindow.h
index 181ad84..0a9487c 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -13,6 +13,8 @@
#include
#include
#include
+#include
+#include
#ifdef Q_OS_WIN
#include
#include
@@ -20,6 +22,9 @@
#include "configdialog.h"
#include "colorstxtassistant.h"
+#include "drawmapfigure.h"
+#include "drawmapfiguretablemodel.h"
+#include "figuredelegate.h"
namespace Ui {
class MainWindow;
@@ -104,6 +109,14 @@ private slots:
void on_actionPreferences_triggered();
+ void on_button_addFigure_clicked();
+
+ void on_figure_geometry_apply_clicked();
+
+ void on_button_deleteFigure_clicked();
+
+ void on_figureSelect_currentIndexChanged(int index);
+
private:
bool portable;
Ui::MainWindow *ui;
@@ -135,6 +148,9 @@ private:
//QSettings profile;
QSettings *settings;
QString getColorsTxtFilePath(QDir *appDir, QDir *worldDir);
+
+ DrawMapFigureTableModel *drawMapFigureTable;
+ QDataWidgetMapper *drawMapFigureTableMapper;
};
#endif // MAINWINDOW_H
diff --git a/mainwindow.ui b/mainwindow.ui
index 0a333ce..5f07ad8 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -894,7 +894,7 @@ Nodes higher than this level will not be drawn. This can be used to avoid floati
0
0
- 503
+ 524
427
@@ -2178,6 +2178,174 @@ Nodes higher than this level will not be drawn. This can be used to avoid floati
+
+
+ Draw figures
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Elements
+
+
+ -
+
+
+ +
+
+
+
+ -
+
+
+ -
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ QAbstractItemView::DragDrop
+
+
+ Qt::MoveAction
+
+
+ QAbstractItemView::SingleSelection
+
+
+ QAbstractItemView::SelectRows
+
+
+ true
+
+
+ 30
+
+
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Properties
+
+
+ -
+
+
+ -
+
+
+ Information:
+
+
+
+ -
+
+
+ -
+
+
+ Figure:
+
+
+
+ -
+
+
+ red
+
+
+
+ -
+
+
+ Color:
+
+
+
+ -
+
+
+ Use Image Coodinates
+
+
+
+ -
+
+
+ -
+
+
+ Text:
+
+
+
+ -
+
+
+ Geometry
+
+
+ -
+
+
+ -
+
+
+ Apply
+
+
+
+
+
+
+ -
+
+
+ Point
+
+
+
+ -
+
+
+ false
+
+
+
+ qrc:/doc/drawfigure.html
+
+
+
+
+
+
+
+
+
MinetestMapper Output
@@ -3092,7 +3260,7 @@ p, li { white-space: pre-wrap; }
-
+
diff --git a/makecolors.cpp b/makecolors.cpp
index b865dba..2695829 100644
--- a/makecolors.cpp
+++ b/makecolors.cpp
@@ -173,12 +173,13 @@ bool MakeColors::writeColorsTxt(const QString file)
{
mi.next();
const QString fullNodeName = mi.key();
- const QString currentMod = fullNodeName.split(':')[0];
+ const QString currentMod = fullNodeName.section(':',0,0,QString::SectionIncludeLeadingSep);
//write a new paragraph
- if(currentMod != lastMod){
- out<images/open.svg
images/icon.svg
images/minetest.svg
+ doc/drawfigure.html
+ images/draw-arrow.svg
+ images/draw-circle.svg
+ images/draw-ellipse.svg
+ images/draw-line.svg
+ images/draw-point.svg
+ images/draw-rectangle.svg
+ images/draw-unknown.svg
+ images/draw-text.svg
+ images/drawarrow.png
+ images/drawcircle.png
+ images/drawline.png
+ images/drawpoint.png
+ images/drawrectangle.png
+ images/drawtext.png