File: Show_point_dialog.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (92 lines) | stat: -rw-r--r-- 2,358 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "Show_point_dialog.h"
#include "ui_Show_point_dialog.h"

#include <QClipboard>
#include <QRegularExpression>

Show_point_dialog::Show_point_dialog(QWidget* parent)
  : QDialog(parent)
  , ui(new Ui::Show_point_dialog)
  , m_has_correct_coordinates(false)
{
  ui->setupUi(this);

  QClipboard::Mode mode = QClipboard::Selection;
  while(true) {
    QString clipboard_text = QApplication::clipboard()->text(mode);

    interprete_string(clipboard_text);
    if(m_has_correct_coordinates) {
      ui->lineEdit->setText(clipboard_text);
      ui->lineEdit->selectAll();
      break;
    } else {
      interprete_string(ui->lineEdit->text());
    }
    if(mode == QClipboard::Selection) mode = QClipboard::Clipboard;
    else break;
  }

  connect(ui->lineEdit, SIGNAL(textChanged(const QString&)),
          this, SLOT(interprete_string(const QString&)));
}

Show_point_dialog::~Show_point_dialog()
{
  delete ui;
}

void Show_point_dialog::interprete_string(const QString& string)
{
  QString double_re("([-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?)");
  QString not_double_char_re("[^0-9-+.eE]");
  QString full_re = QString("^")
    + not_double_char_re + "*"
    + double_re
    + not_double_char_re + "+"
    + double_re
    + not_double_char_re + "+"
    + double_re
    + "(" + not_double_char_re + "*"
    + "|" + not_double_char_re + "+" + double_re
    + ")"
    + "$";

  QRegularExpression re(full_re);
  QRegularExpressionMatch match = re.match(string);
  if(match.hasMatch()) {
    // const double x = re.cap(1).toDouble();
    // const double y = re.cap(2).toDouble();
    // const double z = re.cap(3).toDouble();
    ui->coord_x->setText(QString(match.captured(1)));
    ui->coord_y->setText(QString(match.captured(2)));
    ui->coord_z->setText(QString(match.captured(3)));
    m_has_correct_coordinates = true;
  }
  else {
    ui->coord_x->setText(QString());
    ui->coord_y->setText(QString());
    ui->coord_z->setText(QString());
    m_has_correct_coordinates = false;
  }
}

double Show_point_dialog::get_x() const
{
  return ui->coord_x->text().toDouble();
}

double Show_point_dialog::get_y() const
{
  return ui->coord_y->text().toDouble();
}

double Show_point_dialog::get_z() const
{
  return ui->coord_z->text().toDouble();
}

bool Show_point_dialog::has_correct_coordinates() const
{
  return m_has_correct_coordinates;
}