~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/ui/forms/qg_dlgoptionsvariables.cpp

  • Committer: Scott Howard
  • Date: 2014-02-21 19:07:55 UTC
  • Revision ID: showard@debian.org-20140221190755-csjax9wb146hgdq4
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the LibreCAD project, a 2D CAD program
 
4
**
 
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
 
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
 
7
**
 
8
**
 
9
** This file may be distributed and/or modified under the terms of the
 
10
** GNU General Public License version 2 as published by the Free Software 
 
11
** Foundation and appearing in the file gpl-2.0.txt included in the
 
12
** packaging of this file.
 
13
**
 
14
** This program is distributed in the hope that it will be useful,
 
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
** GNU General Public License for more details.
 
18
** 
 
19
** You should have received a copy of the GNU General Public License
 
20
** along with this program; if not, write to the Free Software
 
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
22
**
 
23
** This copyright notice MUST APPEAR in all copies of the script!  
 
24
**
 
25
**********************************************************************/
 
26
#include "qg_dlgoptionsvariables.h"
 
27
 
 
28
/*#include <qvariant.h>
 
29
#include <qmessagebox.h>
 
30
#include "rs_units.h"*/
 
31
#include "rs_filterdxf.h"
 
32
 
 
33
/*
 
34
 *  Constructs a QG_DlgOptionsVariables as a child of 'parent', with the
 
35
 *  name 'name' and widget flags set to 'f'.
 
36
 *
 
37
 *  The dialog will by default be modeless, unless you set 'modal' to
 
38
 *  true to construct a modal dialog.
 
39
 */
 
40
QG_DlgOptionsVariables::QG_DlgOptionsVariables(QWidget* parent, bool modal, Qt::WindowFlags fl)
 
41
    : QDialog(parent, fl)
 
42
{
 
43
    setModal(modal);
 
44
    setupUi(this);
 
45
 
 
46
    init();
 
47
}
 
48
 
 
49
/*
 
50
 *  Destroys the object and frees any allocated resources
 
51
 */
 
52
QG_DlgOptionsVariables::~QG_DlgOptionsVariables()
 
53
{
 
54
    // no need to delete child widgets, Qt does it all for us
 
55
}
 
56
 
 
57
/*
 
58
 *  Sets the strings of the subwidgets using the current
 
59
 *  language.
 
60
 */
 
61
void QG_DlgOptionsVariables::languageChange()
 
62
{
 
63
    retranslateUi(this);
 
64
}
 
65
 
 
66
void QG_DlgOptionsVariables::init() {
 
67
    graphic = NULL;
 
68
 
 
69
    // variables
 
70
    tabVariables->verticalHeader()->hide();
 
71
    tabVariables->verticalHeader()->setFixedWidth(0);
 
72
    tabVariables->setColumnReadOnly(0, true);
 
73
    tabVariables->setColumnReadOnly(1, true);
 
74
    tabVariables->setColumnReadOnly(2, true);
 
75
}
 
76
 
 
77
 
 
78
/**
 
79
 * Sets the graphic and updates the GUI to match the drawing.
 
80
 */
 
81
void QG_DlgOptionsVariables::setGraphic(RS_Graphic* g) {
 
82
    graphic = g;
 
83
    updateVariables();
 
84
}
 
85
 
 
86
 
 
87
/**
 
88
 * Updates the Variables tab from the graphic values.
 
89
 */
 
90
void QG_DlgOptionsVariables::updateVariables() {
 
91
    if (graphic==NULL) {
 
92
        return;
 
93
    }
 
94
    
 
95
    QVector<int> r(tabVariables->numRows());
 
96
    for (int i=0; i<tabVariables->numRows(); ++i) {
 
97
        r[i] = i;
 
98
    }
 
99
    tabVariables->removeRows(r);
 
100
    QHash<QString, RS_Variable>vars = graphic->getVariableDict();
 
101
    QHash<QString, RS_Variable>::iterator it = vars.begin();
 
102
    while (it != vars.end()) {
 
103
        tabVariables->insertRows(tabVariables->numRows(), 1);
 
104
        
 
105
        tabVariables->setText(tabVariables->numRows()-1, 0, it.key());
 
106
        tabVariables->setText(tabVariables->numRows()-1, 1, QString("%1").arg(it.value().getCode()));
 
107
        QString str = "";
 
108
        switch (it.value().getType()) {
 
109
            case RS2::VariableVoid:
 
110
                break;
 
111
            case RS2::VariableInt:
 
112
                str = QString("%1").arg(it.value().getInt());
 
113
                break;
 
114
            case RS2::VariableDouble:
 
115
                str = QString("%1").arg(it.value().getDouble());
 
116
                break;
 
117
            case RS2::VariableString:
 
118
                str = QString("%1").arg(it.value().getString());
 
119
                break;
 
120
            case RS2::VariableVector:
 
121
                str = QString("%1/%2")
 
122
                      .arg(it.value().getVector().x)
 
123
                      .arg(it.value().getVector().y);
 
124
                if (RS_FilterDXF::isVariableTwoDimensional(it.key())==false) {
 
125
                    str+= QString("/%1").arg(it.value().getVector().z);
 
126
                }
 
127
                break;
 
128
        }
 
129
        tabVariables->setText(tabVariables->numRows()-1, 2, str);
 
130
        ++it;
 
131
    }
 
132
}