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  // LOG4CPP_INFO_S is below
434 
435  QString textFunctions = m_editFunctionsPointsEvenlySpacing->text();
436  int posFunctions;
437 
438  bool isGood = (m_validatorFunctionsPointsEvenlySpacing->validate (textFunctions, posFunctions) == QValidator::Acceptable);
439 
440  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::goodIntervalFunctions"
441  << " text=" << textFunctions.toLatin1().data()
442  << " good=" << (isGood ? "true" : "false")
443  << " bottom=" << m_validatorFunctionsPointsEvenlySpacing->bottom()
444  << " top=" << m_validatorFunctionsPointsEvenlySpacing->top();
445 
446  return isGood;
447 }
448 
449 bool DlgSettingsExportFormat::goodIntervalRelations() const
450 {
451  // LOG4CPP_INFO_S is below
452 
453  QString textRelations = m_editRelationsPointsEvenlySpacing->text();
454  int posRelations;
455 
456  bool isGood = (m_validatorRelationsPointsEvenlySpacing->validate (textRelations, posRelations) == QValidator::Acceptable);
457 
458  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::goodIntervalRelations"
459  << " text=" << textRelations.toLatin1().data()
460  << " good=" << (isGood ? "true" : "false")
461  << " bottom=" << m_validatorRelationsPointsEvenlySpacing->bottom()
462  << " top=" << m_validatorRelationsPointsEvenlySpacing->top();
463 
464  return isGood;
465 }
466 
468 {
469  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::handleOk";
470 
472  cmdMediator ().document(),
473  *m_modelExportBefore,
474  *m_modelExportAfter);
475  cmdMediator ().push (cmd);
476 
477  hide ();
478 }
479 
480 void DlgSettingsExportFormat::initializeIntervalConstraints ()
481 {
482  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::initializeIntervalConstraints";
483 
484  const int MAX_POINTS_ACROSS_RANGE = 5000;
485 
486  // Get min and max of graph and screen coordinates
487  CallbackBoundingRects ftor (mainWindow().transformation());
488 
489  Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
491  cmdMediator().iterateThroughCurvesPointsGraphs (ftorWithCallback);
492 
493  // If there are no points, then interval will be zero. That special case must be handled downstream to prevent infinite loops
494  bool isEmpty;
495  double maxSizeGraph = qMax (ftor.boundingRectGraph(isEmpty).width(),
496  ftor.boundingRectGraph(isEmpty).height());
497  double maxSizeScreen = qMax (ftor.boundingRectScreen(isEmpty).width(),
498  ftor.boundingRectScreen(isEmpty).height());
499  m_minIntervalGraph = maxSizeGraph / MAX_POINTS_ACROSS_RANGE;
500  m_minIntervalScreen = maxSizeScreen / MAX_POINTS_ACROSS_RANGE;
501 }
502 
504 {
505  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::load";
506 
507  setCmdMediator (cmdMediator);
508 
509  // Flush old data
510  if (m_modelExportBefore != 0) {
511  delete m_modelExportBefore;
512  }
513  if (m_modelExportAfter != 0) {
514  delete m_modelExportAfter;
515  }
516 
517  // Save new data
518  m_modelExportBefore = new DocumentModelExportFormat (cmdMediator.document());
519  m_modelExportAfter = new DocumentModelExportFormat (cmdMediator.document());
520 
521  // Populate controls. First load excluded curves
522  m_listExcluded->clear();
523  QStringList curveNamesExcluded = m_modelExportAfter->curveNamesNotExported();
524  QStringList::const_iterator itr;
525  for (itr = curveNamesExcluded.begin (); itr != curveNamesExcluded.end(); ++itr) {
526  QString curveNameNotExported = *itr;
527  m_listExcluded->addItem (curveNameNotExported);
528  }
529 
530  // Include curves that are not excluded
531  m_listIncluded->clear();
532  QStringList curveNamesAll = cmdMediator.document().curvesGraphsNames();
533  for (itr = curveNamesAll.begin (); itr != curveNamesAll.end(); itr++) {
534  QString curveName = *itr;
535  if (!curveNamesExcluded.contains (curveName)) {
536  m_listIncluded->addItem (curveName);
537  }
538  }
539 
540  ExportPointsSelectionFunctions pointsSelectionFunctions = m_modelExportAfter->pointsSelectionFunctions();
541  m_btnFunctionsPointsAllCurves->setChecked (pointsSelectionFunctions == EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES);
542  m_btnFunctionsPointsFirstCurve->setChecked (pointsSelectionFunctions == EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_FIRST_CURVE);
543  m_btnFunctionsPointsEvenlySpaced->setChecked (pointsSelectionFunctions == EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_PERIODIC);
544  m_btnFunctionsPointsRaw->setChecked (pointsSelectionFunctions == EXPORT_POINTS_SELECTION_FUNCTIONS_RAW);
545 
546  ExportLayoutFunctions layoutFunctions = m_modelExportAfter->layoutFunctions ();
547  m_btnFunctionsLayoutAllCurves->setChecked (layoutFunctions == EXPORT_LAYOUT_ALL_PER_LINE);
548  m_btnFunctionsLayoutOneCurve->setChecked (layoutFunctions == EXPORT_LAYOUT_ONE_PER_LINE);
549 
550  ExportPointsSelectionRelations pointsSelectionRelations = m_modelExportAfter->pointsSelectionRelations();
551  m_btnRelationsPointsEvenlySpaced->setChecked (pointsSelectionRelations == EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE);
552  m_btnRelationsPointsRaw->setChecked (pointsSelectionRelations == EXPORT_POINTS_SELECTION_RELATIONS_RAW);
553 
554  ExportDelimiter delimiter = m_modelExportAfter->delimiter ();
555  m_btnDelimitersCommas->setChecked (delimiter == EXPORT_DELIMITER_COMMA);
556  m_btnDelimitersSpaces->setChecked (delimiter == EXPORT_DELIMITER_SPACE);
557  m_btnDelimitersTabs->setChecked (delimiter == EXPORT_DELIMITER_TAB);
558 
559  m_chkOverrideCsvTsv->setChecked (m_modelExportAfter->overrideCsvTsv());
560 
561  ExportHeader header = m_modelExportAfter->header ();
562  m_btnHeaderNone->setChecked (header == EXPORT_HEADER_NONE);
563  m_btnHeaderSimple->setChecked (header == EXPORT_HEADER_SIMPLE);
564  m_btnHeaderGnuplot->setChecked (header == EXPORT_HEADER_GNUPLOT);
565 
566  m_editXLabel->setText (m_modelExportAfter->xLabel());
567 
568  m_editFunctionsPointsEvenlySpacing->setText (QString::number (m_modelExportAfter->pointsIntervalFunctions()));
569  m_editRelationsPointsEvenlySpacing->setText (QString::number (m_modelExportAfter->pointsIntervalRelations()));
570 
571  ExportPointsIntervalUnits pointsIntervalUnitsFunctions = m_modelExportAfter->pointsIntervalUnitsFunctions();
572  ExportPointsIntervalUnits pointsIntervalUnitsRelations = m_modelExportAfter->pointsIntervalUnitsRelations();
573  int indexFunctions = m_cmbFunctionsPointsEvenlySpacingUnits->findData (QVariant (pointsIntervalUnitsFunctions));
574  int indexRelations = m_cmbRelationsPointsEvenlySpacingUnits->findData (QVariant (pointsIntervalUnitsRelations));
575  m_cmbFunctionsPointsEvenlySpacingUnits->setCurrentIndex (indexFunctions);
576  m_cmbRelationsPointsEvenlySpacingUnits->setCurrentIndex (indexRelations);
577 
578  initializeIntervalConstraints ();
579 
580  updateControls();
581  updateIntervalConstraints();
582  enableOk (false); // Disable Ok button since there not yet any changes
583  updatePreview();
584 }
585 
586 void DlgSettingsExportFormat::slotDelimitersCommas()
587 {
588  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotDelimitersCommas";
589 
590  m_modelExportAfter->setDelimiter(EXPORT_DELIMITER_COMMA);
591  updateControls();
592  updatePreview();
593 }
594 
595 void DlgSettingsExportFormat::slotDelimitersSpaces()
596 {
597  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotDelimitersSpaces";
598 
599  m_modelExportAfter->setDelimiter(EXPORT_DELIMITER_SPACE);
600  updateControls();
601  updatePreview();
602 }
603 
604 void DlgSettingsExportFormat::slotDelimitersTabs()
605 {
606  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotDelimitersTabs";
607 
608  m_modelExportAfter->setDelimiter(EXPORT_DELIMITER_TAB);
609  updateControls();
610  updatePreview();
611 }
612 
613 void DlgSettingsExportFormat::slotExclude ()
614 {
615  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotExclude";
616 
617  // Perform forward pass to get excluded curves in the proper order
618  int i;
619  QStringList excluded;
620  for (i = 0; i < m_listIncluded->count(); i++) {
621  if (m_listIncluded->item(i)->isSelected()) {
622  excluded += m_listIncluded->item(i)->text();
623  }
624  }
625 
626  // Add the excluded curves to the excluded list
627  for (i = 0; i < excluded.count(); i++) {
628  QString curveName = excluded.at (i);
629  m_listExcluded->addItem (curveName);
630  }
631 
632  // Perform backwards pass to remove the excluded curves from the included list
633  for (i = m_listIncluded->count() - 1; i>= 0; i--) {
634  QString curveName = m_listIncluded->item(i)->text();
635  if (excluded.contains (curveName)) {
636  QListWidgetItem *item = m_listIncluded->item (i);
637  m_listIncluded->removeItemWidget (item);
638  delete item;
639  }
640  }
641 
642  m_modelExportAfter->setCurveNamesNotExported(excluded);
643  updateControls();
644  updatePreview();
645 }
646 
647 void DlgSettingsExportFormat::slotFunctionsLayoutAllCurves()
648 {
649  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsLayoutAllCurves";
650 
651  m_modelExportAfter->setLayoutFunctions(EXPORT_LAYOUT_ALL_PER_LINE);
652  updateControls();
653  updatePreview();
654 }
655 
656 void DlgSettingsExportFormat::slotFunctionsLayoutOneCurve()
657 {
658  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsLayoutOneCurve";
659 
660  m_modelExportAfter->setLayoutFunctions(EXPORT_LAYOUT_ONE_PER_LINE);
661  updateControls();
662  updatePreview();
663 }
664 
665 void DlgSettingsExportFormat::slotFunctionsPointsAllCurves()
666 {
667  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsAllCurves";
668 
669  m_modelExportAfter->setPointsSelectionFunctions(EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES);
670  updateControls();
671  updatePreview();
672 }
673 
674 void DlgSettingsExportFormat::slotFunctionsPointsEvenlySpaced()
675 {
676  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsEvenlySpaced";
677 
678  m_modelExportAfter->setPointsSelectionFunctions(EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_PERIODIC);
679  updateControls();
680  updatePreview();
681 }
682 
683 void DlgSettingsExportFormat::slotFunctionsPointsEvenlySpacedInterval(const QString &)
684 {
685  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsEvenlySpacedInterval";
686 
687  // Prevent infinite loop on empty and "-" values which get treated as zero interval
688  if (goodIntervalFunctions()) {
689  m_modelExportAfter->setPointsIntervalFunctions(m_editFunctionsPointsEvenlySpacing->text().toDouble());
690  updateControls();
691  updatePreview();
692  } else {
693  m_editPreview->setText(EMPTY_PREVIEW);
694  }
695 }
696 
697 void DlgSettingsExportFormat::slotFunctionsPointsEvenlySpacedIntervalUnits(const QString &)
698 {
699  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsEvenlySpacedIntervalUnits";
700 
701  int index = m_cmbFunctionsPointsEvenlySpacingUnits->currentIndex();
702  ExportPointsIntervalUnits units = (ExportPointsIntervalUnits) m_cmbFunctionsPointsEvenlySpacingUnits->itemData (index).toInt();
703 
704  m_modelExportAfter->setPointsIntervalUnitsFunctions(units);
705  updateIntervalConstraints(); // Call this before updateControls so constraint checking is updated for ok button
706  updateControls();
707  updatePreview();
708 }
709 
710 void DlgSettingsExportFormat::slotFunctionsPointsFirstCurve()
711 {
712  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsFirstCurve";
713 
714  m_modelExportAfter->setPointsSelectionFunctions(EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_FIRST_CURVE);
715  updateControls();
716  updatePreview();
717 }
718 
719 void DlgSettingsExportFormat::slotFunctionsPointsRaw()
720 {
721  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsRaw";
722 
723  m_modelExportAfter->setPointsSelectionFunctions(EXPORT_POINTS_SELECTION_FUNCTIONS_RAW);
724  updateControls();
725  updatePreview();
726 }
727 
728 void DlgSettingsExportFormat::slotHeaderGnuplot()
729 {
730  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotHeaderGnuplot";
731 
732  m_modelExportAfter->setHeader(EXPORT_HEADER_GNUPLOT);
733  updateControls();
734  updatePreview();
735 }
736 
737 void DlgSettingsExportFormat::slotHeaderNone()
738 {
739  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotHeaderNone";
740 
741  m_modelExportAfter->setHeader(EXPORT_HEADER_NONE);
742  updateControls();
743  updatePreview();
744 }
745 
746 void DlgSettingsExportFormat::slotHeaderSimple()
747 {
748  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotHeaderSimple";
749 
750  m_modelExportAfter->setHeader(EXPORT_HEADER_SIMPLE);
751  updateControls();
752  updatePreview();
753 }
754 
755 void DlgSettingsExportFormat::slotInclude ()
756 {
757  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotInclude";
758 
759  // Perform forward pass to get included curves in the proper order
760  int i;
761  QStringList included;
762  for (i = 0; i < m_listExcluded->count(); i++) {
763  if (m_listExcluded->item(i)->isSelected()) {
764  included += m_listExcluded->item(i)->text();
765  }
766  }
767 
768  // Add the included curves to the included list
769  for (i = 0; i < included.count(); i++) {
770  QString curveName = included.at (i);
771  m_listIncluded->addItem (curveName);
772  }
773 
774  // Perform backwards pass to remove the included curves from the excluded list
775  QStringList excluded;
776  for (i = m_listExcluded->count() - 1; i>= 0; i--) {
777  QString curveName = m_listExcluded->item(i)->text();
778  QListWidgetItem *item = m_listExcluded->item (i);
779  if (included.contains (curveName)) {
780  m_listExcluded->removeItemWidget (item);
781  delete item;
782  } else {
783  excluded += item->text();
784  }
785  }
786 
787  m_modelExportAfter->setCurveNamesNotExported(excluded);
788  updateControls();
789  updatePreview();
790 }
791 
792 void DlgSettingsExportFormat::slotListExcluded()
793 {
794  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotListExcluded";
795 
796  updateControls();
797  // Do not call updatePreview since this method changes nothing
798 }
799 
800 void DlgSettingsExportFormat::slotListIncluded()
801 {
802  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotListIncluded";
803 
804  updateControls();
805  // Do not call updatePreview since this method changes nothing
806 }
807 
808 void DlgSettingsExportFormat::slotOverrideCsvTsv(int)
809 {
810  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotOverrideCsvTsv";
811 
812  m_modelExportAfter->setOverrideCsvTsv(m_chkOverrideCsvTsv->isChecked());
813  updateControls();
814  updatePreview();
815 }
816 
817 void DlgSettingsExportFormat::slotRelationsPointsEvenlySpaced()
818 {
819  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotRelationsPointsEvenlySpaced";
820 
821  m_modelExportAfter->setPointsSelectionRelations(EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE);
822  updateControls();
823  updatePreview();
824 }
825 
826 void DlgSettingsExportFormat::slotRelationsPointsEvenlySpacedInterval(const QString &)
827 {
828  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotRelationsPointsEvenlySpacedInterval";
829 
830  m_modelExportAfter->setPointsIntervalRelations(m_editRelationsPointsEvenlySpacing->text().toDouble());
831  updateControls();
832  updatePreview();
833 }
834 
835 void DlgSettingsExportFormat::slotRelationsPointsEvenlySpacedIntervalUnits(const QString &)
836 {
837  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotRelationsPointsEvenlySpacedIntervalUnits";
838 
839  int index = m_cmbRelationsPointsEvenlySpacingUnits->currentIndex();
840  ExportPointsIntervalUnits units = (ExportPointsIntervalUnits) m_cmbRelationsPointsEvenlySpacingUnits->itemData (index).toInt();
841 
842  m_modelExportAfter->setPointsIntervalUnitsRelations(units);
843  updateIntervalConstraints(); // Call this before updateControls so constraint checking is updated for ok button
844  updateControls();
845  updatePreview();
846 }
847 
848 void DlgSettingsExportFormat::slotRelationsPointsRaw()
849 {
850  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotRelationsPointsRaw";
851 
852  m_modelExportAfter->setPointsSelectionRelations(EXPORT_POINTS_SELECTION_RELATIONS_RAW);
853  updateControls();
854  updatePreview();
855 }
856 
857 void DlgSettingsExportFormat::slotSaveDefault()
858 {
859  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotSaveDefault";
860 
861  QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
862  settings.beginGroup (SETTINGS_GROUP_EXPORT);
863 
864  settings.setValue (SETTINGS_EXPORT_DELIMITER,
865  QVariant (m_modelExportAfter->delimiter()));
866  settings.setValue (SETTINGS_EXPORT_HEADER,
867  QVariant (m_modelExportAfter->header()));
868  settings.setValue (SETTINGS_EXPORT_LAYOUT_FUNCTIONS,
869  QVariant (m_modelExportAfter->layoutFunctions()));
870  settings.setValue (SETTINGS_EXPORT_POINTS_INTERVAL_FUNCTIONS,
871  QVariant (m_modelExportAfter->pointsIntervalFunctions()));
872  settings.setValue (SETTINGS_EXPORT_POINTS_INTERVAL_RELATIONS,
873  QVariant (m_modelExportAfter->pointsIntervalUnitsRelations()));
874  settings.setValue (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS,
875  QVariant (m_modelExportAfter->pointsIntervalUnitsFunctions()));
876  settings.setValue (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS,
877  QVariant (m_modelExportAfter->pointsIntervalUnitsRelations()));
878  settings.setValue (SETTINGS_EXPORT_POINTS_SELECTION_FUNCTIONS,
879  QVariant (m_modelExportAfter->pointsSelectionFunctions()));
880  settings.setValue (SETTINGS_EXPORT_POINTS_SELECTION_RELATIONS,
881  QVariant (m_modelExportAfter->pointsSelectionFunctions()));
882  settings.setValue (SETTINGS_EXPORT_X_LABEL,
883  QVariant (m_modelExportAfter->xLabel()));
884 
885  settings.endGroup ();
886 }
887 
888 void DlgSettingsExportFormat::slotTabChanged (int)
889 {
890  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotTabChanged";
891 
892  updatePreview();
893 }
894 
895 void DlgSettingsExportFormat::slotXLabel(const QString &)
896 {
897  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotXLabel";
898 
899  m_modelExportAfter->setXLabel (m_editXLabel->text());
900  updateControls();
901  updatePreview();
902 }
903 
904 void DlgSettingsExportFormat::updateControls ()
905 {
906  bool isGoodState = goodIntervalFunctions() &&
907  goodIntervalRelations();
908  enableOk (isGoodState);
909 
910  m_listIncluded->sortItems (Qt::AscendingOrder);
911  m_listExcluded->sortItems (Qt::AscendingOrder);
912 
913  int selectedForInclude = m_listExcluded->selectedItems().count();
914  int selectedForExclude = m_listIncluded->selectedItems().count();
915  int inInclude = m_listIncluded->count();
916 
917  m_btnInclude->setEnabled (selectedForInclude > 0); // Need at least one selection
918  m_btnExclude->setEnabled ((selectedForExclude > 0) && (inInclude - selectedForExclude > 0)); // Need at least one selection, and one left after the move
919 
920  m_editFunctionsPointsEvenlySpacing->setEnabled (m_btnFunctionsPointsEvenlySpaced->isChecked ());
921  m_editRelationsPointsEvenlySpacing->setEnabled (m_btnRelationsPointsEvenlySpaced->isChecked ());
922 
923  m_editXLabel->setEnabled (!m_btnHeaderNone->isChecked());
924 }
925 
926 void DlgSettingsExportFormat::updateIntervalConstraints ()
927 {
928  double functionsMin = (m_modelExportAfter->pointsIntervalUnitsFunctions() == EXPORT_POINTS_INTERVAL_UNITS_GRAPH ?
929  m_minIntervalGraph :
930  m_minIntervalScreen);
931  double relationsMin = (m_modelExportAfter->pointsIntervalUnitsRelations() == EXPORT_POINTS_INTERVAL_UNITS_GRAPH ?
932  m_minIntervalGraph :
933  m_minIntervalScreen);
934 
935  if (m_tabWidget->currentIndex() == TAB_WIDGET_INDEX_FUNCTIONS) {
936 
937  if (m_modelExportAfter->pointsIntervalFunctions() < functionsMin) {
938 
939  m_editFunctionsPointsEvenlySpacing->setText (QString::number (functionsMin));
940 
941  }
942 
943  m_validatorFunctionsPointsEvenlySpacing->setBottom (functionsMin);
944 
945  } else {
946 
947  if (m_modelExportAfter->pointsIntervalRelations() < relationsMin) {
948 
949  m_editRelationsPointsEvenlySpacing->setText (QString::number (relationsMin));
950  m_validatorFunctionsPointsEvenlySpacing->setBottom (relationsMin);
951 
952  }
953 
954  m_validatorRelationsPointsEvenlySpacing->setBottom (relationsMin);
955  }
956 }
957 
958 void DlgSettingsExportFormat::updatePreview()
959 {
960  // Save the scroll position for continuity before and after the preview update
961  int scrollPosition = m_editPreview->verticalScrollBar()->value();
962 
963  QString exportedText;
964  QTextStream str (&exportedText);
965 
966  if (mainWindow().transformation().transformIsDefined()) {
967 
968  // Transformaiton is defined so we can create a preview
969  if (m_tabWidget->currentIndex() == TAB_WIDGET_INDEX_FUNCTIONS) {
970 
971  ExportFileFunctions exportStrategy;
972  exportStrategy.exportToFile (*m_modelExportAfter,
973  cmdMediator().document(),
974  mainWindow().modelMainWindow(),
975  mainWindow().transformation(),
976  str);
977 
978  } else {
979 
980  ExportFileRelations exportStrategy;
981  exportStrategy.exportToFile (*m_modelExportAfter,
982  cmdMediator().document(),
983  mainWindow().modelMainWindow(),
984  mainWindow().transformation(),
985  str);
986 
987  }
988  } else {
989 
990  str << "Preview is unavailable until axis points are defined.";
991  }
992 
993  m_editPreview->setText (exportedText);
994 
995  // Restore scroll position
996  m_editPreview->verticalScrollBar()->setValue (scrollPosition);
997 }
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.