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