46
KstMatrixDialogI::KstMatrixDialogI(QWidget* parent,
47
const char* name, bool modal, WFlags fl)
48
: KstMatrixDialog(parent, name, modal, fl) {
51
connect(_zVector, SIGNAL(newVectorCreated(const QString&)),
52
this, SIGNAL(modified()));
54
//signals within the dialog
55
connect(_useMaximum, SIGNAL(clicked()),
56
this, SLOT(updateFields()));
58
setFixedHeight(height());
52
KstMatrixDialogI::KstMatrixDialogI(QWidget* parent, const char* name, bool modal, WFlags fl)
53
: KstDataDialog(parent, name, modal, fl) {
54
_w = new MatrixDialogWidget(_contents);
57
_w->_fileName->completionObject()->setDir(QDir::currentDirPath());
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()));
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()));
74
_w->_configure->setEnabled(false);
75
_fieldCompletion = _w->_field->completionObject();
76
_w->_field->setAutoDeleteCompletionObject(true);
77
setFixedHeight(height());
79
_w->_field->setEnabled(false);
80
_ok->setEnabled(_w->_field->isEnabled());
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()));
91
resize(minimumSizeHint());
92
setFixedHeight(height());
62
96
KstMatrixDialogI::~KstMatrixDialogI() {
66
KstMatrixPtr KstMatrixDialogI::_getPtr(const QString &tagin) {
67
KstMatrixList matrices = kstObjectSubList<KstDataObject, KstMatrix>(KST::dataObjectList);
68
return *matrices.findTag(tagin);
71
100
void KstMatrixDialogI::updateWindow() {
74
void KstMatrixDialogI::_fillFieldsForEdit() {
76
//fill in the tag name
77
_tagName->setText(DP->tagName());
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());
89
_zVector->setSelection(DP->zVectorTag());
95
void KstMatrixDialogI::_fillFieldsForNew() {
104
void KstMatrixDialogI::fillFieldsForEdit() {
105
KstMatrixPtr mp = kst_cast<KstMatrix>(_dp);
107
return; // shouldn't be needed
110
// fill in the common fields
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()));
119
_w->_sourceGroup->hide();
121
KstRMatrixPtr rmp = kst_cast<KstRMatrix>(mp);
123
fillFieldsForRMatrixEdit();
125
fillFieldsForSMatrixEdit();
131
resize(minimumSizeHint());
132
setFixedHeight(height());
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();
145
KstRMatrixPtr rmp = kst_cast<KstRMatrix>(_dp);
147
return; //internal inconsistency
152
// fill in the list of fields
154
if (_fieldCompletion) {
155
_fieldCompletion->clear();
157
// scope for iterator
160
KST::dataSourceList.lock().readLock();
161
KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(rmp->filename());
162
if (it != KST::dataSourceList.end()) {
165
_w->_field->insertStringList(tf->matrixList());
166
if (_fieldCompletion) {
167
_fieldCompletion->insertItems(tf->matrixList());
171
QStringList list = KstDataSource::matrixListForSource(_w->_fileName->url());
172
_w->_field->insertStringList(list);
173
if (_fieldCompletion) {
174
_fieldCompletion->insertItems(list);
177
KST::dataSourceList.lock().readUnlock();
179
_w->_field->setEnabled(_w->_field->count() > 0);
180
_ok->setEnabled(_w->_field->isEnabled());
181
_w->_field->setCurrentText(rmp->field());
183
// fill in the other parameters
184
_w->_fileName->setURL(rmp->filename());
186
_w->_xStart->setValue(rmp->reqXStart());
187
_w->_yStart->setValue(rmp->reqYStart());
188
_w->_xNumSteps->setValue(rmp->reqXNumSteps());
189
_w->_yNumSteps->setValue(rmp->reqYNumSteps());
191
_w->_xStartCountFromEnd->setChecked(rmp->xCountFromEnd());
192
_w->_yStartCountFromEnd->setChecked(rmp->yCountFromEnd());
193
_w->_xNumStepsReadToEnd->setChecked(rmp->xReadToEnd());
194
_w->_yNumStepsReadToEnd->setChecked(rmp->yReadToEnd());
196
_w->_doSkip->setChecked(rmp->doSkip());
197
_w->_skip->setValue(rmp->skip());
198
_w->_doAve->setChecked(rmp->doAverage());
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();
213
KstSMatrixPtr smp = kst_cast<KstSMatrix>(_dp);
215
return; // internal inconsistency
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());
229
void KstMatrixDialogI::fillFieldsForNew() {
97
231
_tagName->setText("<New_Matrix>");
99
//fill some default values for the grid parameters
102
_xStep->setText("1");
103
_yStep->setText("1");
104
_useMaximum->setChecked(true);
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");
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());
257
_w->_gradientX->setChecked(true);
258
_w->_gradientY->setChecked(false);
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);
269
resize(minimumSizeHint());
270
setFixedHeight(height());
108
274
void KstMatrixDialogI::update() {
112
bool KstMatrixDialogI::new_I() {
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)) {
120
(*vector_iter)->readLock();
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();
130
KstMatrixPtr matrix = new KstMatrix(tag_name, *vector_iter,
131
_nX->cleanText().toUInt(),
132
_nY->cleanText().toUInt(),
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
149
bool KstMatrixDialogI::edit_I() {
150
KstVectorList::Iterator vector_iter;
152
/* verify that the matrix name is unique */
153
if (_tagName->text() != DP->tagName() && KST::dataTagNameNotUnique(_tagName->text())) {
156
double minXDouble, minYDouble, xStepDouble, yStepDouble;
157
if (!checkParameters(vector_iter, minXDouble, minYDouble, xStepDouble, yStepDouble)) {
160
(*vector_iter)->readLock();
162
DP->changeParameters(_tagName->text(), *vector_iter,
163
_nX->cleanText().toUInt(),
164
_nY->cleanText().toUInt(),
169
_useMaximum->isChecked());
171
(*vector_iter)->readUnlock();
177
void KstMatrixDialogI::updateFields() {
178
_nX->setEnabled(!_useMaximum->isChecked());
181
bool KstMatrixDialogI::checkParameters(KstVectorList::Iterator &vector_iter,
185
double &yStepDouble) {
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."));
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;
199
(*vector_iter)->readLock();
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();
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();
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();
293
// get the data source and matrix field from datasource
294
KstDataSourcePtr file;
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());
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."));
308
if (file->isEmpty()) {
309
KST::dataSourceList.lock().writeUnlock();
310
KMessageBox::sorry(this, i18n("The file does not contain data."));
313
KST::dataSourceList.append(file);
317
KST::dataSourceList.lock().writeUnlock();
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."));
326
// skipping parameters
327
bool doSkip = _w->_doSkip->isChecked();
328
bool doAve = _w->_doAve->isChecked();
329
int skip = _w->_skip->value();
331
KstRMatrixPtr matrix = new KstRMatrix(file, pField, tag_name,
332
xStart, yStart, xNumSteps, yNumSteps,
333
doAve, doSkip, skip);
335
KST::addMatrixToList(KstMatrixPtr(matrix));
336
emit matrixCreated(KstMatrixPtr(matrix));
337
matrix = 0L; // drop the reference
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();
354
bool xDirection, ok1, ok2, ok3, ok4, ok5, ok6;
355
double zMin, zMax, xStep, yStep, minX, minY;
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();
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);
369
if (!checkParameters(ok3, ok4, ok5, ok6, xStep, yStep)) {
373
KMessageBox::sorry(this, i18n("Invalid gradient bounds. Ensure only decimal values are entered."));
377
KstSMatrixPtr matrix = new KstSMatrix(tag_name, nX, nY, minX, minY, xStep, yStep, zMin, zMax, xDirection);
379
KST::addMatrixToList(KstMatrixPtr(matrix));
381
emit matrixCreated(KstMatrixPtr(matrix));
382
matrix = 0L; // drop the reference
388
bool KstMatrixDialogI::newObject() {
389
if (_w->_readFromSource->isChecked()) {
390
return new_IRMatrix();
392
return new_ISMatrix();
396
bool KstMatrixDialogI::editSingleRMatrix(KstRMatrixPtr rmp) {
397
// get the parameters for this object
398
KstDataSourcePtr file;
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());
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."));
412
if (file->isEmpty()) {
413
KST::dataSourceList.lock().writeUnlock();
414
KMessageBox::sorry(this, i18n("The file does not contain data."));
417
KST::dataSourceList.append(file);
421
KST::dataSourceList.lock().writeUnlock();
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."));
431
file = rmp->dataSource();
432
pField = rmp->field();
435
int xStart, yStart, xNumSteps, yNumSteps;
440
if (_xStartDirty || _xStartCountFromEndDirty) {
441
xStart = _w->_xStartCountFromEnd->isChecked() ? -1 : _w->_xStart->value();
443
xStart = rmp->reqXStart();
445
if (_yStartDirty || _yStartCountFromEndDirty) {
446
yStart = _w->_yStartCountFromEnd->isChecked() ? -1 : _w->_yStart->value();
448
yStart = rmp->reqYStart();
450
if (_xNumStepsDirty || _xNumStepsReadToEndDirty) {
451
xNumSteps = _w->_xNumStepsReadToEnd->isChecked() ? -1 : _w->_xNumSteps->value();
453
xNumSteps = rmp->reqXNumSteps();
455
if (_yNumStepsDirty || _yNumStepsReadToEndDirty) {
456
yNumSteps = _w->_yNumStepsReadToEnd->isChecked() ? -1 : _w->_yNumSteps->value();
458
yNumSteps = rmp->reqYNumSteps();
461
doSkip = _w->_doSkip->isChecked();
463
doSkip = rmp->doSkip();
466
doAve = _w->_doAve->isChecked();
468
doAve = rmp->doAverage();
471
skip = _w->_skip->value();
479
rmp->change(file, pField, rmp->tagName(), xStart, yStart, xNumSteps, yNumSteps, doAve, doSkip, skip);
485
bool KstMatrixDialogI::editSingleSMatrix(KstSMatrixPtr smp) {
486
bool xDirection, ok5, ok6;
487
double gradientZAtMin, gradientZAtMax;
489
double xMin, yMin, xStepSize, yStepSize;
490
bool ok1 = true, ok2 = true, ok3 = true, ok4 = true;
494
xStepSize = _w->_xStep->text().toDouble(&ok1);
496
xStepSize = smp->xStepSize();
500
yStepSize = _w->_yStep->text().toDouble(&ok2);
502
yStepSize = smp->yStepSize();
506
xMin = _w->_minX->text().toDouble(&ok3);
512
yMin = _w->_minY->text().toDouble(&ok4);
517
if (_gradientXDirty || _gradientYDirty) {
518
xDirection = _w->_gradientX->isChecked();
520
xDirection = smp->xDirection();
522
if (_gradientZAtMinDirty) {
523
gradientZAtMin = _w->_gradientZAtMin->text().toDouble(&ok5);
525
gradientZAtMin = smp->gradZMin();
527
if (_gradientZAtMaxDirty) {
528
gradientZAtMax = _w->_gradientZAtMax->text().toDouble(&ok6);
530
gradientZAtMax = smp->gradZMax();
533
nX = _w->_nX->value();
535
nX = smp->xNumSteps();
538
nY = _w->_nY->value();
540
nY = smp->yNumSteps();
544
KMessageBox::sorry(this, i18n("Gradient values are invalid. Ensure only decimal values are entered."));
547
// check the other parameters
548
if (!checkParameters(ok1, ok2, ok3, ok4, xStepSize, yStepSize)) {
553
smp->change(smp->tagName(), nX, nY, xMin, yMin, xStepSize, yStepSize, gradientZAtMin, gradientZAtMax, xDirection);
560
bool KstMatrixDialogI::editSingleObject(KstMatrixPtr mxPtr) {
561
// see if it's an RMatrix
562
KstRMatrixPtr rmp = kst_cast<KstRMatrix>(mxPtr);
564
return editSingleRMatrix(rmp);
566
// are editing an SMatrix
567
KstSMatrixPtr smp = kst_cast<KstSMatrix>(mxPtr);
571
return editSingleSMatrix(smp);
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();
588
_xStartDirty = _w->_xStart->text() != " ";
589
_yStartDirty = _w->_yStart->text() != " ";
590
_xNumStepsDirty = _w->_xNumSteps->text() != " ";
591
_yNumStepsDirty = _w->_yNumSteps->text() != " ";
593
_skipDirty = _w->_skip->text() != " ";
594
_nXDirty = _w->_nX->text() != " ";
595
_nYDirty = _w->_nY->text() != " ";
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();
608
if (!editSingleObject(mxPtr)) {
615
KMessageBox::sorry(this, i18n("Select one or more objects to edit."));
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();
628
mp->setTagName(tag_name);
631
// then edit the object
632
_fileNameDirty = true;
635
_xStartCountFromEndDirty = 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;
655
if (!editSingleObject(mp)) {
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();
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();
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."));
670
if (xStep <= 0 || yStep <= 0) {
671
KMessageBox::sorry(this, i18n("Invalid step size entered. Ensure the step sizes are positive."));
678
void KstMatrixDialogI::populateEditMultiple() {
679
if (kst_cast<KstRMatrix>(_dp)) {
680
populateEditMultipleRMatrix();
682
populateEditMultipleSMatrix();
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);
693
// and clean all the fields
694
_fileNameDirty = 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;
712
_doSkipDirty = false;
720
void KstMatrixDialogI::populateEditMultipleRMatrix() {
721
KstRMatrixList mxList = kstObjectSubList<KstMatrix,KstRMatrix>(KST::matrixList);
722
_editMultipleWidget->_objectList->insertStringList(mxList.tagNames());
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());
730
_w->_yStart->setSpecialValueText(" ");
731
_w->_yStart->setMinValue(_w->_yStart->minValue() - 1);
732
_w->_yStart->setValue(_w->_yStart->minValue());
734
_w->_xNumSteps->setSpecialValueText(" ");
735
_w->_xNumSteps->setMinValue(_w->_xNumSteps->minValue() - 1);
736
_w->_xNumSteps->setValue(_w->_xNumSteps->minValue());
738
_w->_yNumSteps->setSpecialValueText(" ");
739
_w->_yNumSteps->setMinValue(_w->_yNumSteps->minValue() - 1);
740
_w->_yNumSteps->setValue(_w->_yNumSteps->minValue());
742
_w->_skip->setSpecialValueText(" ");
743
_w->_skip->setMinValue(_w->_skip->minValue() - 1);
744
_w->_skip->setValue(_w->_skip->minValue());
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);
765
void KstMatrixDialogI::populateEditMultipleSMatrix() {
766
KstSMatrixList mxList = kstObjectSubList<KstMatrix,KstSMatrix>(KST::matrixList);
767
_editMultipleWidget->_objectList->insertStringList(mxList.tagNames());
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());
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);
799
void KstMatrixDialogI::updateCompletion() {
800
QString current_text = _w->_field->currentText();
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();
808
delete _configWidget;
813
list = ds->matrixList();
814
_w->_field->setEditable(!ds->fieldListIsComplete());
815
_configWidget = ds->configWidget();
817
_w->_field->setEnabled(true);
818
_w->_connect->hide();
819
// _kstDataRange->setAllowTime(ds->supportsTimeConversions());
822
bool complete = false;
823
QString u = _w->_fileName->url();
825
if (QFile::exists(u) && QFileInfo(u).isRelative()) {
828
url = KURL::fromPathOrURL(u);
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);
836
// pretend we're getting the full field list
837
if (list.isEmpty()) {
838
QStringList fullList = KstDataSource::fieldListForSource(u, QString::null, &type, &complete);
841
if (!_inTest || (_inTest && !list.isEmpty())) {
842
_w->_connect->hide();
845
_w->_field->setEditable(!complete);
846
_w->_field->setEnabled(!list.isEmpty());
847
if (!type.isEmpty()) {
848
_configWidget = KstDataSource::configWidgetForSource(u, type);
850
// _kstDataRange->setAllowTime(KstDataSource::supportsTime(u, type));
853
_w->_configure->setEnabled(_configWidget);
855
_fieldCompletion = _w->_field->completionObject();
857
_w->_field->insertStringList(list);
858
if (_fieldCompletion) {
859
_fieldCompletion->clear();
860
_fieldCompletion->insertItems(list);
862
if (!current_text.isEmpty() && (list.contains(current_text) || _w->_field->editable())) {
863
_w->_field->setCurrentText(current_text);
865
_ok->setEnabled(_w->_field->isEnabled() || _editMultipleMode);
869
void KstMatrixDialogI::markSourceAndSave() {
870
assert(_configWidget);
871
KstDataSourcePtr src = static_cast<KstDataSourceConfigWidget*>((QWidget*)_configWidget)->instance();
875
static_cast<KstDataSourceConfigWidget*>((QWidget*)_configWidget)->save();
879
void KstMatrixDialogI::setXStartCountFromEndDirty() {
880
_w->_xStartCountFromEnd->setTristate(false);
881
_xStartCountFromEndDirty = true;
885
void KstMatrixDialogI::setYStartCountFromEndDirty() {
886
_w->_yStartCountFromEnd->setTristate(false);
887
_yStartCountFromEndDirty = true;
891
void KstMatrixDialogI::setXNumStepsReadToEndDirty() {
892
_w->_xNumStepsReadToEnd->setTristate(false);
893
_xNumStepsReadToEndDirty = true;
897
void KstMatrixDialogI::setYNumStepsReadToEndDirty() {
898
_w->_yNumStepsReadToEnd->setTristate(false);
899
_yNumStepsReadToEndDirty = true;
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());
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();
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());
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());
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());
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());
950
void KstMatrixDialogI::setDoSkipDirty() {
951
_w->_doSkip->setTristate(false);
956
void KstMatrixDialogI::setDoAveDirty() {
957
_w->_doAve->setTristate(false);
962
void KstMatrixDialogI::configureSource() {
964
KST::dataSourceList.lock().readLock();
965
KstDataSourcePtr ds = *KST::dataSourceList.findReusableFileName(_w->_fileName->url());
966
KST::dataSourceList.lock().readUnlock();
969
ds = KstDataSource::loadSource(_w->_fileName->url());
970
if (!ds || !ds->isValid()) {
971
_w->_configure->setEnabled(false);
976
assert(_configWidget);
977
KDialogBase *dlg = new KDialogBase(this, "Data Config Dialog", true, i18n("Configure Data Source"));
979
connect(dlg, SIGNAL(okClicked()), _configWidget, SLOT(save()));
980
connect(dlg, SIGNAL(applyClicked()), _configWidget, SLOT(save()));
982
connect(dlg, SIGNAL(okClicked()), this, SLOT(markSourceAndSave()));
983
connect(dlg, SIGNAL(applyClicked()), this, SLOT(markSourceAndSave()));
985
_configWidget->reparent(dlg, QPoint(0, 0));
986
dlg->setMainWidget(_configWidget);
987
_configWidget->setInstance(ds);
988
_configWidget->load();
990
_configWidget->reparent(0L, QPoint(0, 0));
991
dlg->setMainWidget(0L);
993
updateCompletion(); // could be smarter by only running if Ok/Apply clicked
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);
1005
void KstMatrixDialogI::testURL() {
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();
232
1019
#include "kstmatrixdialog_i.moc"
233
1020
// vim: ts=2 sw=2 et