]> Shamusworld >> Repos - architektonas/blob - src/forms/dimensionlabeleditor.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / forms / dimensionlabeleditor.cpp
1 // dimensionlabeleditor.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/11/2010  Created this file. :-)
15 //
16
17 #include "dimensionlabeleditor.h"
18
19 //#include "arc.h"
20 //#include "drawing.h"
21 //#include "math.h"
22
23 DimensionLabelEditor::DimensionLabelEditor(QWidget * parent/*= NULL*/, Qt::WindowFlags flags/*= 0*/):
24         QWidget(parent, flags)
25 {
26         ui.setupUi(this);
27 }
28
29 DimensionLabelEditor::~DimensionLabelEditor()
30 {
31 }
32
33 void DimensionLabelEditor::setLabel(const QString & l)
34 {
35         int i0, i1a, i1b, i2;
36         QString label, tol1, tol2;
37         bool hasDiameter = false;
38
39         label = l;
40
41         if (label.at(0) == QChar(0x2205) || label.at(0) == QChar(0xF8))
42         {
43                 hasDiameter = true;
44                 ui.bDiameter->setChecked(true);
45         }
46
47         i0 = l.indexOf("\\S");
48
49         if (i0 >= 0)
50         {
51                 i1a = l.indexOf("^ ", i0);
52                 i1b = i1a + 1;
53
54                 if (i1a < 0)
55                         i1a = i1b = l.indexOf('^', i0);
56
57
58                 if (i1a >= 0)
59                 {
60                         i2 = l.indexOf(';', i1b);
61                         label = l.mid(0, i0);
62                         tol1 = l.mid(i0 + 2, i1a - i0 - 2);
63                         tol2 = l.mid(i1b + 1, i2 - i1b - 1);
64                 }
65         }
66
67         ui.leLabel->setText(label.mid(hasDiameter));
68         ui.leTol1->setText(tol1);
69         ui.leTol2->setText(tol2);
70 }
71
72 QString DimensionLabelEditor::getLabel()
73 {
74         QString l = ui.leLabel->text();
75
76         // diameter:
77         if (ui.bDiameter->isChecked())
78         {
79                 if (l.isEmpty())
80                         l = QString("%1<>").arg(QChar(0x2205));
81                 else
82                         l = QChar(0x2205) + l;
83         }
84
85         if (ui.leTol1->text().isEmpty() && ui.leTol2->text().isEmpty())
86                 return l;
87         else
88                 return l + "\\S" + ui.leTol1->text() + "^ " + ui.leTol2->text() + ";";
89 }
90
91 void DimensionLabelEditor::insertSign(const QString & s)
92 {
93         ui.leLabel->insert(s.left(1));
94 }