ScaleDetails.cpp 23.6 KB
Newer Older
1
2
3
4
//---------------------------
// Includes
//--------------------------

5
#include "ScaleDetails.h"
6
#include "ApplicationWindow.h"
Roman Tolchenov's avatar
Roman Tolchenov committed
7
#include "MantidQtWidgets/Common/DoubleSpinBox.h"
8

Roman Tolchenov's avatar
Roman Tolchenov committed
9
#include "MantidQtWidgets/Common/qwt_compat.h"
10
#include "Plot.h"
Roman Tolchenov's avatar
Roman Tolchenov committed
11
#include "MantidQtWidgets/Common/ScaleEngine.h"
12

13
14
#include "MantidKernel/Logger.h"

15
16
#include <QSpinBox>
#include <QComboBox>
17
18
#include <QGroupBox>
#include <QRadioButton>
19
#include <QDateTimeEdit>
20
21
22

namespace {
Mantid::Kernel::Logger g_log("ScaleDetails");
23
}
24

25
26
/** The constructor for a single set of widgets containing parameters for the
* scale of an axis.
Keith Brown's avatar
Keith Brown committed
27
28
29
*  @param app :: the containing application window
*  @param graph :: the graph the dialog is settign the options for
*  @param mappedaxis :: the QwtPlot::axis value that corresponds to this axis
30
31
*  @param parent :: the QWidget that acts as this widget's parent in the
* hierachy
Keith Brown's avatar
Keith Brown committed
32
*/
33
34
35
ScaleDetails::ScaleDetails(ApplicationWindow *app, Graph *graph, int mappedaxis,
                           QWidget *parent)
    : QWidget(parent) {
Keith Brown's avatar
Keith Brown committed
36
37
  m_app = app;
  m_graph = graph;
38
39
  m_mappedaxis = mappedaxis;
  m_initialised = false;
40
41
  m_modified = false;

42
43
  QGroupBox *middleBox = new QGroupBox(QString());
  QGridLayout *middleLayout = new QGridLayout(middleBox);
44

45
46
  m_lblStart = new QLabel(tr("From"));
  middleLayout->addWidget(m_lblStart, 0, 0);
Keith Brown's avatar
Keith Brown committed
47
48
  m_dspnStart = new DoubleSpinBox();
  m_dspnStart->setLocale(m_app->locale());
49
  m_dspnStart->setDecimals(m_app->d_graphing_digits);
Keith Brown's avatar
Keith Brown committed
50
  middleLayout->addWidget(m_dspnStart, 0, 1);
51
52
  connect(m_dspnStart, SIGNAL(valueChanged(double)), this,
          SLOT(recalcStepMin()));
53

Keith Brown's avatar
Keith Brown committed
54
55
56
57
  m_dteStartDateTime = new QDateTimeEdit();
  m_dteStartDateTime->setCalendarPopup(true);
  middleLayout->addWidget(m_dteStartDateTime, 0, 1);
  m_dteStartDateTime->hide();
58

Keith Brown's avatar
Keith Brown committed
59
60
61
  m_timStartTime = new QTimeEdit();
  middleLayout->addWidget(m_timStartTime, 0, 1);
  m_timStartTime->hide();
62

63
64
  m_lblEnd = new QLabel(tr("To"));
  middleLayout->addWidget(m_lblEnd, 1, 0);
Keith Brown's avatar
Keith Brown committed
65
66
  m_dspnEnd = new DoubleSpinBox();
  m_dspnEnd->setLocale(m_app->locale());
67
  m_dspnEnd->setDecimals(m_app->d_graphing_digits);
Keith Brown's avatar
Keith Brown committed
68
  middleLayout->addWidget(m_dspnEnd, 1, 1);
69
70
  connect(m_dspnStart, SIGNAL(valueChanged(double)), this,
          SLOT(recalcStepMin()));
Keith Brown's avatar
Keith Brown committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84

  m_dteEndDateTime = new QDateTimeEdit();
  m_dteEndDateTime->setCalendarPopup(true);
  middleLayout->addWidget(m_dteEndDateTime, 1, 1);
  m_dteEndDateTime->hide();

  m_timEndTime = new QTimeEdit();
  middleLayout->addWidget(m_timEndTime, 1, 1);
  m_timEndTime->hide();

  m_lblScaleTypeLabel = new QLabel(tr("Type"));
  m_cmbScaleType = new QComboBox();
  m_cmbScaleType->addItem(tr("linear"));
  m_cmbScaleType->addItem(tr("logarithmic"));
85
  m_cmbScaleType->addItem(tr("power"));
Keith Brown's avatar
Keith Brown committed
86
87
88
  middleLayout->addWidget(m_lblScaleTypeLabel, 2, 0);
  middleLayout->addWidget(m_cmbScaleType, 2, 1);

89
90
91
92
93
94
95
  m_lblN = new QLabel(tr("n ="));
  m_dspnN = new DoubleSpinBox();
  m_dspnN->setLocale(m_app->locale());
  m_dspnN->setDecimals(m_app->d_graphing_digits);
  middleLayout->addWidget(m_lblN, 3, 0);
  middleLayout->addWidget(m_dspnN, 3, 1);

96
97
  m_lblWarn = new QLabel(tr(
      "Ensure axis and data ranges are\ncompatible with chosen axis scale."));
98
99
100
  middleLayout->addWidget(m_lblWarn, 4, 0, 1, 2);
  m_lblWarn->setVisible(false);

Keith Brown's avatar
Keith Brown committed
101
102
103
104
  m_chkInvert = new QCheckBox();
  m_chkInvert->setText(tr("Inverted"));
  m_chkInvert->setChecked(false);
  middleLayout->addWidget(m_chkInvert, 3, 1);
105
  middleLayout->setRowStretch(4, 1);
106
107
108
109
  // TODO: This is disabled because the code handling it's value is commented
  // out
  // Hence the value has no effect on the plot
  // THis was a UX issue in ticket #8198
110
  m_chkInvert->setVisible(false);
111

Keith Brown's avatar
Keith Brown committed
112
113
114
  m_grpAxesBreaks = new QGroupBox(tr("Show Axis &Break"));
  m_grpAxesBreaks->setCheckable(true);
  m_grpAxesBreaks->setChecked(false);
115

116
  QGridLayout *breaksLayout = new QGridLayout(m_grpAxesBreaks);
Keith Brown's avatar
Keith Brown committed
117
  m_chkBreakDecoration = new QCheckBox(tr("Draw Break &Decoration"));
Dan Nixon's avatar
Dan Nixon committed
118
  breaksLayout->addWidget(m_chkBreakDecoration, 0, 0, 1, 3);
119
120

  breaksLayout->addWidget(new QLabel(tr("From")), 1, 0);
Keith Brown's avatar
Keith Brown committed
121
122
123
124
  m_dspnBreakStart = new DoubleSpinBox();
  m_dspnBreakStart->setLocale(m_app->locale());
  m_dspnBreakStart->setDecimals(m_app->d_decimal_digits);
  breaksLayout->addWidget(m_dspnBreakStart, 1, 1);
125
126

  breaksLayout->addWidget(new QLabel(tr("To")), 2, 0);
Keith Brown's avatar
Keith Brown committed
127
128
129
130
  m_dspnBreakEnd = new DoubleSpinBox();
  m_dspnBreakEnd->setLocale(m_app->locale());
  m_dspnBreakEnd->setDecimals(m_app->d_decimal_digits);
  breaksLayout->addWidget(m_dspnBreakEnd, 2, 1);
131
132

  breaksLayout->addWidget(new QLabel(tr("Position")), 3, 0);
Keith Brown's avatar
Keith Brown committed
133
  m_spnBreakPosition = new QSpinBox();
134
  /* m_spnBreakPosition->setSuffix(" (" + tr("% of Axis Length") + ")"); */
Keith Brown's avatar
Keith Brown committed
135
  breaksLayout->addWidget(m_spnBreakPosition, 3, 1);
136
  breaksLayout->addWidget(new QLabel(tr("(% of Axis Length)")), 3, 2);
137
138

  breaksLayout->addWidget(new QLabel(tr("Width")), 4, 0);
Keith Brown's avatar
Keith Brown committed
139
  m_spnBreakWidth = new QSpinBox();
140
  /* m_spnBreakWidth->setSuffix(" (" + tr("pixels") + ")"); */
Keith Brown's avatar
Keith Brown committed
141
  breaksLayout->addWidget(m_spnBreakWidth, 4, 1);
142
  breaksLayout->addWidget(new QLabel(tr("(pixels)")), 4, 2);
143

Keith Brown's avatar
Keith Brown committed
144
145
  m_chkLog10AfterBreak = new QCheckBox(tr("&Log10 Scale After Break"));
  breaksLayout->addWidget(m_chkLog10AfterBreak, 0, 3);
146

147
  breaksLayout->addWidget(new QLabel(tr("Step Before Break")), 1, 3);
Keith Brown's avatar
Keith Brown committed
148
  m_dspnStepBeforeBreak = new DoubleSpinBox();
149
150
151
  m_dspnStepBeforeBreak->addSpecialTextMapping("Guess", 0.0);
  m_dspnStepBeforeBreak->addSpecialTextMapping("guess", 0.0);
  m_dspnStepBeforeBreak->addSpecialTextMapping("GUESS", 0.0);
Keith Brown's avatar
Keith Brown committed
152
153
154
155
  m_dspnStepBeforeBreak->setMinimum(0.0);
  m_dspnStepBeforeBreak->setSpecialValueText(tr("Guess"));
  m_dspnStepBeforeBreak->setLocale(m_app->locale());
  m_dspnStepBeforeBreak->setDecimals(m_app->d_decimal_digits);
156
  breaksLayout->addWidget(m_dspnStepBeforeBreak, 1, 4);
157

158
  breaksLayout->addWidget(new QLabel(tr("Step After Break")), 2, 3);
Keith Brown's avatar
Keith Brown committed
159
  m_dspnStepAfterBreak = new DoubleSpinBox();
160
161
162
  m_dspnStepAfterBreak->addSpecialTextMapping("Guess", 0.0);
  m_dspnStepAfterBreak->addSpecialTextMapping("guess", 0.0);
  m_dspnStepAfterBreak->addSpecialTextMapping("GUESS", 0.0);
Keith Brown's avatar
Keith Brown committed
163
164
165
166
  m_dspnStepAfterBreak->setMinimum(0.0);
  m_dspnStepAfterBreak->setSpecialValueText(tr("Guess"));
  m_dspnStepAfterBreak->setLocale(m_app->locale());
  m_dspnStepAfterBreak->setDecimals(m_app->d_decimal_digits);
167
  breaksLayout->addWidget(m_dspnStepAfterBreak, 2, 4);
168

169
  breaksLayout->addWidget(new QLabel(tr("Minor Ticks Before")), 3, 3);
Keith Brown's avatar
Keith Brown committed
170
171
  m_cmbMinorTicksBeforeBreak = new QComboBox();
  m_cmbMinorTicksBeforeBreak->setEditable(true);
Hahn, Steven's avatar
Hahn, Steven committed
172
  m_cmbMinorTicksBeforeBreak->addItems({"0", "1", "4", "9", "14", "19"});
173
  breaksLayout->addWidget(m_cmbMinorTicksBeforeBreak, 3, 4);
174

175
  breaksLayout->addWidget(new QLabel(tr("Minor Ticks After")), 4, 3);
Keith Brown's avatar
Keith Brown committed
176
177
  m_cmbMinorTicksAfterBreak = new QComboBox();
  m_cmbMinorTicksAfterBreak->setEditable(true);
Hahn, Steven's avatar
Hahn, Steven committed
178
  m_cmbMinorTicksAfterBreak->addItems({"0", "1", "4", "9", "14", "19"});
179
  breaksLayout->addWidget(m_cmbMinorTicksAfterBreak, 4, 4);
180
181
182
183

  QGroupBox *rightBox = new QGroupBox(QString());
  QGridLayout *rightLayout = new QGridLayout(rightBox);

184
185
  QWidget *stepWidget = new QWidget();
  QHBoxLayout *stepWidgetLayout = new QHBoxLayout(stepWidget);
186
187
  stepWidgetLayout->setMargin(0);

Keith Brown's avatar
Keith Brown committed
188
189
190
  m_radStep = new QRadioButton(tr("Step"));
  m_radStep->setChecked(true);
  rightLayout->addWidget(m_radStep, 0, 0);
191

Keith Brown's avatar
Keith Brown committed
192
193
194
195
196
  m_dspnStep = new DoubleSpinBox();
  m_dspnStep->setMinimum(0.0);
  m_dspnStep->setLocale(m_app->locale());
  m_dspnStep->setDecimals(m_app->d_decimal_digits);
  stepWidgetLayout->addWidget(m_dspnStep);
197

Keith Brown's avatar
Keith Brown committed
198
199
200
  m_cmbUnit = new QComboBox();
  m_cmbUnit->hide();
  stepWidgetLayout->addWidget(m_cmbUnit);
201
202
203

  rightLayout->addWidget(stepWidget, 0, 1);

204
  m_radMajor = new QRadioButton(tr("Max. Major Ticks"));
Keith Brown's avatar
Keith Brown committed
205
  rightLayout->addWidget(m_radMajor, 1, 0);
206

Keith Brown's avatar
Keith Brown committed
207
208
  m_spnMajorValue = new QSpinBox();
  m_spnMajorValue->setDisabled(true);
209
210
211
  m_spnMajorValue->setToolTip("Maximum number of major ticks which will be "
                              "added to the axis.\nNote that less ticks may be "
                              "added to preserve readability.");
Keith Brown's avatar
Keith Brown committed
212
  rightLayout->addWidget(m_spnMajorValue, 1, 1);
213

214
  m_lblMinorBox = new QLabel(tr("Max. Minor Ticks"));
Keith Brown's avatar
Keith Brown committed
215
  rightLayout->addWidget(m_lblMinorBox, 2, 0);
216

Keith Brown's avatar
Keith Brown committed
217
218
  m_cmbMinorValue = new QComboBox();
  m_cmbMinorValue->setEditable(true);
Hahn, Steven's avatar
Hahn, Steven committed
219
  m_cmbMinorValue->addItems({"0", "1", "4", "9", "14", "19"});
220
221
222
  m_cmbMinorValue->setToolTip("Maximum number of minor ticks which will be "
                              "added to the axis.\nNote that less ticks may be "
                              "added to preserve readability.");
Keith Brown's avatar
Keith Brown committed
223
  rightLayout->addWidget(m_cmbMinorValue, 2, 1);
224
225
226

  rightLayout->setRowStretch(3, 1);

227
  QHBoxLayout *hl = new QHBoxLayout();
228
229
230
  hl->addWidget(middleBox);
  hl->addWidget(rightBox);

231
  QVBoxLayout *vl = new QVBoxLayout(this);
232
  vl->addLayout(hl);
Keith Brown's avatar
Keith Brown committed
233
  vl->addWidget(m_grpAxesBreaks);
234

Keith Brown's avatar
Keith Brown committed
235
236
  connect(m_radStep, SIGNAL(clicked()), this, SLOT(radiosSwitched()));
  connect(m_radMajor, SIGNAL(clicked()), this, SLOT(radiosSwitched()));
237

238
  initWidgets();
239
  recalcStepMin();
240
241
}

