|
@@ -1,6 +1,9 @@
|
|
|
#include <QFile>
|
|
|
#include <QColor>
|
|
|
#include <QTextStream>
|
|
|
+#include <QJsonObject>
|
|
|
+#include <QJsonArray>
|
|
|
+#include <QJsonDocument>
|
|
|
|
|
|
#include <QDebug>
|
|
|
#include <QStringList>
|
|
@@ -62,42 +65,54 @@ WorkArea::loadImage (const std::string & filename)
|
|
|
liste_points.clear ();
|
|
|
|
|
|
setFixedSize (img->width (), img->height ());
|
|
|
- maxLines = 3;
|
|
|
}
|
|
|
|
|
|
void
|
|
|
WorkArea::loadSL (const std::string & filename)
|
|
|
{
|
|
|
- //qDebug() << resizeFactor << Qt::endl;
|
|
|
liste_points.clear();
|
|
|
- QFile file(QString::fromStdString (filename));
|
|
|
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
|
- return;
|
|
|
-
|
|
|
- QTextStream in(&file);
|
|
|
- while (!in.atEnd()) {
|
|
|
- QString line = in.readLine();
|
|
|
- QStringList parts = line.split(" ");
|
|
|
- liste_points << new QPoint((int)(parts[0].toDouble()*resizeFactor), (int)(parts[1].toDouble()*resizeFactor));
|
|
|
- liste_points << new QPoint((int)(parts[2].toDouble()*resizeFactor), (int)(parts[3].toDouble()*resizeFactor));
|
|
|
- //qDebug() << liste_points.back()->x() << " " << liste_points.back()->y() << Qt::endl;
|
|
|
+
|
|
|
+ QFile fin(QString::fromStdString (filename));
|
|
|
+ fin.open(QIODevice::ReadOnly);
|
|
|
+ QByteArray ba2 = fin.readAll();
|
|
|
+ QJsonParseError parseError;
|
|
|
+ QJsonDocument doc2 = QJsonDocument::fromJson(ba2, &parseError);
|
|
|
+ QJsonArray lines = doc2["lines"].toArray();
|
|
|
+ for(unsigned int i=0; i<lines.size(); i++){
|
|
|
+ QJsonArray line = lines[i].toArray();
|
|
|
+ QJsonArray point1 = line[0].toArray();
|
|
|
+ QJsonArray point2 = line[1].toArray();
|
|
|
+ liste_points << new QPoint((int)(point1[0].toDouble()*resizeFactor), (int)(point1[1].toDouble()*resizeFactor));
|
|
|
+ liste_points << new QPoint((int)(point2[0].toDouble()*resizeFactor), (int)(point2[1].toDouble()*resizeFactor));
|
|
|
}
|
|
|
- file.close();
|
|
|
}
|
|
|
|
|
|
void
|
|
|
WorkArea::saveStrengthLine (const std::string & filename)
|
|
|
{
|
|
|
- QFile file (QString::fromStdString (filename));
|
|
|
-
|
|
|
- if (!file.open (QIODevice::WriteOnly | QIODevice::Text))
|
|
|
- return;
|
|
|
|
|
|
- QTextStream out (&file);
|
|
|
- for (int i = 0; i < liste_points.size () / 2; i++)
|
|
|
- out << (liste_points[i*2]->x ()/resizeFactor) << " " << (liste_points[i*2]->y ()/resizeFactor) << " " << (liste_points[i*2+1]->x ()/resizeFactor) << " " << (liste_points[i*2+1]->y ()/resizeFactor) << "\n";
|
|
|
+ QJsonArray lines;
|
|
|
+
|
|
|
+ for (int i = 0; i < liste_points.size () / 2; i++){
|
|
|
+ QJsonArray line;
|
|
|
+ QJsonArray point1;
|
|
|
+ point1.push_back(liste_points[i*2]->x ()/resizeFactor);
|
|
|
+ point1.push_back(liste_points[i*2]->y ()/resizeFactor);
|
|
|
+ line.push_back(point1);
|
|
|
+ QJsonArray point2;
|
|
|
+ point2.push_back(liste_points[i*2+1]->x ()/resizeFactor);
|
|
|
+ point2.push_back(liste_points[i*2+1]->y ()/resizeFactor);
|
|
|
+ line.push_back(point2);
|
|
|
+
|
|
|
+ lines.push_back(line);
|
|
|
+ }
|
|
|
+
|
|
|
+ root["lines"] = lines;
|
|
|
|
|
|
- file.close ();
|
|
|
+ QByteArray ba = QJsonDocument(root).toJson();
|
|
|
+ QFile fout(QString::fromStdString (filename));
|
|
|
+ fout.open(QIODevice::WriteOnly);
|
|
|
+ fout.write(ba);
|
|
|
}
|
|
|
|
|
|
void
|