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