242
ScaleDetails::~ScaleDetails() {}
243

244
245
/** Initialisation method. Sets up all widgets and variables not done in the
 * constructor.
Keith Brown's avatar
Keith Brown committed
246
247
*
*/
248
249
void ScaleDetails::initWidgets() {
  if (m_initialised) {
250
    return;
251
  } else {
Keith Brown's avatar
Keith Brown committed
252
    Plot *d_plot = m_graph->plotWidget();
253
    const QwtScaleDiv *scDiv = d_plot->axisScaleDiv(m_mappedaxis);
254
255
    double start = qMin(scDiv->lBound(), scDiv->hBound());
    double end = qMax(scDiv->lBound(), scDiv->hBound());
Keith Brown's avatar
Keith Brown committed
256
    ScaleDraw::ScaleType type = m_graph->axisType(m_mappedaxis);
257
258
259
    if (type == ScaleDraw::Date) {
      ScaleDraw *sclDraw =
          dynamic_cast<ScaleDraw *>(d_plot->axisScaleDraw(m_mappedaxis));
260
261
262
263
      if (!sclDraw) {
        throw std::runtime_error("Could not convert the axis Scale Draw object "
                                 "to a ScaleDraw object");
      }
264
265
      QDateTime origin = sclDraw->dateTimeOrigin();

Keith Brown's avatar
Keith Brown committed
266
267
268
269
      m_dspnStart->hide();
      m_timStartTime->hide();
      m_dteStartDateTime->show();
      m_dteStartDateTime->setDisplayFormat(sclDraw->format());
270
      m_dteStartDateTime->setDateTime(origin.addSecs((int)start));
Keith Brown's avatar
Keith Brown committed
271
272
273
274
275

      m_dspnEnd->hide();
      m_timEndTime->hide();
      m_dteEndDateTime->show();
      m_dteEndDateTime->setDisplayFormat(sclDraw->format());
276
      m_dteEndDateTime->setDateTime(origin.addSecs((int)end));
Keith Brown's avatar
Keith Brown committed
277
278

      m_cmbUnit->show();
Nick Draper's avatar
Nick Draper committed
279
280
      m_cmbUnit->addItem(tr("days"));
      m_cmbUnit->addItem(tr("weeks"));
Keith Brown's avatar
Keith Brown committed
281
282
      m_dspnStep->setValue(m_graph->axisStep(m_mappedaxis) / 86400.0);
      m_dspnStep->setSingleStep(1);
283
284
285
    } else if (type == ScaleDraw::Time) {
      if (ScaleDraw *sclDraw =
              dynamic_cast<ScaleDraw *>(d_plot->axisScaleDraw(m_mappedaxis))) {
286
287
288
289
290
291
        QTime origin = sclDraw->dateTimeOrigin().time();

        m_dspnStart->hide();
        m_dteStartDateTime->hide();
        m_timStartTime->show();
        m_timStartTime->setDisplayFormat(sclDraw->format());
292
        m_timStartTime->setTime(origin.addMSecs((int)start));
293
294
295
296
297

        m_dspnEnd->hide();
        m_dteEndDateTime->hide();
        m_timEndTime->show();
        m_timEndTime->setDisplayFormat(sclDraw->format());
298
        m_timEndTime->setTime(origin.addMSecs((int)end));
299
300

        m_cmbUnit->show();
Nick Draper's avatar
Nick Draper committed
301
302
303
304
        m_cmbUnit->addItem(tr("millisec."));
        m_cmbUnit->addItem(tr("sec."));
        m_cmbUnit->addItem(tr("min."));
        m_cmbUnit->addItem(tr("hours"));
305
306
307
308
        m_cmbUnit->setCurrentIndex(1);
        m_dspnStep->setValue(m_graph->axisStep(m_mappedaxis) / 1e3);
        m_dspnStep->setSingleStep(1000);
      }
309
    } else {
Keith Brown's avatar
Keith Brown committed
310
311
312
313
314
315
316
317
318
319
      m_dspnStart->show();
      m_dspnStart->setValue(start);
      m_timStartTime->hide();
      m_dteStartDateTime->hide();
      m_dspnEnd->show();
      m_dspnEnd->setValue(end);
      m_timEndTime->hide();
      m_dteEndDateTime->hide();
      m_dspnStep->setValue(m_graph->axisStep(m_mappedaxis));
      m_dspnStep->setSingleStep(0.1);
320
321
322
323
    }

    double range = fabs(scDiv->range());
    QwtScaleEngine *qwtsc_engine = d_plot->axisScaleEngine(m_mappedaxis);
324
325
326
    ScaleEngine *sc_engine = dynamic_cast<ScaleEngine *>(qwtsc_engine);
    if (sc_engine) {
      if (sc_engine->axisBreakLeft() > -DBL_MAX) {
Keith Brown's avatar
Keith Brown committed
327
        m_dspnBreakStart->setValue(sc_engine->axisBreakLeft());
328
      } else {
Keith Brown's avatar
Keith Brown committed
329
        m_dspnBreakStart->setValue(start + 0.25 * range);
330
      }
331

332
      if (sc_engine->axisBreakRight() < DBL_MAX) {
Keith Brown's avatar
Keith Brown committed
333
        m_dspnBreakEnd->setValue(sc_engine->axisBreakRight());
334
      } else {
Keith Brown's avatar
Keith Brown committed
335
        m_dspnBreakEnd->setValue(start + 0.75 * range);
336
      }
Keith Brown's avatar
Keith Brown committed
337
      m_grpAxesBreaks->setChecked(sc_engine->hasBreak());
338

Keith Brown's avatar
Keith Brown committed
339
340
341
342
      m_spnBreakPosition->setValue(sc_engine->breakPosition());
      m_spnBreakWidth->setValue(sc_engine->breakWidth());
      m_dspnStepBeforeBreak->setValue(sc_engine->stepBeforeBreak());
      m_dspnStepAfterBreak->setValue(sc_engine->stepAfterBreak());
343

344
      ScaleTransformation::Type scale_type = sc_engine->type();
Keith Brown's avatar
Keith Brown committed
345
      m_cmbMinorTicksBeforeBreak->clear();
Hahn, Steven's avatar
Hahn, Steven committed
346
347
348
349
      if (scale_type == ScaleTransformation::Log10) {
        m_cmbMinorTicksBeforeBreak->addItems({"0", "2", "4", "8"});
      } else {
        m_cmbMinorTicksBeforeBreak->addItems({"0", "1", "4", "9", "14", "19"});
350
      }
351
352
      m_cmbMinorTicksBeforeBreak->setEditText(
          QString::number(sc_engine->minTicksBeforeBreak()));
Keith Brown's avatar
Keith Brown committed
353

354
355
      m_cmbMinorTicksAfterBreak->setEditText(
          QString::number(sc_engine->minTicksAfterBreak()));
Keith Brown's avatar
Keith Brown committed
356
357
      m_chkLog10AfterBreak->setChecked(sc_engine->log10ScaleAfterBreak());
      m_chkBreakDecoration->setChecked(sc_engine->hasBreakDecoration());
358
359
      m_chkInvert->setChecked(
          sc_engine->testAttribute(QwtScaleEngine::Inverted));
Nick Draper's avatar
Nick Draper committed
360
      m_cmbScaleType->setCurrentIndex(scale_type);
361
      m_dspnN->setValue(sc_engine->nthPower());
Keith Brown's avatar
Keith Brown committed
362
      m_cmbMinorValue->clear();
Hahn, Steven's avatar
Hahn, Steven committed
363
364
365
366
      if (scale_type == ScaleTransformation::Log10) {
        m_cmbMinorValue->addItems({"0", "2", "4", "8"});
      } else {
        m_cmbMinorValue->addItems({"0", "1", "4", "9", "14", "19"});
367
      }
Hahn, Steven's avatar
Hahn, Steven committed
368
369
      m_cmbMinorValue->setEditText(
          QString::number(d_plot->axisMaxMinor(m_mappedaxis)));
370

Keith Brown's avatar
Keith Brown committed
371
372
      bool isColorMap = m_graph->isColorBarEnabled(m_mappedaxis);
      m_grpAxesBreaks->setEnabled(!isColorMap);
373
      if (isColorMap) {
Keith Brown's avatar
Keith Brown committed
374
        m_grpAxesBreaks->setChecked(false);
375
      }
376
    } else {
Keith Brown's avatar
Keith Brown committed
377
378
      m_grpAxesBreaks->setChecked(false);
      m_grpAxesBreaks->setEnabled(false);
379
380
381
    }

    QwtValueList lst = scDiv->ticks(QwtScaleDiv::MajorTick);
Keith Brown's avatar
Keith Brown committed
382
    m_spnMajorValue->setValue(lst.count());
383
384

    checkstep();
385
    checkscaletype();
386

387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
    connect(m_grpAxesBreaks, SIGNAL(clicked()), this, SLOT(setModified()));
    connect(m_chkInvert, SIGNAL(clicked()), this, SLOT(setModified()));
    connect(m_chkLog10AfterBreak, SIGNAL(clicked()), this, SLOT(setModified()));
    connect(m_chkBreakDecoration, SIGNAL(clicked()), this, SLOT(setModified()));
    connect(m_radStep, SIGNAL(clicked()), this, SLOT(setModified()));
    connect(m_radMajor, SIGNAL(clicked()), this, SLOT(setModified()));
    connect(m_cmbMinorTicksBeforeBreak, SIGNAL(currentIndexChanged(int)), this,
            SLOT(setModified()));
    connect(m_cmbMinorTicksAfterBreak, SIGNAL(currentIndexChanged(int)), this,
            SLOT(setModified()));
    connect(m_cmbMinorValue, SIGNAL(currentIndexChanged(int)), this,
            SLOT(setModified()));
    connect(m_cmbUnit, SIGNAL(currentIndexChanged(int)), this,
            SLOT(setModified()));
    connect(m_cmbScaleType, SIGNAL(currentIndexChanged(int)), this,
            SLOT(setModified()));
    connect(m_cmbScaleType, SIGNAL(currentIndexChanged(int)), this,
            SLOT(checkscaletype()));
Keith Brown's avatar
Keith Brown committed
405
    connect(m_dspnEnd, SIGNAL(valueChanged(double)), this, SLOT(setModified()));
406
407
    connect(m_dspnStart, SIGNAL(valueChanged(double)), this,
            SLOT(setModified()));
408
    connect(m_dspnN, SIGNAL(valueChanged(double)), this, SLOT(setModified()));
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
    connect(m_dspnStep, SIGNAL(valueChanged(double)), this,
            SLOT(setModified()));
    connect(m_dspnBreakStart, SIGNAL(valueChanged(double)), this,
            SLOT(setModified()));
    connect(m_dspnStepBeforeBreak, SIGNAL(valueChanged(double)), this,
            SLOT(setModified()));
    connect(m_dspnStepAfterBreak, SIGNAL(valueChanged(double)), this,
            SLOT(setModified()));
    connect(m_dspnBreakEnd, SIGNAL(valueChanged(double)), this,
            SLOT(setModified()));
    connect(m_spnMajorValue, SIGNAL(valueChanged(int)), this,
            SLOT(setModified()));
    connect(m_spnBreakPosition, SIGNAL(valueChanged(int)), this,
            SLOT(setModified()));
    connect(m_spnBreakWidth, SIGNAL(valueChanged(int)), this,
            SLOT(setModified()));
    connect(m_dteStartDateTime, SIGNAL(dateTimeChanged(QDateTime)), this,
            SLOT(setModified()));
    connect(m_dteStartDateTime, SIGNAL(dateChanged(QDate)), this,
            SLOT(setModified()));
    connect(m_dteStartDateTime, SIGNAL(timeChanged(QTime)), this,
            SLOT(setModified()));
    connect(m_dteEndDateTime, SIGNAL(dateTimeChanged(QDateTime)), this,
            SLOT(setModified()));
    connect(m_dteEndDateTime, SIGNAL(dateChanged(QDate)), this,
            SLOT(setModified()));
    connect(m_dteEndDateTime, SIGNAL(timeChanged(QTime)), this,
            SLOT(setModified()));
    connect(m_timStartTime, SIGNAL(dateTimeChanged(QDateTime)), this,
            SLOT(setModified()));
    connect(m_timStartTime, SIGNAL(dateChanged(QDate)), this,
            SLOT(setModified()));
    connect(m_timStartTime, SIGNAL(timeChanged(QTime)), this,
            SLOT(setModified()));
    connect(m_timEndTime, SIGNAL(dateTimeChanged(QDateTime)), this,
            SLOT(setModified()));
    connect(m_timEndTime, SIGNAL(dateChanged(QDate)), this,
            SLOT(setModified()));
    connect(m_timEndTime, SIGNAL(timeChanged(QTime)), this,
            SLOT(setModified()));
449

450
451
452
453
    m_initialised = true;
  }
}

