Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
DlgSettingsExportFormat.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "CallbackBoundingRects.h"
8 #include "CmdMediator.h"
9 #include "CmdSettingsExportFormat.h"
10 #include "DocumentModelExportFormat.h"
11 #include "DlgSettingsExportFormat.h"
12 #include "ExportFileFunctions.h"
13 #include "ExportFileRelations.h"
14 #include "Logger.h"
15 #include "MainWindow.h"
16 #include "MainWindowModel.h"
17 #include <QComboBox>
18 #include <QDoubleValidator>
19 #include <QGridLayout>
20 #include <QGroupBox>
21 #include <QHBoxLayout>
22 #include <QLabel>
23 #include <QLineEdit>
24 #include <QListWidget>
25 #include <QPushButton>
26 #include <QRadioButton>
27 #include <QScrollBar>
28 #include <QSettings>
29 #include <QTabWidget>
30 #include <QTextEdit>
31 #include <QTextStream>
32 #include <QVBoxLayout>
33 #include "Settings.h"
34 #include "Transformation.h"
35 
36 const int MIN_INDENT_COLUMN_WIDTH = 20;
37 const int MIN_HEADER_EMPTY_COLUMN_WIDTH = 10;
38 const int MIN_EDIT_WIDTH = 110;
39 const int MAX_EDIT_WIDTH = 180;
40 
41 const int TAB_WIDGET_INDEX_FUNCTIONS = 0;
42 //const int TAB_WIDGET_INDEX_RELATIONS = 1;
43 
44 const QString EMPTY_PREVIEW;
45 
47  DlgSettingsAbstractBase (tr ("Export Format"),
48  "DlgSettingsExportFormat",
49  mainWindow),
50  m_modelExportBefore (0),
51  m_modelExportAfter (0)
52 {
53  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::DlgSettingsExportFormat";
54 
55  QWidget *subPanel = createSubPanel ();
56  finishPanel (subPanel);
57 }
58 
59 DlgSettingsExportFormat::~DlgSettingsExportFormat()
60 {
61  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::~DlgSettingsExportFormat";
62 }
63 
64 void DlgSettingsExportFormat::createCurveSelection (QGridLayout *layout, int &row)
65 {
66  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createCurveSelection";
67 
68  QLabel *labelIncluded = new QLabel (tr ("Included"));
69  layout->addWidget (labelIncluded, row, 0);
70 
71  QLabel *labelExcluded = new QLabel (tr ("Not included"));
72  layout->addWidget (labelExcluded, row++, 2);
73 
74  m_listIncluded = new QListWidget;
75  m_listIncluded->setWhatsThis (tr ("List of curves to be included in the exported file.\n\n"
76  "The order of the curves here does not affect the order in the exported file. That "
77  "order is determined by the Curves settings."));
78  m_listIncluded->setSelectionMode (QAbstractItemView::MultiSelection);
79  layout->addWidget (m_listIncluded, row, 0, 4, 1);
80  connect (m_listIncluded, SIGNAL (itemSelectionChanged ()), this, SLOT (slotListIncluded()));
81 
82  m_listExcluded = new QListWidget;
83  m_listExcluded->setWhatsThis (tr ("List of curves to be excluded from the exported file"));
84  m_listExcluded->setSelectionMode (QAbstractItemView::MultiSelection);
85  layout->addWidget (m_listExcluded, row++, 2, 4, 1);
86  connect (m_listExcluded, SIGNAL (itemSelectionChanged ()), this, SLOT (slotListExcluded()));
87 
88  m_btnInclude = new QPushButton (tr ("<<Include"));
89  m_btnInclude->setEnabled (false);
90  m_btnInclude->setWhatsThis (tr ("Move the currently selected curve(s) from the excluded list"));
91  layout->addWidget (m_btnInclude, row++, 1);
92  connect (m_btnInclude, SIGNAL (released ()), this, SLOT (slotInclude()));
93 
94  m_btnExclude = new QPushButton (tr ("Exclude>>"));
95  m_btnExclude->setEnabled (false);
96  m_btnExclude->setWhatsThis (tr ("Move the currently selected curve(s) from the included list"));
97  layout->addWidget (m_btnExclude, row++, 1);
98  connect (m_btnExclude, SIGNAL (released ()), this, SLOT (slotExclude()));
99 
100  row++;
101 }
102 
103 void DlgSettingsExportFormat::createDelimiters (QHBoxLayout *layoutMisc)
104 {
105  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createDelimiters";
106 
107  QGroupBox *groupDelimiters = new QGroupBox (tr ("Default Delimiters"));
108  layoutMisc->addWidget (groupDelimiters, 1);
109 
110  QVBoxLayout *layoutDelimiters = new QVBoxLayout;
111  groupDelimiters->setLayout (layoutDelimiters);
112 
113  m_btnDelimitersCommas = new QRadioButton (exportDelimiterToString (EXPORT_DELIMITER_COMMA));
114  m_btnDelimitersCommas->setWhatsThis (tr ("Exported file will have commas between adjacent values.\n\n"
115  "This setting is overridden for TSV files"));
116  layoutDelimiters->addWidget (m_btnDelimitersCommas);
117  connect (m_btnDelimitersCommas, SIGNAL (released ()), this, SLOT (slotDelimitersCommas()));
118 
119  m_btnDelimitersSpaces = new QRadioButton (exportDelimiterToString (EXPORT_DELIMITER_SPACE));
120  m_btnDelimitersSpaces->setWhatsThis (tr ("Exported file will have spaces between adjacent values.\n\n"
121  "This setting is overridden for CSV and TSV files"));
122  layoutDelimiters->addWidget (m_btnDelimitersSpaces);
123  connect (m_btnDelimitersSpaces, SIGNAL (released ()), this, SLOT (slotDelimitersSpaces()));
124 
125  m_btnDelimitersTabs = new QRadioButton (exportDelimiterToString (EXPORT_DELIMITER_TAB));
126  m_btnDelimitersTabs->setWhatsThis (tr ("Exported file will have tabs between adjacent values.\n\n"
127  "This setting is overridden for CSV files"));
128  layoutDelimiters->addWidget (m_btnDelimitersTabs);
129  connect (m_btnDelimitersTabs, SIGNAL (released ()), this, SLOT (slotDelimitersTabs()));
130 }
131 
132 void DlgSettingsExportFormat::createFileLayout (QHBoxLayout *layoutMisc)
133 {
134  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createFileLayout";
135 
136  QGroupBox *groupLayout = new QGroupBox (tr ("Layout"));
137  layoutMisc->addWidget (groupLayout, 1);
138 
139  QVBoxLayout *layoutLayout = new QVBoxLayout;
140  groupLayout->setLayout (layoutLayout);
141 
142  m_btnFunctionsLayoutAllCurves = new QRadioButton (tr ("All curves on each line"));
143  m_btnFunctionsLayoutAllCurves->setWhatsThis (tr ("Exported file will have, on each line, "
144  "an X value, the Y value for the first curve, the Y value for the second curve,..."));
145  layoutLayout->addWidget (m_btnFunctionsLayoutAllCurves);
146  connect (m_btnFunctionsLayoutAllCurves, SIGNAL (released()), this, SLOT (slotFunctionsLayoutAllCurves ()));
147 
148  m_btnFunctionsLayoutOneCurve = new QRadioButton (tr ("One curve on each line"));
149  m_btnFunctionsLayoutOneCurve->setWhatsThis (tr ("Exported file will have all the points for "
150  "the first curve, with one X-Y pair on each line, then the points for the second curve,..."));
151  layoutLayout->addWidget (m_btnFunctionsLayoutOneCurve);
152  connect (m_btnFunctionsLayoutOneCurve, SIGNAL (released()), this, SLOT (slotFunctionsLayoutOneCurve ()));
153 }
154 
155 void DlgSettingsExportFormat::createFunctionsPointsSelection (QHBoxLayout *layoutFunctions)
156 {
157  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createFunctionsPointsSelection";
158 
159  QGroupBox *groupPointsSelection = new QGroupBox (tr ("Points Selection"));
160  layoutFunctions->addWidget (groupPointsSelection, 1);
161 
162  QGridLayout *layoutPointsSelections = new QGridLayout;
163  groupPointsSelection->setLayout (layoutPointsSelections);
164 
165  layoutPointsSelections->setColumnMinimumWidth(0, MIN_INDENT_COLUMN_WIDTH);
166  layoutPointsSelections->setColumnStretch (0, 0);
167  layoutPointsSelections->setColumnStretch (1, 0);
168  layoutPointsSelections->setColumnStretch (2, 0);
169  layoutPointsSelections->setColumnStretch (3, 1);
170 
171  int row = 0;
172  m_btnFunctionsPointsAllCurves = new QRadioButton (tr ("Interpolate Ys at Xs from all curves"));
173  m_btnFunctionsPointsAllCurves->setWhatsThis (tr ("Exported file will have values at every unique X "
174  "value from every curve. Y values will be linearly interpolated if necessary"));
175  layoutPointsSelections->addWidget (m_btnFunctionsPointsAllCurves, row++, 0, 1, 4);
176  connect (m_btnFunctionsPointsAllCurves, SIGNAL (released()), this, SLOT (slotFunctionsPointsAllCurves()));
177 
178  m_btnFunctionsPointsFirstCurve = new QRadioButton (tr ("Interpolate Ys at Xs from first curve"));
179  m_btnFunctionsPointsFirstCurve->setWhatsThis (tr ("Exported file will have values at every unique X "
180  "value from the first curve. Y values will be linearly interpolated if necessary"));
181  layoutPointsSelections->addWidget (m_btnFunctionsPointsFirstCurve, row++, 0, 1, 4);
182  connect (m_btnFunctionsPointsFirstCurve, SIGNAL (released()), this, SLOT (slotFunctionsPointsFirstCurve()));
183 
184  m_btnFunctionsPointsEvenlySpaced = new QRadioButton (tr ("Interpolate Ys at evenly spaced X values."));
185  m_btnFunctionsPointsEvenlySpaced->setWhatsThis (tr ("Exported file will have values at evenly spaced X values, separated by the interval selected below."));
186  layoutPointsSelections->addWidget (m_btnFunctionsPointsEvenlySpaced, row++, 0, 1, 4);
187  connect (m_btnFunctionsPointsEvenlySpaced, SIGNAL (released()), this, SLOT (slotFunctionsPointsEvenlySpaced()));
188 
189  QLabel *labelInterval = new QLabel (tr ("Interval:"));
190  layoutPointsSelections->addWidget (labelInterval, row, 1, 1, 1, Qt::AlignRight);
191 
192  m_editFunctionsPointsEvenlySpacing = new QLineEdit;
193  m_validatorFunctionsPointsEvenlySpacing = new QDoubleValidator; // Minimum value, to prevent overflow, is set later according to settings
194  m_editFunctionsPointsEvenlySpacing->setValidator (m_validatorFunctionsPointsEvenlySpacing);
195  m_editFunctionsPointsEvenlySpacing->setMinimumWidth (MIN_EDIT_WIDTH);
196  m_editFunctionsPointsEvenlySpacing->setMaximumWidth (MAX_EDIT_WIDTH);
197  m_editFunctionsPointsEvenlySpacing->setWhatsThis (tr ("Interval, in the units of X, between successive points in the X direction.\n\n"
198  "If the scale is linear, then this interval is added to successive X values. If the scale is "
199  "logarithmic, then this interval is multiplied to successive X values.\n\n"
200  "The X values will be automatically aligned along simple numbers. If the first and/or last "
201  "points are not along the aligned X values, then one or two additional points are added "
202  "as necessary."));
203  layoutPointsSelections->addWidget (m_editFunctionsPointsEvenlySpacing, row, 2, 1, 1, Qt::AlignLeft);
204  connect (m_editFunctionsPointsEvenlySpacing, SIGNAL (textChanged(const QString &)), this, SLOT (slotFunctionsPointsEvenlySpacedInterval(const QString &)));
205 
206  m_cmbFunctionsPointsEvenlySpacingUnits = new QComboBox;
207  m_cmbFunctionsPointsEvenlySpacingUnits->setWhatsThis (tr ("Units for spacing interval.\n\n"
208  "Pixel units are preferred when the spacing is to be independent of the X scale. The spacing will be "
209  "consistent across the graph, even if the X scale is logarithmic.\n\n"
210  "Graph units are preferred when the spacing is to depend on the X scale."));
211  m_cmbFunctionsPointsEvenlySpacingUnits->addItem(exportPointsIntervalUnitsToString (EXPORT_POINTS_INTERVAL_UNITS_GRAPH),
212  QVariant (EXPORT_POINTS_INTERVAL_UNITS_GRAPH));
213  m_cmbFunctionsPointsEvenlySpacingUnits->addItem(exportPointsIntervalUnitsToString (EXPORT_POINTS_INTERVAL_UNITS_SCREEN),
214  QVariant (EXPORT_POINTS_INTERVAL_UNITS_SCREEN));
215  connect (m_cmbFunctionsPointsEvenlySpacingUnits, SIGNAL (activated (const QString &)),
216  this, SLOT (slotFunctionsPointsEvenlySpacedIntervalUnits (const QString &))); // activated() ignores code changes
217  layoutPointsSelections->addWidget (m_cmbFunctionsPointsEvenlySpacingUnits, row++, 3, 1, 1, Qt::AlignLeft);
218 
219  m_btnFunctionsPointsRaw = new QRadioButton (tr ("Raw Xs and Ys"));
220  m_btnFunctionsPointsRaw->setWhatsThis (tr ("Exported file will have only original X and Y values"));
221  layoutPointsSelections->addWidget (m_btnFunctionsPointsRaw, row++, 0, 1, 4);
222  connect (m_btnFunctionsPointsRaw, SIGNAL (released()), this, SLOT (slotFunctionsPointsRaw()));
223 }
224 
225 void DlgSettingsExportFormat::createHeader (QHBoxLayout *layoutMisc)
226 {
227  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createHeader";
228 
229  const int COLUMN_RADIO_BUTTONS = 0, COLUMN_EMPTY = 1, COLUMN_LABEL = 2;
230 
231  QGroupBox *groupHeader = new QGroupBox (tr ("Header"));
232  layoutMisc->addWidget (groupHeader, 1);
233 
234  QGridLayout *layoutHeader = new QGridLayout;
235  layoutHeader->setColumnMinimumWidth(COLUMN_EMPTY,
236  MIN_HEADER_EMPTY_COLUMN_WIDTH);
237  groupHeader->setLayout (layoutHeader);
238  int row = 0;
239 
240  m_btnHeaderNone = new QRadioButton (exportHeaderToString (EXPORT_HEADER_NONE));
241  m_btnHeaderNone->setWhatsThis (tr ("Exported file will have no header line"));
242  layoutHeader->addWidget (m_btnHeaderNone, row++, COLUMN_RADIO_BUTTONS, 1, 1);
243  connect (m_btnHeaderNone, SIGNAL (released ()), this, SLOT (slotHeaderNone()));
244 
245  m_btnHeaderSimple = new QRadioButton (exportHeaderToString (EXPORT_HEADER_SIMPLE));
246  m_btnHeaderSimple->setWhatsThis (tr ("Exported file will have simple header line"));
247  layoutHeader->addWidget (m_btnHeaderSimple, row++, COLUMN_RADIO_BUTTONS, 1, 1);
248  connect (m_btnHeaderSimple, SIGNAL (released ()), this, SLOT (slotHeaderSimple()));
249 
250  m_btnHeaderGnuplot = new QRadioButton (exportHeaderToString (EXPORT_HEADER_GNUPLOT));
251  m_btnHeaderGnuplot->setWhatsThis (tr ("Exported file will have gnuplot header line"));
252  layoutHeader->addWidget (m_btnHeaderGnuplot, row++, COLUMN_RADIO_BUTTONS, 1, 1);
253  connect (m_btnHeaderGnuplot, SIGNAL (released()), this, SLOT (slotHeaderGnuplot()));
254 
255  createXLabel (layoutHeader,
256  COLUMN_LABEL);
257 }
258 
260 {
261  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createOptionalSaveDefault";
262 
263  m_btnSaveDefault = new QPushButton (tr ("Save As Default"));
264  m_btnSaveDefault->setWhatsThis (tr ("Save the settings for use as future defaults."));
265  connect (m_btnSaveDefault, SIGNAL (released ()), this, SLOT (slotSaveDefault ()));
266  layout->addWidget (m_btnSaveDefault, 0, Qt::AlignLeft);
267 }
268 
269 void DlgSettingsExportFormat::createPreview(QGridLayout *layout, int &row)
270 {
271  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createPreview";
272 
273  QLabel *label = new QLabel (tr ("Preview"));
274  layout->addWidget (label, row++, 0, 1, 3);
275 
276  m_editPreview = new QTextEdit;
277  m_editPreview->setReadOnly (true);
278  m_editPreview->setWhatsThis (tr ("Preview window shows how current settings affect the exported file"));
279  m_editPreview->setMinimumHeight (MINIMUM_PREVIEW_HEIGHT);
280 
281  layout->addWidget (m_editPreview, row++, 0, 1, 3);
282 }
283 
284 void DlgSettingsExportFormat::createRelationsPointsSelection (QHBoxLayout *layoutRelations)
285 {
286  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createRelationsPointsSelection";
287 
288  QGroupBox *groupPointsSelection = new QGroupBox (tr ("Points Selection"));
289  layoutRelations->addWidget (groupPointsSelection);
290 
291  QGridLayout *layoutPointsSelections = new QGridLayout;
292  groupPointsSelection->setLayout (layoutPointsSelections);
293 
294  layoutPointsSelections->setColumnMinimumWidth(0, MIN_INDENT_COLUMN_WIDTH);
295  layoutPointsSelections->setColumnStretch (0, 0);
296  layoutPointsSelections->setColumnStretch (1, 0);
297  layoutPointsSelections->setColumnStretch (2, 0);
298  layoutPointsSelections->setColumnStretch (3, 1);
299 
300  int row = 0;
301  m_btnRelationsPointsEvenlySpaced = new QRadioButton (tr ("Interpolate Xs and Ys at evenly spaced intervals."));
302  m_btnRelationsPointsEvenlySpaced->setWhatsThis (tr ("Exported file will have points evenly spaced along each relation, separated by the interval "
303  "selected below. If the last interval does not end at the last point, then a shorter last interval "
304  "is added that ends on the last point."));
305  layoutPointsSelections->addWidget (m_btnRelationsPointsEvenlySpaced, row++, 0, 1, 4);
306  connect (m_btnRelationsPointsEvenlySpaced, SIGNAL (released()), this, SLOT (slotRelationsPointsEvenlySpaced()));
307 
308  QLabel *labelInterval = new QLabel (tr ("Interval:"));
309  layoutPointsSelections->addWidget (labelInterval, row, 1, 1, 1, Qt::AlignRight);
310 
311  m_editRelationsPointsEvenlySpacing = new QLineEdit;
312  m_validatorRelationsPointsEvenlySpacing = new QDoubleValidator; // Minimum value, to prevent overflow, is set later according to settings
313  m_editRelationsPointsEvenlySpacing->setValidator (m_validatorRelationsPointsEvenlySpacing);
314  m_editRelationsPointsEvenlySpacing->setMinimumWidth (MIN_EDIT_WIDTH);
315  m_editRelationsPointsEvenlySpacing->setMaximumWidth (MAX_EDIT_WIDTH);
316  m_editRelationsPointsEvenlySpacing->setWhatsThis (tr ("Interval between successive points when "
317  "exporting at evenly spaced (X,Y) coordinates."));
318  layoutPointsSelections->addWidget (m_editRelationsPointsEvenlySpacing, row, 2, 1, 1, Qt::AlignLeft);
319  connect (m_editRelationsPointsEvenlySpacing, SIGNAL (textChanged(const QString &)), this, SLOT (slotRelationsPointsEvenlySpacedInterval(const QString &)));
320 
321  m_cmbRelationsPointsEvenlySpacingUnits = new QComboBox;
322  m_cmbRelationsPointsEvenlySpacingUnits->setWhatsThis (tr ("Units for spacing interval.\n\n"
323  "Pixel units are preferred when the spacing is to be independent of the X and Y scales. The spacing will be "
324  "consistent across the graph, even if a scale is logarithmic or the X and Y scales are different.\n\n"
325  "Graph units are usually preferred when the X and Y scales are identical."));
326  m_cmbRelationsPointsEvenlySpacingUnits->addItem(exportPointsIntervalUnitsToString (EXPORT_POINTS_INTERVAL_UNITS_GRAPH),
327  QVariant (EXPORT_POINTS_INTERVAL_UNITS_GRAPH));
328  m_cmbRelationsPointsEvenlySpacingUnits->addItem(exportPointsIntervalUnitsToString (EXPORT_POINTS_INTERVAL_UNITS_SCREEN),
329  QVariant (EXPORT_POINTS_INTERVAL_UNITS_SCREEN));
330  connect (m_cmbRelationsPointsEvenlySpacingUnits, SIGNAL (activated (const QString &)),
331  this, SLOT (slotRelationsPointsEvenlySpacedIntervalUnits (const QString &))); // activated() ignores code changes
332  layoutPointsSelections->addWidget (m_cmbRelationsPointsEvenlySpacingUnits, row++, 3, 1, 1, Qt::AlignLeft);
333 
334  m_btnRelationsPointsRaw = new QRadioButton (tr ("Raw Xs and Ys"));
335  m_btnRelationsPointsRaw->setWhatsThis (tr ("Exported file will have only original X and Y values"));
336  layoutPointsSelections->addWidget (m_btnRelationsPointsRaw, row++, 0, 1, 4);
337  connect (m_btnRelationsPointsRaw, SIGNAL (released()), this, SLOT (slotRelationsPointsRaw()));
338 }
339 
341 {
342  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createSubPanel";
343 
344  QWidget *subPanel = new QWidget ();
345  QGridLayout *layout = new QGridLayout (subPanel);
346  subPanel->setLayout (layout);
347 
348  int row = 0;
349  createCurveSelection (layout, row);
350 
351  createTabWidget (layout,
352  row);
353 
354  QWidget *widgetMisc = new QWidget;
355  layout->addWidget (widgetMisc, row++, 0, 1, 3);
356  QHBoxLayout *layoutMisc = new QHBoxLayout;
357  widgetMisc->setLayout (layoutMisc);
358 
359  createDelimiters (layoutMisc); // One row of radio buttons
360  createHeader (layoutMisc); // Two rows with radio buttons and then header label
361  createFileLayout (layoutMisc); // One row of radio buttons
362 
363  createPreview (layout, row);
364 
365  return subPanel;
366 }
367 
368 void DlgSettingsExportFormat::createTabWidget (QGridLayout *layout,
369  int &row)
370 {
371  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createTabWidget";
372 
373  m_tabWidget = new QTabWidget;
374  // This gets connected below, after the tabs have been added
375  layout->addWidget (m_tabWidget, row++, 0, 1, 3);
376 
377  QWidget *widgetFunctions = new QWidget;
378  int indexFunctions = m_tabWidget->addTab (widgetFunctions, tr ("Functions"));
379  QWidget *tabFunctions = m_tabWidget->widget (indexFunctions);
380  tabFunctions->setWhatsThis (tr ("Functions Tab\n\n"
381  "Controls for specifying the format of functions during export"));
382  QHBoxLayout *layoutFunctions = new QHBoxLayout;
383  widgetFunctions->setLayout (layoutFunctions);
384 
385  QWidget *widgetRelations = new QWidget;
386  int indexRelations = m_tabWidget->addTab (widgetRelations, tr ("Relations"));
387  QWidget *tabRelations = m_tabWidget->widget (indexRelations);
388  tabRelations->setWhatsThis (tr ("Relations Tab\n\n"
389  "Controls for specifying the format of relations during export"));
390  QHBoxLayout *layoutRelations = new QHBoxLayout;
391  widgetRelations->setLayout (layoutRelations);
392 
393  // Now that the tabs have been added we can connect this signal
394  connect (m_tabWidget, SIGNAL (currentChanged (int)), this, SLOT (slotTabChanged (int)));
395 
396  createFunctionsPointsSelection (layoutFunctions);
397  createRelationsPointsSelection (layoutRelations);
398 }
399 
400 void DlgSettingsExportFormat::createXLabel (QGridLayout *layoutHeader,
401  int colLabel)
402 {
403  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createXLabel";
404 
405  int row = 1; // Skip first row
406 
407  QLabel *title;
408  if (true) {
409  title = new QLabel (tr ("X Label:"));
410  } else {
411  title = new QLabel (tr ("Theta Label:"));
412  }
413  layoutHeader->addWidget (title, row++, colLabel, 1, 1);
414 
415  m_editXLabel = new QLineEdit;
416  if (true) {
417  m_editXLabel->setWhatsThis (tr ("Label in the header for x values"));
418  } else {
419  m_editXLabel->setWhatsThis (tr ("Label in the header for theta values"));
420  }
421  layoutHeader->addWidget (m_editXLabel, row++, colLabel, 1, 1);
422  connect (m_editXLabel, SIGNAL (textChanged (const QString &)), this, SLOT (slotXLabel(const QString &)));
423 }
424 
425 bool DlgSettingsExportFormat::goodIntervalFunctions() const
426 {
427  QString textFunctions = m_editFunctionsPointsEvenlySpacing->text();
428  int posFunctions;
429 
430  bool isGood = (m_validatorFunctionsPointsEvenlySpacing->validate (textFunctions, posFunctions) == QValidator::Acceptable);
431 
432  return isGood;
433 }
434 
435 bool DlgSettingsExportFormat::goodIntervalRelations() const
436 {
437  QString textRelations = m_editRelationsPointsEvenlySpacing->text();
438  int posRelations;
439 
440  return (m_validatorRelationsPointsEvenlySpacing->validate (textRelations, posRelations) == QValidator::Acceptable);
441 }
442 
444 {
445  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::handleOk";
446 
448  cmdMediator ().document(),
449  *m_modelExportBefore,
450  *m_modelExportAfter);
451  cmdMediator ().push (cmd);
452 
453  hide ();
454 }
455 
456 void DlgSettingsExportFormat::initializeIntervalConstraints ()
457 {
458  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::initializeIntervalConstraints";
459 
460  const int MAX_POINTS_ACROSS_RANGE = 1000;
461 
462  // Get min and max of graph and screen coordinates
463  CallbackBoundingRects ftor (mainWindow().transformation());
464 
465  Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
467  cmdMediator().iterateThroughCurvesPointsGraphs (ftorWithCallback);
468 
469  // If there are no points, then interval will be zero. That special case must be handled downstream to prevent infinite loops
470  bool isEmpty;
471  double maxSizeGraph = qMax (ftor.boundingRectGraph(isEmpty).width(),
472  ftor.boundingRectGraph(isEmpty).height());
473  double maxSizeScreen = qMax (ftor.boundingRectScreen(isEmpty).width(),
474  ftor.boundingRectScreen(isEmpty).height());
475  m_minIntervalGraph = maxSizeGraph / MAX_POINTS_ACROSS_RANGE;
476  m_minIntervalScreen = maxSizeScreen / MAX_POINTS_ACROSS_RANGE;
477 }
478 
480 {
481  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::load";
482 
483  setCmdMediator (cmdMediator);
484 
485  // Flush old data
486  if (m_modelExportBefore != 0) {
487  delete m_modelExportBefore;
488  }
489  if (m_modelExportAfter != 0) {
490  delete m_modelExportAfter;
491  }
492 
493  // Save new data
494  m_modelExportBefore = new DocumentModelExportFormat (cmdMediator.document());
495  m_modelExportAfter = new DocumentModelExportFormat (cmdMediator.document());
496 
497  // Populate controls. First load excluded curves
498  m_listExcluded->clear();
499  QStringList curveNamesExcluded = m_modelExportAfter->curveNamesNotExported();
500  QStringList::const_iterator itr;
501  for (itr = curveNamesExcluded.begin (); itr != curveNamesExcluded.end(); ++itr) {
502  QString curveNameNotExported = *itr;
503  m_listExcluded->addItem (curveNameNotExported);
504  }
505 
506  // Include curves that are not excluded
507  m_listIncluded->clear();
508  QStringList curveNamesAll = cmdMediator.document().curvesGraphsNames();
509  for (itr = curveNamesAll.begin (); itr != curveNamesAll.end(); itr++) {
510  QString curveName = *itr;
511  if (!curveNamesExcluded.contains (curveName)) {
512  m_listIncluded->addItem (curveName);
513  }
514  }
515 
516  ExportPointsSelectionFunctions pointsSelectionFunctions = m_modelExportAfter->pointsSelectionFunctions();
517  m_btnFunctionsPointsAllCurves->setChecked (pointsSelectionFunctions == EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES);
518  m_btnFunctionsPointsFirstCurve->setChecked (pointsSelectionFunctions == EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_FIRST_CURVE);
519  m_btnFunctionsPointsEvenlySpaced->setChecked (pointsSelectionFunctions == EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_PERIODIC);
520  m_btnFunctionsPointsRaw->setChecked (pointsSelectionFunctions == EXPORT_POINTS_SELECTION_FUNCTIONS_RAW);
521 
522  ExportLayoutFunctions layoutFunctions = m_modelExportAfter->layoutFunctions ();
523  m_btnFunctionsLayoutAllCurves->setChecked (layoutFunctions == EXPORT_LAYOUT_ALL_PER_LINE);
524  m_btnFunctionsLayoutOneCurve->setChecked (layoutFunctions == EXPORT_LAYOUT_ONE_PER_LINE);
525 
526  ExportPointsSelectionRelations pointsSelectionRelations = m_modelExportAfter->pointsSelectionRelations();
527  m_btnRelationsPointsEvenlySpaced->setChecked (pointsSelectionRelations == EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE);
528  m_btnRelationsPointsRaw->setChecked (pointsSelectionRelations == EXPORT_POINTS_SELECTION_RELATIONS_RAW);
529 
530  ExportDelimiter delimiter = m_modelExportAfter->delimiter ();
531  m_btnDelimitersCommas->setChecked (delimiter == EXPORT_DELIMITER_COMMA);
532  m_btnDelimitersSpaces->setChecked (delimiter == EXPORT_DELIMITER_SPACE);
533  m_btnDelimitersTabs->setChecked (delimiter == EXPORT_DELIMITER_TAB);
534 
535  ExportHeader header = m_modelExportAfter->header ();
536  m_btnHeaderNone->setChecked (header == EXPORT_HEADER_NONE);
537  m_btnHeaderSimple->setChecked (header == EXPORT_HEADER_SIMPLE);
538  m_btnHeaderGnuplot->setChecked (header == EXPORT_HEADER_GNUPLOT);
539 
540  m_editXLabel->setText (m_modelExportAfter->xLabel());
541  m_editFunctionsPointsEvenlySpacing->setText (QString::number (m_modelExportAfter->pointsIntervalFunctions()));
542  m_editRelationsPointsEvenlySpacing->setText (QString::number (m_modelExportAfter->pointsIntervalRelations()));
543 
544  ExportPointsIntervalUnits pointsIntervalUnitsFunctions = m_modelExportAfter->pointsIntervalUnitsRelations();
545  ExportPointsIntervalUnits pointsIntervalUnitsRelations = m_modelExportAfter->pointsIntervalUnitsRelations();
546  int indexFunctions = m_cmbRelationsPointsEvenlySpacingUnits->findData (QVariant (pointsIntervalUnitsFunctions));
547  int indexRelations = m_cmbRelationsPointsEvenlySpacingUnits->findData (QVariant (pointsIntervalUnitsRelations));
548  m_cmbFunctionsPointsEvenlySpacingUnits->setCurrentIndex (indexFunctions);
549  m_cmbRelationsPointsEvenlySpacingUnits->setCurrentIndex (indexRelations);
550 
551  initializeIntervalConstraints ();
552 
553  updateControls();
554  updateIntervalConstraints();
555  enableOk (false); // Disable Ok button since there not yet any changes
556  updatePreview();
557 }
558 
559 void DlgSettingsExportFormat::slotDelimitersCommas()
560 {
561  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotDelimitersCommas";
562 
563  m_modelExportAfter->setDelimiter(EXPORT_DELIMITER_COMMA);
564  updateControls();
565  updatePreview();
566 }
567 
568 void DlgSettingsExportFormat::slotDelimitersSpaces()
569 {
570  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotDelimitersSpaces";
571 
572  m_modelExportAfter->setDelimiter(EXPORT_DELIMITER_SPACE);
573  updateControls();
574  updatePreview();
575 }
576 
577 void DlgSettingsExportFormat::slotDelimitersTabs()
578 {
579  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotDelimitersTabs";
580 
581  m_modelExportAfter->setDelimiter(EXPORT_DELIMITER_TAB);
582  updateControls();
583  updatePreview();
584 }
585 
586 void DlgSettingsExportFormat::slotExclude ()
587 {
588  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotExclude";
589 
590  // Perform forward pass to get excluded curves in the proper order
591  int i;
592  QStringList excluded;
593  for (i = 0; i < m_listIncluded->count(); i++) {
594  if (m_listIncluded->item(i)->isSelected()) {
595  excluded += m_listIncluded->item(i)->text();
596  }
597  }
598 
599  // Add the excluded curves to the excluded list
600  for (i = 0; i < excluded.count(); i++) {
601  QString curveName = excluded.at (i);
602  m_listExcluded->addItem (curveName);
603  }
604 
605  // Perform backwards pass to remove the excluded curves from the included list
606  for (i = m_listIncluded->count() - 1; i>= 0; i--) {
607  QString curveName = m_listIncluded->item(i)->text();
608  if (excluded.contains (curveName)) {
609  QListWidgetItem *item = m_listIncluded->item (i);
610  m_listIncluded->removeItemWidget (item);
611  delete item;
612  }
613  }
614 
615  m_modelExportAfter->setCurveNamesNotExported(excluded);
616  updateControls();
617  updatePreview();
618 }
619 
620 void DlgSettingsExportFormat::slotFunctionsLayoutAllCurves()
621 {
622  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsLayoutAllCurves";
623 
624  m_modelExportAfter->setLayoutFunctions(EXPORT_LAYOUT_ALL_PER_LINE);
625  updateControls();
626  updatePreview();
627 }
628 
629 void DlgSettingsExportFormat::slotFunctionsLayoutOneCurve()
630 {
631  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsLayoutOneCurve";
632 
633  m_modelExportAfter->setLayoutFunctions(EXPORT_LAYOUT_ONE_PER_LINE);
634  updateControls();
635  updatePreview();
636 }
637 
638 void DlgSettingsExportFormat::slotFunctionsPointsAllCurves()
639 {
640  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsAllCurves";
641 
642  m_modelExportAfter->setPointsSelectionFunctions(EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES);
643  updateControls();
644  updatePreview();
645 }
646 
647 void DlgSettingsExportFormat::slotFunctionsPointsEvenlySpaced()
648 {
649  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsEvenlySpaced";
650 
651  m_modelExportAfter->setPointsSelectionFunctions(EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_PERIODIC);
652  updateControls();
653  updatePreview();
654 }
655 
656 void DlgSettingsExportFormat::slotFunctionsPointsEvenlySpacedInterval(const QString &)
657 {
658  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsEvenlySpacedInterval";
659 
660  // Prevent infinite loop on empty and "-" values which get treated as zero interval
661  if (goodIntervalFunctions()) {
662  m_modelExportAfter->setPointsIntervalFunctions(m_editFunctionsPointsEvenlySpacing->text().toDouble());
663  updateControls();
664  updatePreview();
665  } else {
666  m_editPreview->setText(EMPTY_PREVIEW);
667  }
668 }
669 
670 void DlgSettingsExportFormat::slotFunctionsPointsEvenlySpacedIntervalUnits(const QString &)
671 {
672  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsEvenlySpacedIntervalUnits";
673 
674  int index = m_cmbFunctionsPointsEvenlySpacingUnits->currentIndex();
675  ExportPointsIntervalUnits units = (ExportPointsIntervalUnits) m_cmbFunctionsPointsEvenlySpacingUnits->itemData (index).toInt();
676 
677  m_modelExportAfter->setPointsIntervalUnitsFunctions(units);
678  updateIntervalConstraints(); // Call this before updateControls so constraint checking is updated for ok button
679  updateControls();
680  updatePreview();
681 }
682 
683 void DlgSettingsExportFormat::slotFunctionsPointsFirstCurve()
684 {
685  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsFirstCurve";
686 
687  m_modelExportAfter->setPointsSelectionFunctions(EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_FIRST_CURVE);
688  updateControls();
689  updatePreview();
690 }
691 
692 void DlgSettingsExportFormat::slotFunctionsPointsRaw()
693 {
694  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsRaw";
695 
696  m_modelExportAfter->setPointsSelectionFunctions(EXPORT_POINTS_SELECTION_FUNCTIONS_RAW);
697  updateControls();
698  updatePreview();
699 }
700 
701 void DlgSettingsExportFormat::slotHeaderGnuplot()
702 {
703  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotHeaderGnuplot";
704 
705  m_modelExportAfter->setHeader(EXPORT_HEADER_GNUPLOT);
706  updateControls();
707  updatePreview();
708 }
709 
710 void DlgSettingsExportFormat::slotHeaderNone()
711 {
712  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotHeaderNone";
713 
714  m_modelExportAfter->setHeader(EXPORT_HEADER_NONE);
715  updateControls();
716  updatePreview();
717 }
718 
719 void DlgSettingsExportFormat::slotHeaderSimple()
720 {
721  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotHeaderSimple";
722 
723  m_modelExportAfter->setHeader(EXPORT_HEADER_SIMPLE);
724  updateControls();
725  updatePreview();
726 }
727 
728 void DlgSettingsExportFormat::slotInclude ()
729 {
730  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotInclude";
731 
732  // Perform forward pass to get included curves in the proper order
733  int i;
734  QStringList included;
735  for (i = 0; i < m_listExcluded->count(); i++) {
736  if (m_listExcluded->item(i)->isSelected()) {
737  included += m_listExcluded->item(i)->text();
738  }
739  }
740 
741  // Add the included curves to the included list
742  for (i = 0; i < included.count(); i++) {
743  QString curveName = included.at (i);
744  m_listIncluded->addItem (curveName);
745  }
746 
747  // Perform backwards pass to remove the included curves from the excluded list
748  QStringList excluded;
749  for (i = m_listExcluded->count() - 1; i>= 0; i--) {
750  QString curveName = m_listExcluded->item(i)->text();
751  QListWidgetItem *item = m_listExcluded->item (i);
752  if (included.contains (curveName)) {
753  m_listExcluded->removeItemWidget (item);
754  delete item;
755  } else {
756  excluded += item->text();
757  }
758  }
759 
760  m_modelExportAfter->setCurveNamesNotExported(excluded);
761  updateControls();
762  updatePreview();
763 }
764 
765 void DlgSettingsExportFormat::slotListExcluded()
766 {
767  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotListExcluded";
768 
769  updateControls();
770  // Do not call updatePreview since this method changes nothing
771 }
772 
773 void DlgSettingsExportFormat::slotListIncluded()
774 {
775  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotListIncluded";
776 
777  updateControls();
778  // Do not call updatePreview since this method changes nothing
779 }
780 
781 void DlgSettingsExportFormat::slotRelationsPointsEvenlySpaced()
782 {
783  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotRelationsPointsEvenlySpaced";
784 
785  m_modelExportAfter->setPointsSelectionRelations(EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE);
786  updateControls();
787  updatePreview();
788 }
789 
790 void DlgSettingsExportFormat::slotRelationsPointsEvenlySpacedInterval(const QString &)
791 {
792  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotRelationsPointsEvenlySpacedInterval";
793 
794  m_modelExportAfter->setPointsIntervalRelations(m_editRelationsPointsEvenlySpacing->text().toDouble());
795  updateControls();
796  updatePreview();
797 }
798 
799 void DlgSettingsExportFormat::slotRelationsPointsEvenlySpacedIntervalUnits(const QString &)
800 {
801  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotRelationsPointsEvenlySpacedIntervalUnits";
802 
803  int index = m_cmbRelationsPointsEvenlySpacingUnits->currentIndex();
804  ExportPointsIntervalUnits units = (ExportPointsIntervalUnits) m_cmbRelationsPointsEvenlySpacingUnits->itemData (index).toInt();
805 
806  m_modelExportAfter->setPointsIntervalUnitsRelations(units);
807  updateIntervalConstraints(); // Call this before updateControls so constraint checking is updated for ok button
808  updateControls();
809  updatePreview();
810 }
811 
812 void DlgSettingsExportFormat::slotRelationsPointsRaw()
813 {
814  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotRelationsPointsRaw";
815 
816  m_modelExportAfter->setPointsSelectionRelations(EXPORT_POINTS_SELECTION_RELATIONS_RAW);
817  updateControls();
818  updatePreview();
819 }
820 
821 void DlgSettingsExportFormat::slotSaveDefault()
822 {
823  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotSaveDefault";
824 
825  QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
826  settings.beginGroup (SETTINGS_GROUP_EXPORT);
827 
828  settings.setValue (SETTINGS_EXPORT_DELIMITER,
829  QVariant (m_modelExportAfter->delimiter()));
830  settings.setValue (SETTINGS_EXPORT_HEADER,
831  QVariant (m_modelExportAfter->header()));
832  settings.setValue (SETTINGS_EXPORT_LAYOUT_FUNCTIONS,
833  QVariant (m_modelExportAfter->layoutFunctions()));
834  settings.setValue (SETTINGS_EXPORT_POINTS_INTERVAL_FUNCTIONS,
835  QVariant (m_modelExportAfter->pointsIntervalFunctions()));
836  settings.setValue (SETTINGS_EXPORT_POINTS_INTERVAL_RELATIONS,
837  QVariant (m_modelExportAfter->pointsIntervalUnitsRelations()));
838  settings.setValue (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS,
839  QVariant (m_modelExportAfter->pointsIntervalUnitsFunctions()));
840  settings.setValue (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS,
841  QVariant (m_modelExportAfter->pointsIntervalUnitsRelations()));
842  settings.setValue (SETTINGS_EXPORT_POINTS_SELECTION_FUNCTIONS,
843  QVariant (m_modelExportAfter->pointsSelectionFunctions()));
844  settings.setValue (SETTINGS_EXPORT_POINTS_SELECTION_RELATIONS,
845  QVariant (m_modelExportAfter->pointsSelectionFunctions()));
846  settings.setValue (SETTINGS_EXPORT_X_LABEL,
847  QVariant (m_modelExportAfter->xLabel()));
848 
849  settings.endGroup ();
850 }
851 
852 void DlgSettingsExportFormat::slotTabChanged (int)
853 {
854  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotTabChanged";
855 
856  updatePreview();
857 }
858 
859 void DlgSettingsExportFormat::slotXLabel(const QString &)
860 {
861  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotXLabel";
862 
863  m_modelExportAfter->setXLabel (m_editXLabel->text());
864  updateControls();
865  updatePreview();
866 }
867 
868 void DlgSettingsExportFormat::updateControls ()
869 {
870  bool isGoodState = goodIntervalFunctions() &&
871  goodIntervalRelations();
872  enableOk (isGoodState);
873 
874  m_listIncluded->sortItems (Qt::AscendingOrder);
875  m_listExcluded->sortItems (Qt::AscendingOrder);
876 
877  int selectedForInclude = m_listExcluded->selectedItems().count();
878  int selectedForExclude = m_listIncluded->selectedItems().count();
879  int inInclude = m_listIncluded->count();
880 
881  m_btnInclude->setEnabled (selectedForInclude > 0); // Need at least one selection
882  m_btnExclude->setEnabled ((selectedForExclude > 0) && (inInclude - selectedForExclude > 0)); // Need at least one selection, and one left after the move
883 
884  m_editFunctionsPointsEvenlySpacing->setEnabled (m_btnFunctionsPointsEvenlySpaced->isChecked ());
885  m_editRelationsPointsEvenlySpacing->setEnabled (m_btnRelationsPointsEvenlySpaced->isChecked ());
886 
887  m_editXLabel->setEnabled (!m_btnHeaderNone->isChecked());
888 }
889 
890 void DlgSettingsExportFormat::updateIntervalConstraints ()
891 {
892  double functionsMin = (m_modelExportAfter->pointsIntervalUnitsFunctions() == EXPORT_POINTS_INTERVAL_UNITS_GRAPH ?
893  m_minIntervalGraph :
894  m_minIntervalScreen);
895  double relationsMin = (m_modelExportAfter->pointsIntervalUnitsRelations() == EXPORT_POINTS_INTERVAL_UNITS_GRAPH ?
896  m_minIntervalGraph :
897  m_minIntervalScreen);
898 
899  if (m_tabWidget->currentIndex() == TAB_WIDGET_INDEX_FUNCTIONS) {
900 
901  if (m_modelExportAfter->pointsIntervalFunctions() < functionsMin) {
902 
903  m_editFunctionsPointsEvenlySpacing->setText (QString::number (functionsMin));
904 
905  }
906 
907  m_validatorFunctionsPointsEvenlySpacing->setBottom (functionsMin);
908 
909  } else {
910 
911  if (m_modelExportAfter->pointsIntervalRelations() < relationsMin) {
912 
913  m_editRelationsPointsEvenlySpacing->setText (QString::number (relationsMin));
914  m_validatorFunctionsPointsEvenlySpacing->setBottom (relationsMin);
915 
916  }
917 
918  m_validatorRelationsPointsEvenlySpacing->setBottom (relationsMin);
919  }
920 }
921 
922 void DlgSettingsExportFormat::updatePreview()
923 {
924  // Save the scroll position for continuity before and after the preview update
925  int scrollPosition = m_editPreview->verticalScrollBar()->value();
926 
927  QString exportedText;
928  QTextStream str (&exportedText);
929 
930  if (mainWindow().transformation().transformIsDefined()) {
931 
932  // Transformaiton is defined so we can create a preview
933  if (m_tabWidget->currentIndex() == TAB_WIDGET_INDEX_FUNCTIONS) {
934 
935  ExportFileFunctions exportStrategy;
936  exportStrategy.exportToFile (*m_modelExportAfter,
937  cmdMediator().document(),
938  mainWindow().modelMainWindow(),
939  mainWindow().transformation(),
940  str);
941 
942  } else {
943 
944  ExportFileRelations exportStrategy;
945  exportStrategy.exportToFile (*m_modelExportAfter,
946  cmdMediator().document(),
947  mainWindow().modelMainWindow(),
948  mainWindow().transformation(),
949  str);
950 
951  }
952  } else {
953 
954  str << "Preview is unavailable until axis points are defined.";
955  }
956 
957  m_editPreview->setText (exportedText);
958 
959  // Restore scroll position
960  m_editPreview->verticalScrollBar()->setValue (scrollPosition);
961 }
void setPointsSelectionFunctions(ExportPointsSelectionFunctions exportPointsSelectionFunctions)
Set method for point selection for functions.
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
ExportPointsSelectionFunctions pointsSelectionFunctions() const
Get method for point selection for functions.
ExportLayoutFunctions layoutFunctions() const
Get method for functions layout.
ExportPointsIntervalUnits pointsIntervalUnitsRelations() const
Get method for points interval units for relations.
virtual void handleOk()
Process slotOk.
ExportPointsIntervalUnits pointsIntervalUnitsFunctions() const
Get method for points interval units for functions.
Model for DlgSettingsExportFormat and CmdSettingsExportFormat.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
void setPointsSelectionRelations(ExportPointsSelectionRelations exportPointsSelectionRelations)
Set method for point selection for relations.
void setCurveNamesNotExported(const QStringList &curveNamesNotExported)
Set method for curve names not exported.
void exportToFile(const DocumentModelExportFormat &modelExportOverride, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, QTextStream &str) const
Export Document points according to the settings.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:72
void setDelimiter(ExportDelimiter exportDelimiter)
Set method for delimiter.
void setPointsIntervalFunctions(double pointsIntervalFunctions)
Set method for points interval for functions.
double pointsIntervalFunctions() const
Get method for points interval for functions.
ExportHeader header() const
Get method for header.
void setLayoutFunctions(ExportLayoutFunctions exportLayoutFunctions)
Set method for functions layout.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
Strategy class for exporting to a file. This strategy is external to the Document class so that class...
QString xLabel() const
Get method for x label.
void setPointsIntervalUnitsFunctions(ExportPointsIntervalUnits pointsIntervalUnitsFunctions)
Set method for points interval units for functions.
ExportDelimiter delimiter() const
Get method for delimiter.
QStringList curveNamesNotExported() const
Get method for curve names not exported.
void setPointsIntervalRelations(double pointsIntervalRelations)
Set method for relations interval for relations.
double pointsIntervalRelations() const
Get method for relations interval for relations.
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
Definition: Document.cpp:312
void finishPanel(QWidget *subPanel)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
Command queue stack.
Definition: CmdMediator.h:23
Strategy class for exporting to a file. This strategy is external to the Document class so that class...
void setPointsIntervalUnitsRelations(ExportPointsIntervalUnits pointsIntervalUnitsRelations)
Set method for points interval units for relations.
Abstract base class for all Settings dialogs.
void setHeader(ExportHeader exportHeader)
Set method for header.
void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
Definition: CmdMediator.cpp:97
Callback for computing the bounding rectangles of the screen and graph coordinates of the points in t...
MainWindow & mainWindow()
Get method for MainWindow.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:77
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
ExportPointsSelectionRelations pointsSelectionRelations() const
Get method for point selection for relations.
void exportToFile(const DocumentModelExportFormat &modelExportOverride, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, QTextStream &str) const
Export Document points according to the settings.
Command for DlgSettingsExportFormat.
void setXLabel(const QString &xLabel)
Set method for x label.
DlgSettingsExportFormat(MainWindow &mainWindow)
Single constructor.