Engauge Digitizer  2
MimePointsImport.cpp
1 /******************************************************************************************************
2  * (C) 2017 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "MimePointsImport.h"
8 #include <QApplication>
9 #include <QClipboard>
10 #include "Transformation.h"
11 
13 {
14 }
15 
17 {
18 }
19 
21  QList<QPoint> &points,
22  QList<double> &ordinals) const
23 {
24  // Sanity checking by MimePointsDetector::isMimePointsData has already been done
25 
26  const QString TAB_DELIMITER ("\t");
27 
28  const QClipboard *clipboard = QApplication::clipboard();
29  QString text = clipboard->text ();
30  QStringList lines = text.split ("\n");
31 
32  // Loop through lines
33  int ordinal = 0;
34  for (int i = 0; i < lines.count(); i++) {
35 
36  QString line = lines.at (i);
37 
38  // Skip empty lines
39  QStringList fields = line.split (TAB_DELIMITER);
40  if (!line.trimmed ().isEmpty () &&
41  fields.count () == 2) {
42 
43  QString field0 = fields [0];
44  QString field1 = fields [1];
45  bool ok0, ok1;
46  double value0 = field0.toDouble (&ok0);
47  double value1 = field1.toDouble (&ok1);
48  if (ok0 && ok1) {
49 
50  QPointF pointScreen;
51  transformation.transformRawGraphToScreen (QPointF (value0, value1),
52  pointScreen);
53 
54  points.push_back (pointScreen.toPoint ());
55  ordinals.push_back (ordinal++);
56  }
57  }
58  }
59 }
MimePointsImport()
Default constructor.
virtual ~MimePointsImport()
Destructor.
void transformRawGraphToScreen(const QPointF &pointRaw, QPointF &pointScreen) const
Transform from raw graph coordinates to linear cartesian graph coordinates, then to screen coordinate...
void retrievePoints(const Transformation &transformation, QList< QPoint > &points, QList< double > &ordinals) const
Retrieve points from clipboard.
Affine transformation between screen and graph coordinates, based on digitized axis points...