~ubuntu-branches/ubuntu/karmic/kst/karmic

« back to all changes in this revision

Viewing changes to kst/kst/kstmatrixdialog_i.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-06-30 19:11:30 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630191130-acumuar75bz4puty
Tags: 1.2.1-1ubuntu1
Merge from debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *                                                                         *
16
16
 ***************************************************************************/
17
17
 
 
18
#include <assert.h>
 
19
 
18
20
// include files for Qt
 
21
#include <qbuttongroup.h>
19
22
#include <qcheckbox.h>
 
23
#include <qlistbox.h>
 
24
#include <qradiobutton.h>
20
25
#include <qspinbox.h>
 
26
#include <qvbox.h>
21
27
 
22
28
// include files for KDE
23
29
#include <kcombobox.h>
24
 
#include <kdebug.h>
25
30
#include <kmessagebox.h>
 
31
#include <kurlcompletion.h>
 
32
#include <kurlrequester.h>
26
33
 
27
34
// application specific includes
 
35
#include "editmultiplewidget.h"
 
36
#include "kstmatrixdefaults.h"
28
37
#include "kstmatrixdialog_i.h"
29
38
#include "kstviewwindow.h"
 
39
#include "matrixdialogwidget.h"
30
40
#include "vectorselector.h"
31
41
 
32
 
#define DIALOGTYPE KstMatrixDialogI
33
 
#define DTYPE "Matrix"
34
 
#include "dataobjectdialog.h"
35
 
 
36
42
QGuardedPtr<KstMatrixDialogI> KstMatrixDialogI::_inst;
37
43
 
38
44
KstMatrixDialogI *KstMatrixDialogI::globalInstance() {
43
49
}
44
50
 
45
51
 
46
 
KstMatrixDialogI::KstMatrixDialogI(QWidget* parent,
47
 
                                 const char* name, bool modal, WFlags fl)
48
 