454
455
456
457
458
/**
 * Enabled or disables the scale controls for the axis.
 *
 * @param enabled If the controls should be enabled or disabled
 */
459
460
void ScaleDetails::axisEnabled(bool enabled) {
  // Stuff the is always enabled when the axis is shown
461
462
463
464
465
466
467
468
469
470
471
472
473
  m_dspnStart->setEnabled(enabled);
  m_dspnEnd->setEnabled(enabled);
  m_cmbScaleType->setEnabled(enabled);
  m_chkInvert->setEnabled(enabled);
  m_radStep->setEnabled(enabled);
  m_radMajor->setEnabled(enabled);
  m_grpAxesBreaks->setEnabled(enabled);
  m_cmbMinorValue->setEnabled(enabled);
  m_lblStart->setEnabled(enabled);
  m_lblEnd->setEnabled(enabled);
  m_lblMinorBox->setEnabled(enabled);
  m_lblScaleTypeLabel->setEnabled(enabled);

474
475
  // Stuff that is only enabled when the axis is shown and axis breaks are
  // enabled
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
  bool enableAxisBreaks = enabled && m_grpAxesBreaks->isChecked();
  m_dspnBreakStart->setEnabled(enableAxisBreaks);
  m_dspnBreakEnd->setEnabled(enableAxisBreaks);
  m_spnBreakPosition->setEnabled(enableAxisBreaks);
  m_spnBreakWidth->setEnabled(enableAxisBreaks);
  m_dspnStepBeforeBreak->setEnabled(enableAxisBreaks);
  m_dspnStepAfterBreak->setEnabled(enableAxisBreaks);
  m_cmbMinorTicksBeforeBreak->setEnabled(enableAxisBreaks);
  m_cmbMinorTicksAfterBreak->setEnabled(enableAxisBreaks);

  bool majorTicks = enabled && m_radMajor->isChecked();
  m_spnMajorValue->setEnabled(majorTicks);

  bool minorTicks = enabled && m_radStep->isChecked();
  m_dspnStep->setEnabled(minorTicks);
}

