Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
MimePointsDetector Class Reference

Detect if text is acceptable for ingestion by MimePoints. More...

#include <MimePointsDetector.h>

Collaboration diagram for MimePointsDetector:
Collaboration graph

Public Member Functions

 MimePointsDetector ()
 Default constructofr. More...
 
virtual ~MimePointsDetector ()
 Destructor. More...
 
bool isMimePointsData (const Transformation &transforation, const QSize &screenSize) const
 Returns true if text is acceptable mime data. More...
 

Detailed Description

Detect if text is acceptable for ingestion by MimePoints.

Definition at line 18 of file MimePointsDetector.h.

Constructor & Destructor Documentation

MimePointsDetector::MimePointsDetector ( )

Default constructofr.

Definition at line 14 of file MimePointsDetector.cpp.

15 {
16 }
MimePointsDetector::~MimePointsDetector ( )
virtual

Destructor.

Definition at line 18 of file MimePointsDetector.cpp.

19 {
20 }

Member Function Documentation

bool MimePointsDetector::isMimePointsData ( const Transformation transforation,
const QSize &  screenSize 
) const

Returns true if text is acceptable mime data.

Definition at line 22 of file MimePointsDetector.cpp.

24 {
25  // A major goal is for this to return as quickly as possible so user interface is not visibly slowed down
26  //
27  // Expected format is:
28  // x Curve1
29  // # #
30  // # #
31  // x Curve 2
32  // # #
33  //
34  // Tests are, ordered from fastest/easiest to slowest/hardest are:
35  // 1) Transformation must be defined
36  // 2) Need at least two lines (one header plus one data point)
37  // 3) Always two tab-delimited columns
38  // 4) Skip lines that have other than 2 numbers
39  // 5) Skip if numbers correspond to points outside of the X/Y coordinates since user will never be able to see them
40 
41  const QString TAB_DELIMITER ("\t");
42 
43  if (!transformation.transformIsDefined()) {
44  return false;
45  }
46 
47  const QClipboard *clipboard = QApplication::clipboard();
48  QString text = clipboard->text ();
49  QStringList lines = text.split ("\n");
50  int i;
51 
52  // Check for two lines
53  if (lines.count () < 2) {
54  return false;
55  }
56 
57  // Check for two columns
58  for (i = 0; i < lines.count(); i++) {
59 
60  // Skip empty lines
61  QString line = lines.at (i);
62  if (!line.trimmed ().isEmpty ()) {
63 
64  QStringList fields = line.split (TAB_DELIMITER);
65  if (fields.count () != 2) {
66  return false;
67  }
68  }
69  }
70 
71  // Check for numbers outside of the legal range
72  for (i = 0; i < lines.count (); i++) {
73 
74  // Skip empty lines
75  QString line = lines.at (i);
76  if (!line.trimmed ().isEmpty ()) {
77 
78  QStringList fields = line.split (TAB_DELIMITER);
79  QString field0 = fields [0];
80  QString field1 = fields [1];
81  bool ok0, ok1;
82  double value0 = field0.toDouble (&ok0);
83  double value1 = field1.toDouble (&ok1);
84  if (ok0 && ok1) {
85 
86  // This is a data point. Check against legal range
87  QPointF pointScreen;
88  transformation.transformRawGraphToScreen (QPointF (value0, value1),
89  pointScreen);
90  if (pointScreen.x() < 0 ||
91  pointScreen.y() < 0 ||
92  pointScreen.x() > screenSize.width() ||
93  pointScreen.y() > screenSize.height ()) {
94 
95  return false;
96  }
97  }
98  }
99  }
100 
101  return true;
102 }
const QString TAB_DELIMITER("\t")

The documentation for this class was generated from the following files: