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