Keith Brown's avatar
Keith Brown committed
493
494
495
/** Checks to see if this axis has valid parameters
*
*/
496
497
498
bool ScaleDetails::valid() {
  if (m_radStep->isChecked() &&
      (m_dspnStep->value() < m_dspnStep->getMinimum()))
499
500
    return false;

501
502
  return m_initialised && m_app && m_graph &&
         !(m_dspnStart->value() >= m_dspnEnd->value());
503
504
}

Keith Brown's avatar
Keith Brown committed
505
506
507
/** Applies this axis' parameters to the graph
*
*/
508
509
510
511
512
513
514
void ScaleDetails::apply() {
  if (m_modified && valid()) {
    // as the classes are separate now this may cause a problem as ideally i'd
    // get this from the axis tab,
    // but at the moment there's nothing to cause a problem as the only other
    // cases that are used are Date
    // and Time and Mantid doesn't support them in data yet i've been told
Keith Brown's avatar
Keith Brown committed
515
    ScaleDraw::ScaleType type = m_graph->axisType(m_mappedaxis);
516

517
518
519
520
521
    double start = 0.0, end = 0.0, step = 0.0, breakLeft = -DBL_MAX,
           breakRight = DBL_MAX;
    if (type == ScaleDraw::Date) {
      ScaleDraw *sclDraw = dynamic_cast<ScaleDraw *>(
          m_graph->plotWidget()->axisScaleDraw(m_mappedaxis));
522
      QDateTime origin = sclDraw->dateTimeOrigin();
Keith Brown's avatar
Keith Brown committed
523
524
      start = (double)origin.secsTo(m_dteStartDateTime->dateTime());
      end = (double)origin.secsTo(m_dteEndDateTime->dateTime());
525
526
527
    } else if (type == ScaleDraw::Time) {
      ScaleDraw *sclDraw = dynamic_cast<ScaleDraw *>(
          m_graph->plotWidget()->axisScaleDraw(m_mappedaxis));
528
      QTime origin = sclDraw->dateTimeOrigin().time();
Keith Brown's avatar
Keith Brown committed
529
530
      start = (double)origin.msecsTo(m_timStartTime->time());
      end = (double)origin.msecsTo(m_timEndTime->time());
531
    } else {
Keith Brown's avatar
Keith Brown committed
532
533
      start = m_dspnStart->value();
      end = m_dspnEnd->value();
534
    }
535

536
    if (m_radStep->isChecked()) {
Keith Brown's avatar
Keith Brown committed
537
      step = m_dspnStep->value();
538
539
      if (type == ScaleDraw::Time) {
        switch (m_cmbUnit->currentIndex()) {
540
541
542
543
544
545
546
547
548
549
550
551
        case 0:
          break;
        case 1:
          step *= 1e3;
          break;
        case 2:
          step *= 6e4;
          break;
        case 3:
          step *= 36e5;
          break;
        }
552
553
      } else if (type == ScaleDraw::Date) {
        switch (m_cmbUnit->currentIndex()) {
554
555
556
557
558
559
560
        case 0:
          step *= 86400;
          break;
        case 1:
          step *= 604800;
          break;
        }
561
562
      }
    }
563

564
    if (m_grpAxesBreaks->isChecked()) {
Keith Brown's avatar
Keith Brown committed
565
566
      breakLeft = qMin(m_dspnBreakStart->value(), m_dspnBreakEnd->value());
      breakRight = qMax(m_dspnBreakStart->value(), m_dspnBreakEnd->value());
567
    }
568
569
570
571
572
573
574
575
576
577
    m_graph->setScale(
        m_mappedaxis, start, end, step, m_spnMajorValue->value(),
        m_cmbMinorValue->currentText().toInt(), m_cmbScaleType->currentIndex(),
        m_chkInvert->isChecked(), breakLeft, breakRight,
        m_spnBreakPosition->value(), m_dspnStepBeforeBreak->value(),
        m_dspnStepAfterBreak->value(),
        m_cmbMinorTicksBeforeBreak->currentText().toInt(),
        m_cmbMinorTicksAfterBreak->currentText().toInt(),
        m_chkLog10AfterBreak->isChecked(), m_spnBreakWidth->value(),
        m_chkBreakDecoration->isChecked(), m_dspnN->value());
Keith Brown's avatar
Keith Brown committed
578
579
    m_graph->changeIntensity(true);
    m_graph->notifyChanges();
580
    m_modified = false;
581
  }
582
583
}

