Some more improvements
authorunC0Rr
Wed, 01 Dec 2010 20:45:05 +0300
changeset 4439 27a896207aae
parent 4438 39ab70b37e01
child 4441 bb156179f56e
Some more improvements
tools/drawMapTest/drawmapscene.cpp
tools/drawMapTest/drawmapscene.h
tools/drawMapTest/mainwindow.cpp
tools/drawMapTest/mainwindow.ui
--- a/tools/drawMapTest/drawmapscene.cpp	Wed Dec 01 01:43:55 2010 +0100
+++ b/tools/drawMapTest/drawmapscene.cpp	Wed Dec 01 20:45:05 2010 +0300
@@ -37,7 +37,7 @@
     {
         QPainterPath path = m_currPath->path();
         path.lineTo(mouseEvent->scenePos());
-        paths.last().append(mouseEvent->scenePos().toPoint());
+        paths.first().append(mouseEvent->scenePos().toPoint());
         m_currPath->setPath(path);
 
         emit pathChanged();
@@ -55,7 +55,7 @@
     p += QPointF(0.01, 0.01);
     path.moveTo(p);
     path.lineTo(mouseEvent->scenePos());
-    paths.append(QList<QPoint>() << mouseEvent->scenePos().toPoint());
+    paths.prepend(QList<QPoint>() << mouseEvent->scenePos().toPoint());
     m_currPath->setPath(path);
 
     emit pathChanged();
@@ -65,6 +65,8 @@
 {
     qDebug() << "release" << mouseEvent->scenePos();
 
+    simplifyLast();
+
     m_currPath = 0;
 }
 
@@ -73,7 +75,7 @@
     if(items().size())
     {
         removeItem(items().first());
-        paths.removeLast();
+        paths.removeFirst();
 
         emit pathChanged();
     }
@@ -104,23 +106,40 @@
     return b;
 }
 
-void DrawMapScene::simplify()
+void DrawMapScene::simplifyLast()
 {
-    for(int pit = 0; pit < paths.size(); ++pit)
+    QList<QPoint> points = paths[0];
+
+    QPoint prevPoint = points.first();
+    int i = 1;
+    while(i < points.size())
     {
-        QList<QPoint> points = paths[pit];
+        if(sqr(prevPoint.x() - points[i].x()) + sqr(prevPoint.y() - points[i].y()) < 1000)
+            points.removeAt(i);
+        else
+        {
+            prevPoint = points[i];
+            ++i;
+        }
+    }
 
-        QPoint prevPoint = points.first();
-        int i = 1;
-        while(i < points.size())
-        {
-            if(sqr(prevPoint.x() - points[i].x()) + sqr(prevPoint.y() - points[i].y()) < 1000)
-                points.removeAt(i);
-            else
-                ++i;
-        }
+    paths[0] = points;
+
+
+    // redraw path
+    {
 
-        paths[pit] = points;
+        QPainterPath path;
+        QPointF p = paths[0][0] + QPointF(0.01, 0.01);
+        path.moveTo(p);
+
+        foreach(QPoint p, paths[0])
+            path.lineTo(p);
+
+        QGraphicsPathItem * pathItem = static_cast<QGraphicsPathItem *>(items()[0]);
+        pathItem->setPath(path);
+
+        ++i;
     }
 
     emit pathChanged();
--- a/tools/drawMapTest/drawmapscene.h	Wed Dec 01 01:43:55 2010 +0100
+++ b/tools/drawMapTest/drawmapscene.h	Wed Dec 01 20:45:05 2010 +0300
@@ -20,7 +20,7 @@
 
 public slots:
     void undo();
-    void simplify();
+    void simplifyLast();
 
 private:
     QPen m_pen;
--- a/tools/drawMapTest/mainwindow.cpp	Wed Dec 01 01:43:55 2010 +0100
+++ b/tools/drawMapTest/mainwindow.cpp	Wed Dec 01 20:45:05 2010 +0300
@@ -42,10 +42,12 @@
 
 void MainWindow::scene_pathChanged()
 {
-    ui->plainTextEdit->setPlainText(scene->encode().toBase64());
+    QString str = scene->encode().toBase64();
+    ui->plainTextEdit->setPlainText(str);
+    ui->sbBytes->setValue(str.size());
 }
 
 void MainWindow::on_pbSimplify_clicked()
 {
-    scene->simplify();
+    scene->simplifyLast();
 }
--- a/tools/drawMapTest/mainwindow.ui	Wed Dec 01 01:43:55 2010 +0100
+++ b/tools/drawMapTest/mainwindow.ui	Wed Dec 01 20:45:05 2010 +0300
@@ -14,19 +14,12 @@
    <string>MainWindow</string>
   </property>
   <widget class="QWidget" name="centralWidget">
-   <layout class="QGridLayout" name="gridLayout">
+   <layout class="QGridLayout" name="gridLayout" rowstretch="3,1">
     <item row="0" column="2">
      <widget class="QGraphicsView" name="graphicsView"/>
     </item>
     <item row="1" column="2">
-     <widget class="QPlainTextEdit" name="plainTextEdit">
-      <property name="maximumSize">
-       <size>
-        <width>16777215</width>
-        <height>80</height>
-       </size>
-      </property>
-     </widget>
+     <widget class="QPlainTextEdit" name="plainTextEdit"/>
     </item>
     <item row="0" column="0" rowspan="2">
      <layout class="QVBoxLayout" name="verticalLayout">
@@ -51,9 +44,18 @@
        </spacer>
       </item>
       <item>
-       <widget class="QPushButton" name="pbSimplify">
-        <property name="text">
-         <string>Simplify</string>
+       <widget class="QSpinBox" name="sbBytes">
+        <property name="readOnly">
+         <bool>true</bool>
+        </property>
+        <property name="buttonSymbols">
+         <enum>QAbstractSpinBox::NoButtons</enum>
+        </property>
+        <property name="suffix">
+         <string> bytes</string>
+        </property>
+        <property name="maximum">
+         <number>999999</number>
         </property>
        </widget>
       </item>