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