: KstMatrixDialog(parent, name, modal, fl) {
49
 
  Init();
50
 
 
51
 
  connect(_zVector, SIGNAL(newVectorCreated(const QString&)),
52
 
          this, SIGNAL(modified()));
53
 
 
54
 
  //signals within the dialog
55
 
  connect(_useMaximum, SIGNAL(clicked()),
56
 
          this, SLOT(updateFields()));
57
 
 
58
 
  setFixedHeight(height());
59
 
 
 
52
KstMatrixDialogI::KstMatrixDialogI(QWidget* parent, const char* name, bool modal, WFlags fl)
 
53
: KstDataDialog(parent, name, modal, fl) {
 
54
  _w = new MatrixDialogWidget(_contents);
 
55
  setMultiple(true);
 
56
  _inTest = false;
 
57
  _w->_fileName->completionObject()->setDir(QDir::currentDirPath());
 
58
 
 
59
  connect(_w->_readFromSource, SIGNAL(clicked()), this, SLOT(updateEnables()));
 
60
  connect(_w->_generateGradient, SIGNAL(clicked()), this, SLOT(updateEnables()));
 
61
  connect(_w->_xStartCountFromEnd, SIGNAL(clicked()), this, SLOT(xStartCountFromEndClicked()));
 
62
  connect(_w->_yStartCountFromEnd, SIGNAL(clicked()), this, SLOT(yStartCountFromEndClicked()));
 
63
  connect(_w->_xNumStepsReadToEnd, SIGNAL(clicked()), this, SLOT(xNumStepsReadToEndClicked()));
 
64
  connect(_w->_yNumStepsReadToEnd, SIGNAL(clicked()), this, SLOT(yNumStepsReadToEndClicked()));
 
65
  connect(_w->_doSkip, SIGNAL(clicked()), this, SLOT(updateEnables()));
 
66
 
 
67
  _w->_fileName->setMode(KFile::File | KFile::Directory | KFile::ExistingOnly);
 
68
  connect(_w->_fileName, SIGNAL(textChanged(const QString&)), this, SLOT(updateCompletion()));
 
69
  connect(_w->_configure, SIGNAL(clicked()), this, SLOT(configureSource()));
 
70
  connect(_w->_readFromSource, SIGNAL(clicked()), this, SLOT(enableSource()));
 
71
  connect(_w->_generateGradient, SIGNAL(clicked()), this, SLOT(updateEnables()));
 
72
  connect(_w->_connect, SIGNAL(clicked()), this, SLOT(testURL()));
 
73
 
 
74
  _w->_configure->setEnabled(false);
 
75
  _fieldCompletion = _w->_field->completionObject();
 
76
  _w->_field->setAutoDeleteCompletionObject(true);
 
77
  setFixedHeight(height());
 
78
  _configWidget = 0L;
 
79
  _w->_field->setEnabled(false);
 
80
  _ok->setEnabled(_w->_field->isEnabled());
 
81
 
 
82
  // connections for multiple edit mode
 
83
  connect(_w->_xStartCountFromEnd, SIGNAL(clicked()), this, SLOT(setXStartCountFromEndDirty()));
 
84
  connect(_w->_yStartCountFromEnd, SIGNAL(clicked()), this, SLOT(setYStartCountFromEndDirty()));
 
85
  connect(_w->_xNumStepsReadToEnd, SIGNAL(clicked()), this, SLOT(setXNumStepsReadToEndDirty()));
 
86
  connect(_w->_yNumStepsReadToEnd, SIGNAL(clicked()), this, SLOT(setYNumStepsReadToEndDirty()));
 
87
  connect(_w->_doSkip, SIGNAL(clicked()), this, SLOT(setDoSkipDirty()));
 
88
  connect(_w->_doAve, SIGNAL(clicked()), this, SLOT(setDoAveDirty()));
 
89
 
 
90
  adjustSize();
 
91
  resize(minimumSizeHint());
 
92
  setFixedHeight(height());
60
93
}
61
94
 
 
95
 
62
96
KstMatrixDialogI::~KstMatrixDialogI() {
63
 
  DP = 0L;
64
97
}
65
98
 
66
 
KstMatrixPtr KstMatrixDialogI::_getPtr(const QString &tagin) {
67
 
  KstMatrixList matrices = kstObjectSubList<KstDataObject, KstMatrix>(KST::dataObjectList);
68
 
  return *matrices.findTag(tagin);
69
 
}
70
99
 
71
100
void KstMatrixDialogI::updateWindow() {
72
101
}
73
102
 
74
 
void KstMatrixDialogI::_fillFieldsForEdit() {
75
 
  DP->readLock();
76
 
  //fill in the tag name
77
 
  _tagName->setText(DP->tagName());
78
 
 
79
 
  //fill in the other parameters
80
 
  _nX->setValue(DP->xNumSteps());
81
 
  _nY->setValue(DP->yNumSteps());
82
 
  _minX->setText(QString::number(DP->minX()));
83
 
  _minY->setText(QString::number(DP->minY()));
84
 
  _xStep->setText(QString::number(DP->xStepSize()));
85
 
  _yStep->setText(QString::number(DP->yStepSize()));
86
 
  _useMaximum->setChecked(DP->useMaxX());
87
 
 
88
 
  //set the z vector
89
 
  _zVector->setSelection(DP->zVectorTag());
90
 
 
91
 
  updateFields();
92
 
  DP->readUnlock();
93
 
}
94
 
 
95
 
void KstMatrixDialogI::_fillFieldsForNew() {
96
 
  /* set tag name */
 
103
 
 
104
void KstMatrixDialogI::fillFieldsForEdit() {
 
105
  KstMatrixPtr mp = kst_cast<KstMatrix>(_dp);
 
106
  if (!mp) {
 
107
    return; // shouldn't be needed
 
108
  }
 
109
 
 
110
  // fill in the common fields
 
111
  mp->readLock();
 
112
  _tagName->setText(mp->tagName());
 
113
  _w->_minX->setText(QString::number(mp->minX()));
 
114
  _w->_minY->setText(QString::number(mp->minY()));
 
115
  _w->_xStep->setText(QString::number(mp->xStepSize()));
 
116
  _w->_yStep->setText(QString::number(mp->yStepSize()));
 
117
  mp->readUnlock();
 
118
 
 
119
  _w->_sourceGroup->hide();
 
120
 
 
121
  KstRMatrixPtr rmp = kst_cast<KstRMatrix>(mp);
 
122
  if (rmp) {
 
123
    fillFieldsForRMatrixEdit();
 
124
  } else {
 
125
    fillFieldsForSMatrixEdit();
 
126
  }
 
127
 
 
128
  updateEnables();
 
129
 
 
130
  adjustSize();
 
131
  resize(minimumSizeHint());
 
132
  setFixedHeight(height());
 
133
}
 
134
 
 
135
 
 
136
void KstMatrixDialogI::fillFieldsForRMatrixEdit() {
 
137
  // first hide/show the correct widgets
 
138
  _w->_readFromSource->setChecked(true);
 
139
  _w->_generateGradient->setChecked(false);
 
140
  _w->_dataSourceGroup->show();
 
141
  _w->_dataRangeGroup->show();
 
142
  _w->_gradientGroup->hide();
 
143
  _w->_scalingGroup->hide();
 
144
 
 
145
  KstRMatrixPtr rmp = kst_cast<KstRMatrix>(_dp);
 
146
  if (!rmp) {
 
147
    return; //internal inconsistency
 
148
  }
 
149
 
 
150
  rmp->readLock();
 
151
 
 
152
  // fill in the list of fields
 
153
  _w->_field->clear();
 
154
  if (_fieldCompletion) {
 
155
    _fieldCompletion->clear();
 
156
  }
 
157
  // scope for iterator
 
158
  {
 
159
    KstDataSourcePtr tf;
 
160
    KST::dataSourceList.lock().readLock();
 
161
    KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(rmp->filename());
 
162
    if (it != KST::dataSourceList.end()) {
 
163
      tf = *it;
 
164
      tf->readLock();
 
165
      _w->_field->insertStringList(tf->matrixList());
 
166
      if (_fieldCompletion) {
 
167
        _fieldCompletion->insertItems(tf->matrixList());
 
168
      }
 
169
      tf->readUnlock();
 
170
    } else {
 
171
      QStringList list = KstDataSource::matrixListForSource(_w->_fileName->url());
 
172
      _w->_field->insertStringList(list);
 
173
      if (_fieldCompletion) {
 
174
        _fieldCompletion->insertItems(list);
 
175
      }
 
176
    }
 
177
    KST::dataSourceList.lock().readUnlock();
 
178
  }
 
179
  _w->_field->setEnabled(_w->_field->count() > 0);
 
180
  _ok->setEnabled(_w->_field->isEnabled());
 
181
  _w->_field->setCurrentText(rmp->field());
 
182
 
 
183
  // fill in the other parameters
 
184
  _w->_fileName->setURL(rmp->filename());
 
185
 
 
186
  _w->_xStart->setValue(rmp->reqXStart());
 
187
  _w->_yStart->setValue(rmp->reqYStart());
 
188
  _w->_xNumSteps->setValue(rmp->reqXNumSteps());
 
189
  _w->_yNumSteps->setValue(rmp->reqYNumSteps());
 
190
 
 
191
  _w->_xStartCountFromEnd->setChecked(rmp->xCountFromEnd());
 
192
  _w->_yStartCountFromEnd->setChecked(rmp->yCountFromEnd());
 
193
  _w->_xNumStepsReadToEnd->setChecked(rmp->xReadToEnd());
 
194
  _w->_yNumStepsReadToEnd->setChecked(rmp->yReadToEnd());
 
195
 
 
196
  _w->_doSkip->setChecked(rmp->doSkip());
 
197
  _w->_skip->setValue(rmp->skip());
 
198
  _w->_doAve->setChecked(rmp->doAverage());
 
199
 
 
200
  rmp->readUnlock();
 
201
}
 
202
 
 
203
 
 
204
void KstMatrixDialogI::fillFieldsForSMatrixEdit() {
 
205
  // first hide/show the correct widgets
 
206
  _w->_readFromSource->setChecked(false);
 
207
  _w->_generateGradient->setChecked(true);
 
208
  _w->_dataSourceGroup->hide();
 
209
  _w->_dataRangeGroup->hide();
 
210
  _w->_gradientGroup->show();
 
211
  _w->_scalingGroup->show();
 
212
 
 
213
  KstSMatrixPtr smp = kst_cast<KstSMatrix>(_dp);
 
214
  if (!smp) {
 
215
    return; // internal inconsistency
 
216
  }
 
217
 
 
218
  smp->readLock();
 
219
  _w->_gradientX->setChecked(smp->xDirection());
 
220
  _w->_gradientY->setChecked(!smp->xDirection());
 
221
  _w->_gradientZAtMin->setText(QString::number(smp->gradZMin()));
 
222
  _w->_gradientZAtMax->setText(QString::number(smp->gradZMax()));
 
223
  _w->_nX->setValue(smp->xNumSteps());
 
224
  _w->_nY->setValue(smp->yNumSteps());
 
225
  smp->readUnlock();
 
226
}
 
227
 
 
228
 
 
229
void KstMatrixDialogI::fillFieldsForNew() {
 
230
  // set tag name
97
231
  _tagName->setText("<New_Matrix>");
98
232
 
99
 
  //fill some default values for the grid parameters
100
 
  _minX->setText("0");
101
 
  _minY->setText("1");
102
 
  _xStep->setText("1");
103
 
  _yStep->setText("1");
104
 
  _useMaximum->setChecked(true);
105
 
  updateFields();
 
233
  // set defaults using KstMatrixDefaults
 
234
  KST::matrixDefaults.sync();
 
235
  _w->_fileName->setURL(KST::matrixDefaults.dataSource());
 
236
  _w->_minX->setText("0");
 
237
  _w->_minY->setText("1");
 
238
  _w->_xStep->setText("1");
 
239
  _w->_yStep->setText("1");
 
240
  _w->_nX->setValue(100);
 
241
  _w->_nY->setValue(100);
 
242
  _w->_xStart->setValue(KST::matrixDefaults.xStart());
 
243
  _w->_yStart->setValue(KST::matrixDefaults.yStart());
 
244
  _w->_xNumSteps->setValue(KST::matrixDefaults.xNumSteps());
 
245
  _w->_yNumSteps->setValue(KST::matrixDefaults.yNumSteps());
 
246
  _w->_gradientZAtMin->setText("0");
 
247
  _w->_gradientZAtMax->setText("100");
 
248
 
 
249
  _w->_xStartCountFromEnd->setChecked(KST::matrixDefaults.xCountFromEnd());
 
250
  _w->_yStartCountFromEnd->setChecked(KST::matrixDefaults.yCountFromEnd());
 
251
  _w->_xNumStepsReadToEnd->setChecked(KST::matrixDefaults.xReadToEnd());
 
252
  _w->_yNumStepsReadToEnd->setChecked(KST::matrixDefaults.yReadToEnd());
 
253
  _w->_doSkip->setChecked(KST::matrixDefaults.doSkip());
 
254
  _w->_doAve->setChecked(KST::matrixDefaults.doAverage());
 
255
  _w->_skip->setValue(KST::matrixDefaults.skip());
 
256
 
 
257
  _w->_gradientX->setChecked(true);
 
258
  _w->_gradientY->setChecked(false);
 
259
 
 
260
  _w->_sourceGroup->show();
 
261
  _w->_dataSourceGroup->show();
 
262
  _w->_dataRangeGroup->show();
 
263
  _w->_gradientGroup->show();
 
264
  _w->_scalingGroup->show();
 
265
  _w->_readFromSource->setChecked(true);
 
266
 
 
267
  updateEnables();
 
268
  adjustSize();
 
269
  resize(minimumSizeHint());
 
270
  setFixedHeight(height());
106
271
}
107
272
 
 
273
 
108
274
void KstMatrixDialogI::update() {
109
 
   _zVector->update();
 
275
  // nothing to do
110
276
}
111
277
 
112
 
bool KstMatrixDialogI::new_I() {
113
278
 
114
 
  KstVectorList::Iterator vector_iter;
 
279
bool KstMatrixDialogI::new_IRMatrix() {
115
280
  //check the parameters
116
 
  double minXDouble, minYDouble, xStepDouble, yStepDouble;
117
 
  if (!checkParameters(vector_iter, minXDouble, minYDouble, xStepDouble, yStepDouble)) {
118
 
    return false;
119
 
  }
120
 
  (*vector_iter)->readLock();
121
 
 
122
 
  //create a unique name
123
 
  QString tag_name = KST::suggestMatrixName((*vector_iter)->tagName());
124
 
  if (KST::dataTagNameNotUnique(tag_name)) {
125
 
    _tagName->setFocus();
126
 
    (*vector_iter)->readUnlock();
127
 
    return false;
128
 
  }
129
 
 
130
 
  KstMatrixPtr matrix = new KstMatrix(tag_name, *vector_iter,
131
 
                                      _nX->cleanText().toUInt(),
132
 
                                      _nY->cleanText().toUInt(),
133
 
                                      minXDouble,
134
 
                                      minYDouble,
135
 
                                      xStepDouble,
136
 
                                      yStepDouble,
137
 
                                      _useMaximum->isChecked());
138
 
  (*vector_iter)->readUnlock();
139
 
  KST::dataObjectList.lock().writeLock();
140
 
  KST::dataObjectList.append(matrix.data());
141
 
  KST::dataObjectList.lock().writeUnlock();
142
 
  emit matrixCreated(KstMatrixPtr(matrix));
143
 
  matrix = 0L; // drop the reference
144
 
  emit modified();
145
 
 
146
 
  return true;
147
 
}
148
 
 
149
 
bool KstMatrixDialogI::edit_I() {
150
 
  KstVectorList::Iterator vector_iter;
151
 
 
152
 
  /* verify that the matrix name is unique */
153
 
  if (_tagName->text() != DP->tagName() && KST::dataTagNameNotUnique(_tagName->text())) {
154
 
    return false;
155
 
  }
156
 
  double minXDouble, minYDouble, xStepDouble, yStepDouble;
157
 
  if (!checkParameters(vector_iter, minXDouble, minYDouble, xStepDouble, yStepDouble)) {
158
 
    return false;
159
 
  }
160
 
  (*vector_iter)->readLock();
161
 
  DP->writeLock();
162
 
  DP->changeParameters(_tagName->text(), *vector_iter,
163
 
                                      _nX->cleanText().toUInt(),
164
 
                                      _nY->cleanText().toUInt(),
165
 
                                      minXDouble,
166
 
                                      minYDouble,
167
 
                                      xStepDouble,
168
 
                                      yStepDouble,
169
 
                                      _useMaximum->isChecked());
170
 
  DP->writeUnlock();
171
 
  (*vector_iter)->readUnlock();
172
 
 
173
 
  emit modified();
174
 
  return true;
175
 
}
176
 
 
177
 
void KstMatrixDialogI::updateFields() {
178
 
  _nX->setEnabled(!_useMaximum->isChecked());
179
 
}
180
 
 
181
 
bool KstMatrixDialogI::checkParameters(KstVectorList::Iterator &vector_iter,
182
 
                                      double &minXDouble,
183
 
                                      double &minYDouble,
184
 
                                      double &xStepDouble,
185
 
                                      double &yStepDouble) {
186
 
 
187
 
  if (_zVector->selectedVector().isEmpty()){
188
 
    KMessageBox::sorry(this, i18n("Matrix is a 2D grid created from vector", "New matrix not made: define vectors first."));
189
 
    return false;
190
 
  }
191
 
 
192
 
  //find the z vector
193
 
  KST::vectorList.lock().readLock();
194
 
  vector_iter = KST::vectorList.findTag(_zVector->selectedVector());
195
 
  if (vector_iter == KST::vectorList.end()) {
196
 
    kdFatal() << "Bug in kst: the zVector field in matrixDialog refers to "
197
 
              << "a non existant vector...." << endl;
198
 
  }
199
 
  (*vector_iter)->readLock();
200
 
 
201
 
  //basic check to see if parameters are consistent with vector
202
 
  if (!_useMaximum->isChecked() && (*vector_iter)->length() < _nX->cleanText().toInt() * _nY->cleanText().toInt()) {
203
 
    KMessageBox::sorry(this, i18n("The number of elements in the grid is greater than the number of elements in the selected vector.  Please ensure the grid dimensions are correct."));
204
 
    (*vector_iter)->readUnlock();
205
 
    KST::vectorList.lock().readUnlock();
206
 
    return false;
207
 
  }
208
 
 
 
281
  int xStart = _w->_xStartCountFromEnd->isChecked() ? -1 : _w->_xStart->value();
 
282
  int yStart = _w->_yStartCountFromEnd->isChecked() ? -1 : _w->_yStart->value();
 
283
  int xNumSteps = _w->_xNumStepsReadToEnd->isChecked() ? -1 : _w->_xNumSteps->value();
 
284
  int yNumSteps = _w->_yNumStepsReadToEnd->isChecked() ? -1 : _w->_yNumSteps->value();
 
285
 
 
286
  //create a unique name
 
287
  QString tag_name = (_tagName->text() == "<New_Matrix>") ? KST::suggestMatrixName(_w->_field->currentText()) : _tagName->text();
 
288
  if (KstData::self()->matrixTagNameNotUnique(tag_name)) {
 
289
    _tagName->setFocus();
 
290
    return false;
 
291
  }
 
292
 
 
293
  // get the data source and matrix field from datasource
 
294
  KstDataSourcePtr file;
 
295
  QString pField;
 
296
 
 
297
  /* if there is not an active KstFile, create one */
 
298
  KST::dataSourceList.lock().writeLock();
 
299
  KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_w->_fileName->url());
 
300
 
 
301
  if (it == KST::dataSourceList.end()) {
 
302
    file = KstDataSource::loadSource(_w->_fileName->url());
 
303
    if (!file || !file->isValid()) {
 
304
      KST::dataSourceList.lock().writeUnlock();
 
305
      KMessageBox::sorry(this, i18n("The file could not be opened."));
 
306
      return false;
 
307
    }
 
308
    if (file->isEmpty()) {
 
309
      KST::dataSourceList.lock().writeUnlock();
 
310
      KMessageBox::sorry(this, i18n("The file does not contain data."));
 
311
      return false;
 
312
    }
 
313
    KST::dataSourceList.append(file);
 
314
  } else {
 
315
    file = *it;
 
316
  }
 
317
  KST::dataSourceList.lock().writeUnlock();
 
318
 
 
319
  pField = _w->_field->currentText();
 
320
  if (!file->isValidMatrix(pField)) {
 
321
    KMessageBox::sorry(this, i18n("The requested matrix is not defined for the requested file."));
 
322
    file->writeUnlock();
 
323
    return false;
 
324
  }
 
325
 
 
326
  // skipping parameters
 
327
  bool doSkip = _w->_doSkip->isChecked();
 
328
  bool doAve = _w->_doAve->isChecked();
 
329
  int skip = _w->_skip->value();
 
330
 
 
331
  KstRMatrixPtr matrix = new KstRMatrix(file, pField, tag_name,
 
332
                                        xStart, yStart, xNumSteps, yNumSteps,
 
333
                                        doAve, doSkip, skip);
 
334
 
 
335
  KST::addMatrixToList(KstMatrixPtr(matrix));
 
336
  emit matrixCreated(KstMatrixPtr(matrix));
 
337
  matrix = 0L; // drop the reference
 
338
  emit modified();
 
339
 
 
340
  return true;
 
341
}
 
342
 
 
343
 
 
344
bool KstMatrixDialogI::new_ISMatrix() {
 
345
  //create a unique name
 
346
  QString tagPart = _w->_gradientZAtMin->text() + "-" + _w->_gradientZAtMax->text();
 
347
  QString tag_name = (_tagName->text() == "<New_Matrix>") ? KST::suggestMatrixName(tagPart) : _tagName->text();
 
348
  if (KstData::self()->matrixTagNameNotUnique(tag_name)) {
 
349
    _tagName->setFocus();
 
350
    return false;
 
351
  }
 
352
 
 
353
  // get parameters
 
354
  bool xDirection, ok1, ok2, ok3, ok4, ok5, ok6;
 
355
  double zMin, zMax, xStep, yStep, minX, minY;
 
356
  int nX, nY;
 
357
 
 
358
  xDirection = _w->_gradientX->isChecked();
 
359
  zMin = _w->_gradientZAtMin->text().toDouble(&ok1);
 
360
  zMax = _w->_gradientZAtMax->text().toDouble(&ok2);
 
361
  nX = _w->_nX->value();
 
362
  nY = _w->_nY->value();
 
363
 
 
364
  xStep = _w->_xStep->text().toDouble(&ok3);
 
365
  yStep = _w->_yStep->text().toDouble(&ok4);
 
366
  minX = _w->_minX->text().toDouble(&ok5);
 
367
  minY = _w->_minY->text().toDouble(&ok6);
 
368
 
 
369
  if (!checkParameters(ok3, ok4, ok5, ok6, xStep, yStep)) {
 
370
    return false;
 
371
  }
 
372
  if (!ok1 || !ok2) {
 
373
    KMessageBox::sorry(this, i18n("Invalid gradient bounds.  Ensure only decimal values are entered."));
 
374
    return false;
 
375
  }
 
376
 
 
377
  KstSMatrixPtr matrix = new KstSMatrix(tag_name, nX, nY, minX, minY, xStep, yStep, zMin, zMax, xDirection);
 
378
 
 
379
  KST::addMatrixToList(KstMatrixPtr(matrix));
 
380
 
 
381
  emit matrixCreated(KstMatrixPtr(matrix));
 
382
  matrix = 0L; // drop the reference
 
383
  emit modified();
 
384
  return true;
 
385
}
 
386
 
 
387
 
 
388
bool KstMatrixDialogI::newObject() {
 
389
  if (_w->_readFromSource->isChecked()) {
 
390
    return new_IRMatrix();
 
391
  }
 
392
  return new_ISMatrix();
 
393
}
 
394
 
 
395
 
 
396
bool KstMatrixDialogI::editSingleRMatrix(KstRMatrixPtr rmp) {
 
397
  // get the parameters for this object
 
398
  KstDataSourcePtr file;
 
399
  QString pField;
 
400
  if (_fileNameDirty) {
 
401
    /* if there is not an active KstFile, create one */
 
402
    KST::dataSourceList.lock().writeLock();
 
403
    KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(_w->_fileName->url());
 
404
 
 
405
    if (it == KST::dataSourceList.end()) {
 
406
      file = KstDataSource::loadSource(_w->_fileName->url());
 
407
      if (!file || !file->isValid()) {
 
408
        KST::dataSourceList.lock().writeUnlock();
 
409
        KMessageBox::sorry(this, i18n("The file could not be opened."));
 
410
        return false;
 
411
      }
 
412
      if (file->isEmpty()) {
 
413
        KST::dataSourceList.lock().writeUnlock();
 
414
        KMessageBox::sorry(this, i18n("The file does not contain data."));
 
415
        return false;
 
416
      }
 
417
      KST::dataSourceList.append(file);
 
418
    } else {
 
419
      file = *it;
 
420
    }
 
421
    KST::dataSourceList.lock().writeUnlock();
 
422
 
 
423
    pField = _w->_field->currentText();
 
424
    if (!file->isValidMatrix(pField)) {
 
425
      KMessageBox::sorry(this, i18n("The requested field is not defined for the requested file."));
 
426
      file->writeUnlock();
 
427
      return false;
 
428
    }
 
429
  } else {
 
430
    rmp->readLock();
 
431
    file = rmp->dataSource();
 
432
    pField = rmp->field();
 
433
    rmp->readUnlock();
 
434
  }
 
435
  int xStart, yStart, xNumSteps, yNumSteps;
 
436
  bool doSkip, doAve;
 
437
  int skip;
 
438
 
 
439
  rmp->readLock();
 
440
  if (_xStartDirty || _xStartCountFromEndDirty) {
 
441
    xStart = _w->_xStartCountFromEnd->isChecked() ? -1 : _w->_xStart->value();
 
442
  } else {
 
443
    xStart = rmp->reqXStart();
 
444
  }
 
445
  if (_yStartDirty || _yStartCountFromEndDirty) {
 
446
    yStart = _w->_yStartCountFromEnd->isChecked() ? -1 : _w->_yStart->value();
 
447
  } else {
 
448
    yStart = rmp->reqYStart();
 
449
  }
 
450
  if (_xNumStepsDirty || _xNumStepsReadToEndDirty) {
 
451
    xNumSteps = _w->_xNumStepsReadToEnd->isChecked() ? -1 : _w->_xNumSteps->value();
 
452
  } else {
 
453
    xNumSteps = rmp->reqXNumSteps();
 
454
  }
 
455
  if (_yNumStepsDirty || _yNumStepsReadToEndDirty) {
 
456
    yNumSteps = _w->_yNumStepsReadToEnd->isChecked() ? -1 : _w->_yNumSteps->value();
 
457
  } else {
 
458
    yNumSteps = rmp->reqYNumSteps();
 
459
  }
 
460
  if (_doSkipDirty) {
 
461
    doSkip = _w->_doSkip->isChecked();
 
462
  } else {
 
463
    doSkip = rmp->doSkip();
 
464
  }
 
465
  if (_doAveDirty) {
 
466
    doAve = _w->_doAve->isChecked();
 
467
  } else {
 
468
    doAve = rmp->doAverage();
 
469
  }
 
470
  if (_skipDirty) {
 
471
    skip = _w->_skip->value();
 
472
  } else {
 
473
    skip = rmp->skip();
 
474
  }
 
475
 
 
476
  rmp->readUnlock();
 
477
 
 
478
  rmp->writeLock();
 
479
  rmp->change(file, pField, rmp->tagName(), xStart, yStart, xNumSteps, yNumSteps, doAve, doSkip, skip);
 
480
  rmp->writeUnlock();
 
481
  return true;
 
482
}
 
483
 
 
484
 
 
485
bool KstMatrixDialogI::editSingleSMatrix(KstSMatrixPtr smp) {
 
486
  bool xDirection, ok5, ok6;
 
487
  double gradientZAtMin, gradientZAtMax;
 
488
  int nX, nY;
 
489
  double xMin, yMin, xStepSize, yStepSize;
 
490
  bool ok1 = true, ok2 = true, ok3 = true, ok4 = true;
 
491
 
 
492
  smp->readLock();
 
493
  if (_xStepDirty) {
 
494
    xStepSize = _w->_xStep->text().toDouble(&ok1);
 
495
  } else {
 
496
    xStepSize = smp->xStepSize();
 
497
  }
 
498
 
 
499
  if (_yStepDirty) {
 
500
    yStepSize = _w->_yStep->text().toDouble(&ok2);
 
501
  } else {
 
502
    yStepSize = smp->yStepSize();
 
503
  }
 
504
 
 
505
  if (_minXDirty) {
 
506
    xMin = _w->_minX->text().toDouble(&ok3);
 
507
  } else {
 
508
    xMin = smp->minX();
 
509
  }
 
510
 
 
511
  if (_minYDirty) {
 
512
    yMin = _w->_minY->text().toDouble(&ok4);
 
513
  } else {
 
514
    yMin = smp->minY();
 
515
  }
 
516
 
 
517
  if (_gradientXDirty || _gradientYDirty) {
 
518
    xDirection = _w->_gradientX->isChecked();
 
519
  } else {
 
520
    xDirection = smp->xDirection();
 
521
  }
 
522
  if (_gradientZAtMinDirty) {
 
523
    gradientZAtMin = _w->_gradientZAtMin->text().toDouble(&ok5);
 
524
  } else {
 
525
    gradientZAtMin = smp->gradZMin();
 
526
  }
 
527
  if (_gradientZAtMaxDirty) {
 
528
    gradientZAtMax = _w->_gradientZAtMax->text().toDouble(&ok6);
 
529
  } else {
 
530
    gradientZAtMax = smp->gradZMax();
 
531
  }
 
532
  if (_nXDirty) {
 
533
    nX = _w->_nX->value();
 
534
  } else {
 
535
    nX = smp->xNumSteps();
 
536
  }
 
537
  if (_nYDirty) {
 
538
    nY = _w->_nY->value();
 
539
  } else {
 
540
    nY = smp->yNumSteps();
 
541
  }
 
542
  smp->readUnlock();
 
543
  if (!ok5 || !ok6) {
 
544
    KMessageBox::sorry(this, i18n("Gradient values are invalid.  Ensure only decimal values are entered."));
 
545
    return false;
 
546
  }
 
547
  // check the other parameters
 
548
  if (!checkParameters(ok1, ok2, ok3, ok4, xStepSize, yStepSize)) {
 
549
    return false;
 
550
  }
 
551
 
 
552
  smp->writeLock();
 
553
  smp->change(smp->tagName(), nX, nY, xMin, yMin, xStepSize, yStepSize, gradientZAtMin, gradientZAtMax, xDirection);
 
554
  smp->writeUnlock();
 
555
 
 
556
  return true;
 
557
}
 
558
 
 
559
 
 
560
bool KstMatrixDialogI::editSingleObject(KstMatrixPtr mxPtr) {
 
561
  // see if it's an RMatrix
 
562
  KstRMatrixPtr rmp = kst_cast<KstRMatrix>(mxPtr);
 
563
  if (rmp) {
 
564
    return editSingleRMatrix(rmp);
 
565
  } else {
 
566
    // are editing an SMatrix
 
567
    KstSMatrixPtr smp = kst_cast<KstSMatrix>(mxPtr);
 
568
    if (!smp) {
 
569
      return false;
 
570
    }
 
571
    return editSingleSMatrix(smp);
 
572
  }
 
573
  return true;
 
574
}
 
575
 
 
576
 
 
577
bool KstMatrixDialogI::editObject() {
 
578
  // if editing multiple objects, edit each one
 
579
  if (_editMultipleMode) {
 
580
    _fileNameDirty = !_w->_fileName->url().isEmpty();
 
581
    _gradientZAtMinDirty = !_w->_gradientZAtMin->text().isEmpty();
 
582
    _gradientZAtMaxDirty = !_w->_gradientZAtMax->text().isEmpty();
 
583
    _minXDirty = !_w->_minX->text().isEmpty();
 
584
    _minYDirty = !_w->_minY->text().isEmpty();
 
585
    _yStepDirty = !_w->_yStep->text().isEmpty();
 
586
    _xStepDirty = !_w->_xStep->text().isEmpty();
 
587
 
 
588
    _xStartDirty = _w->_xStart->text() != " ";
 
589
    _yStartDirty = _w->_yStart->text() != " ";
 
590
    _xNumStepsDirty = _w->_xNumSteps->text() != " ";
 
591
    _yNumStepsDirty = _w->_yNumSteps->text() != " ";
 
592
 
 
593
    _skipDirty = _w->_skip->text() != " ";
 
594
    _nXDirty = _w->_nX->text() != " ";
 
595
    _nYDirty = _w->_nY->text() != " ";
 
596
 
 
597
    bool didEdit = false;
 
598
    for (uint i = 0; i < _editMultipleWidget->_objectList->count(); i++) {
 
599
      if (_editMultipleWidget->_objectList->isSelected(i)) {
 
600
        // get the pointer to the object
 
601
        KST::matrixList.lock().readLock();
 
602
        KstMatrixPtr mxPtr = *KST::matrixList.findTag(_editMultipleWidget->_objectList->text(i));
 
603
        KST::matrixList.lock().readUnlock();
 
604
        if (!mxPtr) {
 
605
          return false;
 
606
        }
 
607
 
 
608
        if (!editSingleObject(mxPtr)) {
 
609
          return false;
 
610
        }
 
611
        didEdit = true;
 
612
      }
 
613
    }
 
614
    if (!didEdit) {
 
615
      KMessageBox::sorry(this, i18n("Select one or more objects to edit."));
 
616
      return false;
 
617
    }
 
618
  } else {
 
619
    KstMatrixPtr mp = kst_cast<KstMatrix>(_dp);
 
620
    // verify that the curve name is unique
 
621
    QString tag_name = _tagName->text();
 
622
    if (!mp || (tag_name != mp->tagName() && KstData::self()->dataTagNameNotUnique(tag_name))) {
 
623
      _tagName->setFocus();
 
624
      return false;
 
625
    }
 
626
 
 
627
    mp->writeLock();
 
628
    mp->setTagName(tag_name);
 
629
    mp->writeUnlock();
 
630
 
 
631
    // then edit the object
 
632
    _fileNameDirty = true;
 
633
    _fieldDirty = true;
 
634
    _xStartDirty = true;
 
635
    _xStartCountFromEndDirty = true;
 
636
    _yStartDirty = true;
 
637
    _yStartCountFromEndDirty = true;
 
638
    _xNumStepsDirty = true;
 
639
    _xNumStepsReadToEndDirty = true;
 
640
    _yNumStepsDirty = true;
 
641
    _yNumStepsReadToEndDirty = true;
 
642
    _gradientXDirty = true;
 
643
    _gradientYDirty = true;
 
644
    _gradientZAtMinDirty = true;
 
645
    _gradientZAtMaxDirty = true;
 
646
    _minXDirty = true;
 
647
    _minYDirty = true;
 
648
    _xStepDirty = true;
 
649
    _yStepDirty = true;
 
650
    _doSkipDirty = true;
 
651
    _skipDirty = true;
 
652
    _doAveDirty = true;
 
653
    _nXDirty = true;
 
654
    _nYDirty = true;
 
655
    if (!editSingleObject(mp)) {
 
656
      return false;
 
657
    }
 
658
  }
 
659
  emit modified();
 
660
  return true;
 
661
}
 
662
 
 
663
 
 
664
bool KstMatrixDialogI::checkParameters(bool ok1, bool ok2, bool ok3, bool ok4, double xStep, double yStep) {
209
665
    //check parameters
210
 
  bool ok1, ok2, ok3, ok4;
211
 
  minXDouble = _minX->text().toDouble(&ok1);
212
 
  minYDouble = _minY->text().toDouble(&ok2);
213
 
  xStepDouble = _xStep->text().toDouble(&ok3);
214
 
  yStepDouble = _yStep->text().toDouble(&ok4);
215
666
  if (!(ok1 && ok2 && ok3 && ok4)) {
216
 
    KMessageBox::sorry(this, i18n("One or more grid parameters have invalid values.  Please ensure only decimal values are entered."));
217
 
    (*vector_iter)->readUnlock();
218
 
    KST::vectorList.lock().readUnlock();
219
 
    return false;
220
 
  }
221
 
  if (xStepDouble <= 0 || yStepDouble <= 0) {
222
 
    KMessageBox::sorry(this, i18n("Invalid step size entered.  Please ensure the step sizes are positive."));
223
 
    (*vector_iter)->readUnlock();
224
 
    KST::vectorList.lock().readUnlock();
225
 
    return false;
226
 
  }
227
 
  (*vector_iter)->readUnlock();
228
 
  KST::vectorList.lock().readUnlock();
 
667
    KMessageBox::sorry(this, i18n("One or more grid parameters have invalid values.  Ensure that only decimal values are entered."));
 
668
    return false;
 
669
  }
 
670
  if (xStep <= 0 || yStep <= 0) {
 
671
    KMessageBox::sorry(this, i18n("Invalid step size entered.  Ensure the step sizes are positive."));
 
672
    return false;
 
673
  }
229
674
  return true;
230
675
}
231
676
 
 
677
 
 
678
void KstMatrixDialogI::populateEditMultiple() {
 
679
  if (kst_cast<KstRMatrix>(_dp)) {
 
680
    populateEditMultipleRMatrix();
 
681
  } else {
 
682
    populateEditMultipleSMatrix();
 
683
  }
 
684
 
 
685
  // also intermediate state for multiple edit
 
686
  _w->_minX->setText("");
 
687
  _w->_minY->setText("");
 
688
  _w->_xStep->setText("");
 
689
  _w->_yStep->setText("");
 
690
  _tagName->setText("");
 
691
  _tagName->setEnabled(false);
 
692
 
 
693
  // and clean all the fields
 
694
  _fileNameDirty = false;
 
695
  _fieldDirty = false;
 
696
  _xStartDirty = false;
 
697
  _xStartCountFromEndDirty = false;
 
698
  _yStartDirty = false;
 
699
  _yStartCountFromEndDirty = false;
 
700
  _xNumStepsDirty = false;
 
701
  _xNumStepsReadToEndDirty = false;
 
702
  _yNumStepsDirty = false;
 
703
  _yNumStepsReadToEndDirty = false;
 
704
  _gradientXDirty = false;
 
705
  _gradientYDirty = false;
 
706
  _gradientZAtMinDirty = false;
 
707
  _gradientZAtMaxDirty = false;
 
708
  _minXDirty = false;
 
709
  _minYDirty = false;
 
710
  _xStepDirty = false;
 
711
  _yStepDirty = false;
 
712
  _doSkipDirty = false;
 
713
  _skipDirty = false;
 
714
  _doAveDirty = false;
 
715
  _nXDirty = false;
 
716
  _nYDirty = false;
 
717
}
 
718
 
 
719
 
 
720
void KstMatrixDialogI::populateEditMultipleRMatrix() {
 
721
  KstRMatrixList mxList = kstObjectSubList<KstMatrix,KstRMatrix>(KST::matrixList);
 
722
  _editMultipleWidget->_objectList->insertStringList(mxList.tagNames());
 
723
 
 
724
  // intermediate state for multiple edit
 
725
  _w->_fileName->clear();
 
726
  _w->_xStart->setSpecialValueText(" ");
 
727
  _w->_xStart->setMinValue(_w->_xStart->minValue() - 1);
 
728
  _w->_xStart->setValue(_w->_xStart->minValue());
 
729
 
 
730
  _w->_yStart->setSpecialValueText(" ");
 
731
  _w->_yStart->setMinValue(_w->_yStart->minValue() - 1);
 
732
  _w->_yStart->setValue(_w->_yStart->minValue());
 
733
 
 
734
  _w->_xNumSteps->setSpecialValueText(" ");
 
735
  _w->_xNumSteps->setMinValue(_w->_xNumSteps->minValue() - 1);
 
736
  _w->_xNumSteps->setValue(_w->_xNumSteps->minValue());
 
737
 
 
738
  _w->_yNumSteps->setSpecialValueText(" ");
 
739
  _w->_yNumSteps->setMinValue(_w->_yNumSteps->minValue() - 1);
 
740
  _w->_yNumSteps->setValue(_w->_yNumSteps->minValue());
 
741
 
 
742
  _w->_skip->setSpecialValueText(" ");
 
743
  _w->_skip->setMinValue(_w->_skip->minValue() - 1);
 
744
  _w->_skip->setValue(_w->_skip->minValue());
 
745
 
 
746
  _w->_doSkip->setTristate(true);
 
747
  _w->_doSkip->setNoChange();
 
748
  _w->_doAve->setTristate(true);
 
749
  _w->_doAve->setNoChange();
 
750
  _w->_xStartCountFromEnd->setTristate(true);
 
751
  _w->_xStartCountFromEnd->setNoChange();
 
752
  _w->_yStartCountFromEnd->setTristate(true);
 
753
  _w->_yStartCountFromEnd->setNoChange();
 
754
  _w->_xNumStepsReadToEnd->setTristate(true);
 
755
  _w->_xNumStepsReadToEnd->setNoChange();
 
756
  _w->_yNumStepsReadToEnd->setTristate(true);
 
757
  _w->_yNumStepsReadToEnd->setNoChange();
 
758
  _w->_xStart->setEnabled(true);
 
759
  _w->_xNumSteps->setEnabled(true);
 
760
  _w->_yStart->setEnabled(true);
 
761
  _w->_yNumSteps->setEnabled(true);
 
762
}
 
763
 
 
764
 
 
765
void KstMatrixDialogI::populateEditMultipleSMatrix() {
 
766
  KstSMatrixList mxList = kstObjectSubList<KstMatrix,KstSMatrix>(KST::matrixList);
 
767
  _editMultipleWidget->_objectList->insertStringList(mxList.tagNames());
 
768
 
 
769
  // intermediate state for multiple edit
 
770
  _w->_gradientZAtMin->setText("");
 
771
  _w->_gradientZAtMax->setText("");
 
772
  _w->_nX->setSpecialValueText(" ");
 
773
  _w->_nX->setMinValue(_w->_nX->minValue() - 1);
 
774
  _w->_nX->setValue(_w->_nX->minValue());
 
775
  _w->_nY->setSpecialValueText(" ");
 
776
  _w->_nY->setMinValue(_w->_nY->minValue() - 1);
 
777
  _w->_nY->setValue(_w->_nY->minValue());
 
778
}
 
779
 
 
780
 
 
781
void KstMatrixDialogI::cleanup() {
 
782
  if (_editMultipleMode) {
 
783
    _w->_xStart->setSpecialValueText(QString::null);
 
784
    _w->_xStart->setMinValue(_w->_xStart->minValue() + 1);
 
785
    _w->_yStart->setSpecialValueText(QString::null);
 
786
    _w->_yStart->setMinValue(_w->_yStart->minValue() + 1);
 
787
    _w->_xNumSteps->setSpecialValueText(QString::null);
 
788
    _w->_xNumSteps->setMinValue(_w->_xNumSteps->minValue() + 1);
 
789
    _w->_yNumSteps->setSpecialValueText(QString::null);
 
790
    _w->_yNumSteps->setMinValue(_w->_yNumSteps->minValue() + 1);
 
791
    _w->_skip->setSpecialValueText(QString::null);
 
792
    _w->_skip->setMinValue(_w->_skip->minValue() + 1);
 
793
    _w->_nX->setSpecialValueText(QString::null);
 
794
    _w->_nY->setSpecialValueText(QString::null);
 
795
  }
 
796
}
 
797
 
 
798
 
 
799
void KstMatrixDialogI::updateCompletion() {
 
800
  QString current_text = _w->_field->currentText();
 
801
  _w->_field->clear();
 
802
 
 
803
  /* update filename list and ll axes combo boxes */
 
804
  KST::dataSourceList.lock().readLock();
 
805
  KstDataSourcePtr ds = *KST::dataSourceList.findReusableFileName(_w->_fileName->url());
 
806
  KST::dataSourceList.lock().readUnlock();
 
807
 
 
808
  delete _configWidget;
 
809
  _configWidget = 0L;
 
810
  QStringList list;
 
811
  if (ds) {
 
812
    ds->readLock();
 
813
    list = ds->matrixList();
 
814
    _w->_field->setEditable(!ds->fieldListIsComplete());
 
815
    _configWidget = ds->configWidget();
 
816
    ds->readUnlock();
 
817
    _w->_field->setEnabled(true);
 
818
    _w->_connect->hide();
 
819
  //  _kstDataRange->setAllowTime(ds->supportsTimeConversions());
 
820
  } else {
 
821
    QString type;
 
822
    bool complete = false;
 
823
    QString u = _w->_fileName->url();
 
824
    KURL url;
 
825
    if (QFile::exists(u) && QFileInfo(u).isRelative()) {
 
826
      url.setPath(u);
 
827
    } else {
 
828
      url = KURL::fromPathOrURL(u);
 
829
    }
 
830
 
 
831
    if (!_inTest && !url.isLocalFile() && url.protocol() != "file" && !url.protocol().isEmpty()) {
 
832
      _w->_connect->show();
 
833
    } else if (url.isValid()) {
 
834
      list = KstDataSource::matrixListForSource(u, QString::null, &type, &complete);
 
835
 
 
836
      // pretend we're getting the full field list
 
837
      if (list.isEmpty()) {
 
838
        QStringList fullList = KstDataSource::fieldListForSource(u, QString::null, &type, &complete);
 
839
      }
 
840
 
 
841
      if (!_inTest || (_inTest && !list.isEmpty())) {
 
842
        _w->_connect->hide();
 
843
      }
 
844
    }
 
845
    _w->_field->setEditable(!complete);
 
846
    _w->_field->setEnabled(!list.isEmpty());
 
847
    if (!type.isEmpty()) {
 
848
      _configWidget = KstDataSource::configWidgetForSource(u, type);
 
849
    }
 
850
//    _kstDataRange->setAllowTime(KstDataSource::supportsTime(u, type));
 
851
  }
 
852
 
 
853
  _w->_configure->setEnabled(_configWidget);
 
854
 
 
855
  _fieldCompletion = _w->_field->completionObject();
 
856
 
 
857
  _w->_field->insertStringList(list);
 
858
  if (_fieldCompletion) {
 
859
    _fieldCompletion->clear();
 
860
    _fieldCompletion->insertItems(list);
 
861
  }
 
862
  if (!current_text.isEmpty() && (list.contains(current_text) || _w->_field->editable())) {
 
863
    _w->_field->setCurrentText(current_text);
 
864
  }
 
865
  _ok->setEnabled(_w->_field->isEnabled() || _editMultipleMode);
 
866
}
 
867
 
 
868
 
 
869
void KstMatrixDialogI::markSourceAndSave() {
 
870
  assert(_configWidget);
 
871
  KstDataSourcePtr src = static_cast<KstDataSourceConfigWidget*>((QWidget*)_configWidget)->instance();
 
872
  if (src) {
 
873
    src->disableReuse();
 
874
  }
 
875
  static_cast<KstDataSourceConfigWidget*>((QWidget*)_configWidget)->save();
 
876
}
 
877
 
 
878
 
 
879
void KstMatrixDialogI::setXStartCountFromEndDirty() {
 
880
  _w->_xStartCountFromEnd->setTristate(false);
 
881
  _xStartCountFromEndDirty = true;
 
882
}
 
883
 
 
884
 
 
885
void KstMatrixDialogI::setYStartCountFromEndDirty() {
 
886
  _w->_yStartCountFromEnd->setTristate(false);
 
887
  _yStartCountFromEndDirty = true;
 
888
}
 
889
 
 
890
 
 
891
void KstMatrixDialogI::setXNumStepsReadToEndDirty() {
 
892
  _w->_xNumStepsReadToEnd->setTristate(false);
 
893
  _xNumStepsReadToEndDirty = true;
 
894
}
 
895
 
 
896
 
 
897
void KstMatrixDialogI::setYNumStepsReadToEndDirty() {
 
898
  _w->_yNumStepsReadToEnd->setTristate(false);
 
899
  _yNumStepsReadToEndDirty = true;
 
900
}
 
901
 
 
902
 
 
903
void KstMatrixDialogI::updateEnables() {
 
904
  _w->_dataSourceGroup->setEnabled(_w->_readFromSource->isChecked());
 
905
  _w->_dataRangeGroup->setEnabled(_w->_readFromSource->isChecked());
 
906
  _w->_gradientGroup->setEnabled(_w->_generateGradient->isChecked());
 
907
  _w->_scalingGroup->setEnabled(_w->_generateGradient->isChecked());
 
908
  _ok->setEnabled(_ok->isEnabled() || !_w->_readFromSource->isChecked());
 
909
 
 
910
  // also some enables for the checkboxes and spinboxes
 
911
  if (_w->_dataRangeGroup->isEnabled()) {
 
912
    _w->_skip->setEnabled(_w->_doSkip->isChecked());
 
913
    _w->_doAve->setEnabled(_w->_doSkip->isChecked());
 
914
    xStartCountFromEndClicked();
 
915
    xNumStepsReadToEndClicked();
 
916
    yStartCountFromEndClicked();
 
917
    yNumStepsReadToEndClicked();
 
918
  }
 
919
}
 
920
 
 
921
 
 
922
void KstMatrixDialogI::xStartCountFromEndClicked() {
 
923
  _w->_xNumStepsReadToEnd->setChecked(_w->_xNumStepsReadToEnd->isChecked() && !_w->_xStartCountFromEnd->isChecked());
 
924
  _w->_xStart->setEnabled(!_w->_xStartCountFromEnd->isChecked());
 
925
  _w->_xNumSteps->setEnabled(!_w->_xNumStepsReadToEnd->isChecked());
 
926
}
 
927
 
 
928
 
 
929
void KstMatrixDialogI::xNumStepsReadToEndClicked() {
 
930
  _w->_xStartCountFromEnd->setChecked(_w->_xStartCountFromEnd->isChecked() && !_w->_xNumStepsReadToEnd->isChecked());
 
931
  _w->_xNumSteps->setEnabled(!_w->_xNumStepsReadToEnd->isChecked());
 
932
  _w->_xStart->setEnabled(!_w->_xStartCountFromEnd->isChecked());
 
933
}
 
934
 
 
935
 
 
936
void KstMatrixDialogI::yStartCountFromEndClicked() {
 
937
  _w->_yNumStepsReadToEnd->setChecked(_w->_yNumStepsReadToEnd->isChecked() && !_w->_yStartCountFromEnd->isChecked());
 
938
  _w->_yStart->setEnabled(!_w->_yStartCountFromEnd->isChecked());
 
939
  _w->_yNumSteps->setEnabled(!_w->_yNumStepsReadToEnd->isChecked());
 
940
}
 
941
 
 
942
 
 
943
void KstMatrixDialogI::yNumStepsReadToEndClicked() {
 
944
  _w->_yStartCountFromEnd->setChecked(_w->_yStartCountFromEnd->isChecked() && !_w->_yNumStepsReadToEnd->isChecked());
 
945
  _w->_yNumSteps->setEnabled(!_w->_yNumStepsReadToEnd->isChecked());
 
946
  _w->_yStart->setEnabled(!_w->_yStartCountFromEnd->isChecked());
 
947
}
 
948
 
 
949
 
 
950
void KstMatrixDialogI::setDoSkipDirty() {
 
951
  _w->_doSkip->setTristate(false);
 
952
  _doSkipDirty = true;
 
953
}
 
954
 
 
955
 
 
956
void KstMatrixDialogI::setDoAveDirty() {
 
957
  _w->_doAve->setTristate(false);
 
958
  _doAveDirty = true;
 
959
}
 
960
 
 
961
 
 
962
void KstMatrixDialogI::configureSource() {
 
963
  bool isNew = false;
 
964
  KST::dataSourceList.lock().readLock();
 
965
  KstDataSourcePtr ds = *KST::dataSourceList.findReusableFileName(_w->_fileName->url());
 
966
  KST::dataSourceList.lock().readUnlock();
 
967
  if (!ds) {
 
968
    isNew = true;
 
969
    ds = KstDataSource::loadSource(_w->_fileName->url());
 
970
    if (!ds || !ds->isValid()) {
 
971
      _w->_configure->setEnabled(false);
 
972
      return;
 
973
    }
 
974
  }
 
975
 
 
976
  assert(_configWidget);
 
977
  KDialogBase *dlg = new KDialogBase(this, "Data Config Dialog", true, i18n("Configure Data Source"));
 
978
  if (isNew) {
 
979
    connect(dlg, SIGNAL(okClicked()), _configWidget, SLOT(save()));
 
980
    connect(dlg, SIGNAL(applyClicked()), _configWidget, SLOT(save()));
 
981
  } else {
 
982
    connect(dlg, SIGNAL(okClicked()), this, SLOT(markSourceAndSave()));
 
983
    connect(dlg, SIGNAL(applyClicked()), this, SLOT(markSourceAndSave()));
 
984
  }
 
985
  _configWidget->reparent(dlg, QPoint(0, 0));
 
986
  dlg->setMainWidget(_configWidget);
 
987
  _configWidget->setInstance(ds);
 
988
  _configWidget->load();
 
989
  dlg->exec();
 
990
  _configWidget->reparent(0L, QPoint(0, 0));
 
991
  dlg->setMainWidget(0L);
 
992
  delete dlg;
 
993
  updateCompletion(); // could be smarter by only running if Ok/Apply clicked
 
994
}
 
995
 
 
996
 
 
997
void KstMatrixDialogI::enableSource() {
 
998
  _w->_dataSourceGroup->setEnabled(true);
 
999
  _w->_gradientGroup->setEnabled(false);
 
1000
  _ok->setEnabled(_w->_field->isEnabled());
 
1001
  _w->_dataRangeGroup->setEnabled(true);
 
1002
}
 
1003
 
 
1004
 
 
1005
void KstMatrixDialogI::testURL() {
 
1006
  _inTest = true;
 
1007
  updateCompletion();
 
1008
  _inTest = false;
 
1009
}
 
1010
 
 
1011
 
 
1012
KstObjectPtr KstMatrixDialogI::findObject(const QString& name) {
 
1013
  KST::matrixList.lock().readLock();
 
1014
  KstObjectPtr o = (*KST::matrixList.findTag(name)).data();
 
1015
  KST::matrixList.lock().readUnlock();
 
1016
  return o;
 
1017
}
 
1018
 
232
1019
#include "kstmatrixdialog_i.moc"
233
1020
// vim: ts=2 sw=2 et