~showard314/ubuntu/natty/qtiplot/Python2.7_fix

« back to all changes in this revision

Viewing changes to qtiplot/src/MatrixDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gudjon I. Gudjonsson
  • Date: 2007-03-25 12:06:27 UTC
  • Revision ID: james.westby@ubuntu.com-20070325120627-5pvdufddr7i0r74x
Tags: upstream-0.9~rc2
ImportĀ upstreamĀ versionĀ 0.9~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : MatrixDialog.cpp
 
3
    Project              : QtiPlot
 
4
    --------------------------------------------------------------------
 
5
    Copyright            : (C) 2006 by Ion Vasilief, Tilman Hoener zu Siederdissen
 
6
    Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net
 
7
    Description          : Matrix properties dialog
 
8
 
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
13
 *  This program is free software; you can redistribute it and/or modify   *
 
14
 *  it under the terms of the GNU General Public License as published by   *
 
15
 *  the Free Software Foundation; either version 2 of the License, or      *
 
16
 *  (at your option) any later version.                                    *
 
17
 *                                                                         *
 
18
 *  This program is distributed in the hope that it will be useful,        *
 
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
21
 *  GNU General Public License for more details.                           *
 
22
 *                                                                         *
 
23
 *   You should have received a copy of the GNU General Public License     *
 
24
 *   along with this program; if not, write to the Free Software           *
 
25
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 
26
 *   Boston, MA  02110-1301  USA                                           *
 
27
 *                                                                         *
 
28
 ***************************************************************************/
 
29
#include "MatrixDialog.h"
 
30
#include "Matrix.h"
 
31
 
 
32
#include <QPushButton>
 
33
#include <QLabel>
 
34
#include <QComboBox>
 
35
#include <QLayout>
 
36
#include <QGroupBox>
 
37
#include <QSpinBox>
 
38
 
 
39
MatrixDialog::MatrixDialog( QWidget* parent, Qt::WFlags fl )
 
40
    : QDialog( parent, fl ),
 
41
    d_matrix(0)
 
42
{
 
43
    setWindowTitle( tr( "QtiPlot - Matrix Properties" ) );
 
44
 
 
45
        QGridLayout * topLayout = new QGridLayout();
 
46
        QHBoxLayout * bottomLayout = new QHBoxLayout();
 
47
 
 
48
        topLayout->addWidget( new QLabel(tr( "Cell Width" )), 0, 0 );
 
49
        boxColWidth = new QSpinBox();
 
50
        boxColWidth->setRange(0,1000);
 
51
        boxColWidth->setSingleStep(10);
 
52
        topLayout->addWidget( boxColWidth, 0, 1 );
 
53
 
 
54
        topLayout->addWidget( new QLabel(tr( "Data Format" )), 1, 0 );
 
55
        boxFormat = new QComboBox();
 
56
    boxFormat->addItem( tr( "Decimal: 1000" ) );
 
57
        boxFormat->addItem( tr( "Scientific: 1E3" ) );
 
58
 
 
59
        topLayout->addWidget( boxFormat, 1, 1 );
 
60
 
 
61
        topLayout->addWidget( new QLabel( tr( "Numeric Display" )), 2, 0 );
 
62
        boxNumericDisplay = new QComboBox();
 
63
    boxNumericDisplay->addItem( tr( "Default Decimal Digits" ) );
 
64
        boxNumericDisplay->addItem( tr( "Significant Digits=" ) );
 
65
 
 
66
        topLayout->addWidget( boxNumericDisplay, 2, 1 );
 
67
        boxPrecision = new QSpinBox();
 
68
        boxPrecision->setRange(0,100);
 
69
        boxPrecision->setEnabled( false );
 
70
        topLayout->addWidget( boxPrecision, 2, 2 );
 
71
 
 
72
        buttonApply = new QPushButton(tr( "&Apply" ));
 
73
        buttonApply->setAutoDefault( true );
 
74
        bottomLayout->addWidget( buttonApply );
 
75
 
 
76
        buttonOk = new QPushButton(tr( "&OK" ));
 
77
        buttonOk->setAutoDefault( true );
 
78
        buttonOk->setDefault( true );
 
79
        bottomLayout->addWidget( buttonOk );
 
80
 
 
81
        buttonCancel = new QPushButton(tr( "&Cancel" ));
 
82
        buttonCancel->setAutoDefault( true );
 
83
        bottomLayout->addWidget( buttonCancel );
 
84
 
 
85
        QVBoxLayout * mainLayout = new QVBoxLayout(this);
 
86
        mainLayout->addLayout(topLayout);
 
87
        mainLayout->addLayout(bottomLayout);
 
88
 
 
89
        // signals and slots connections
 
90
        connect( buttonApply, SIGNAL( clicked() ), this, SLOT( apply() ) );
 
91
        connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
 
92
        connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( close() ) );
 
93
        connect( boxNumericDisplay, SIGNAL( activated(int) ), this, SLOT( showPrecisionBox(int) ) );
 
94
        connect( boxPrecision, SIGNAL( valueChanged(int) ), this, SLOT( changePrecision(int) ) );
 
95
}
 
96
 
 
97
void MatrixDialog::changePrecision(int precision)
 
98
{
 
99
    if (boxFormat->currentIndex())
 
100
                d_matrix->setNumericFormat('e', precision);
 
101
        else
 
102
                d_matrix->setNumericFormat('f', precision);
 
103
}
 
104
 
 
105
void MatrixDialog::showPrecisionBox(int item)
 
106
{
 
107
        if (item)
 
108
                boxPrecision->setEnabled( true );
 
109
        else
 
110
        {
 
111
                boxPrecision->setValue(6);
 
112
                boxPrecision->setEnabled( false );
 
113
        }
 
114
}
 
115
 
 
116
void MatrixDialog::apply()
 
117
{
 
118
        d_matrix->setColumnsWidth(boxColWidth->value());
 
119
    changePrecision(boxPrecision->value());
 
120
}
 
121
 
 
122
void MatrixDialog::setMatrix(Matrix *m)
 
123
{
 
124
    if (!m)
 
125
        return;
 
126
 
 
127
    d_matrix = m;
 
128
    boxColWidth->setValue(m->columnsWidth());
 
129
 
 
130
    if (QString(m->textFormat()) == "f")
 
131
                boxFormat->setCurrentIndex(0);
 
132
        else
 
133
                boxFormat->setCurrentIndex(1);
 
134
 
 
135
        boxPrecision->setValue(m->precision());
 
136
        if (m->precision() != 6)
 
137
        {
 
138
                boxPrecision->setEnabled( true );
 
139
                boxNumericDisplay->setCurrentIndex(1);
 
140
        }
 
141
 
 
142
    connect(boxColWidth, SIGNAL(valueChanged(int)), d_matrix, SLOT(setColumnsWidth(int)));
 
143
    m->saveCellsToMemory();
 
144
}
 
145
 
 
146
void MatrixDialog::accept()
 
147
{
 
148
        apply();
 
149
        close();
 
150
}
 
151
 
 
152
void MatrixDialog::closeEvent(QCloseEvent* e)
 
153
{
 
154
    if (d_matrix)
 
155
        d_matrix->forgetSavedCells();
 
156
    e->accept();
 
157
}