Keith Brown's avatar
Keith Brown committed
584
585
586
/** Sets the modifed flag to true so that the changes may be applied.
*
*/
587
void ScaleDetails::setModified() { m_modified = true; }
588

589
590
/** enables and disables the appropriate field depending on the current radio
 * button
Keith Brown's avatar
Keith Brown committed
591
592
*
*/
593
594
void ScaleDetails::radiosSwitched() {
  if (m_radStep->isChecked()) {
Keith Brown's avatar
Keith Brown committed
595
596
    m_dspnStep->setEnabled(true);
    m_spnMajorValue->setEnabled(false);
597
  } else if (m_radMajor->isChecked()) {
Keith Brown's avatar
Keith Brown committed
598
599
    m_dspnStep->setEnabled(false);
    m_spnMajorValue->setEnabled(true);
600
  } else {
Keith Brown's avatar
Keith Brown committed
601
602
603
    m_radStep->setChecked(true);
    m_dspnStep->setEnabled(true);
    m_spnMajorValue->setEnabled(false);
604
  }
605
606
}

607
608
/** Enables or disables widgets corresponding to the current value of the step
 * parameter.
Keith Brown's avatar
Keith Brown committed
609
610
*
*/
611
612
void ScaleDetails::checkstep() {
  if (m_dspnStep->value() != 0.0) {
Keith Brown's avatar
Keith Brown committed
613
614
615
    m_radStep->setChecked(true);
    m_dspnStep->setEnabled(true);
    m_cmbUnit->setEnabled(true);
616

Keith Brown's avatar
Keith Brown committed
617
618
    m_radMajor->setChecked(false);
    m_spnMajorValue->setEnabled(false);
619
  } else {
Keith Brown's avatar
Keith Brown committed
620
621
622
623
624
    m_radStep->setChecked(false);
    m_dspnStep->setEnabled(false);
    m_cmbUnit->setEnabled(false);
    m_radMajor->setChecked(true);
    m_spnMajorValue->setEnabled(true);
625
  }
626
627
}

628
/*
629
630
 * Enable the "n =" widget and display warning message
 * if power scale type is selected
631
 */
632
void ScaleDetails::checkscaletype() {
633
  // If "power X^n" scale option is selected
634
  if (m_cmbScaleType->currentIndex() == 2) {
635
    m_dspnN->setEnabled(true);
636
    m_lblWarn->setVisible(true);
637
  } else {
638
    m_dspnN->setEnabled(false);
639
    m_lblWarn->setVisible(false);
640
641
642
  }
}

643
/**
644
645
 * Recalculates the minimum value allowed in step to stop too many labels being
 * rendered
646
 */
647
void ScaleDetails::recalcStepMin() {
648
649
650
651
  double range = m_dspnEnd->value() - m_dspnStart->value();
  double minStep = range / 20;
  m_dspnStep->setMinimum(minStep);
}