00001
00002
00003
00004
00005
00006
00007 #include "CallbackBoundingRects.h"
00008 #include "CmdMediator.h"
00009 #include "CmdSettingsExportFormat.h"
00010 #include "DocumentModelExportFormat.h"
00011 #include "DlgSettingsExportFormat.h"
00012 #include "ExportFileFunctions.h"
00013 #include "ExportFileRelations.h"
00014 #include "Logger.h"
00015 #include "MainWindow.h"
00016 #include "MainWindowModel.h"
00017 #include <QCheckBox>
00018 #include <QComboBox>
00019 #include <QDoubleValidator>
00020 #include <QGridLayout>
00021 #include <QGroupBox>
00022 #include <QHBoxLayout>
00023 #include <QLabel>
00024 #include <QLineEdit>
00025 #include <QListWidget>
00026 #include <QPushButton>
00027 #include <QRadioButton>
00028 #include <QScrollBar>
00029 #include <QSettings>
00030 #include <QTabWidget>
00031 #include <QTextEdit>
00032 #include <QTextStream>
00033 #include <QVBoxLayout>
00034 #include "Settings.h"
00035 #include "Transformation.h"
00036
00037
00038 const QString COLOR_FUNCTIONS = ("#DDDDFF");
00039 const QString COLOR_RELATIONS = ("#DDFFDD");
00040
00041 const int MIN_INDENT_COLUMN_WIDTH = 20;
00042 const int MIN_HEADER_EMPTY_COLUMN_WIDTH = 10;
00043 const int MIN_EDIT_WIDTH = 110;
00044 const int MAX_EDIT_WIDTH = 180;
00045
00046 const int TAB_WIDGET_INDEX_FUNCTIONS = 0;
00047 const int TAB_WIDGET_INDEX_RELATIONS = 1;
00048
00049 const QString EMPTY_PREVIEW;
00050
00051 const int MINIMUM_DIALOG_WIDTH_EXPORT_FORMAT = 650;
00052 const int MINIMUM_HEIGHT = 780;
00053
00054 DlgSettingsExportFormat::DlgSettingsExportFormat(MainWindow &mainWindow) :
00055 DlgSettingsAbstractBase (tr ("Export Format"),
00056 "DlgSettingsExportFormat",
00057 mainWindow),
00058 m_modelExportBefore (0),
00059 m_modelExportAfter (0),
00060 m_haveFunction (false),
00061 m_haveRelation (false)
00062 {
00063 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::DlgSettingsExportFormat";
00064
00065 QWidget *subPanel = createSubPanel ();
00066 finishPanel (subPanel,
00067 MINIMUM_DIALOG_WIDTH_EXPORT_FORMAT);
00068 }
00069
00070 DlgSettingsExportFormat::~DlgSettingsExportFormat()
00071 {
00072 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::~DlgSettingsExportFormat";
00073 }
00074
00075 void DlgSettingsExportFormat::createCurveSelection (QGridLayout *layout, int &row)
00076 {
00077 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createCurveSelection";
00078
00079 QLabel *labelIncluded = new QLabel (tr ("Included"));
00080 layout->addWidget (labelIncluded, row, 0);
00081
00082 QLabel *labelExcluded = new QLabel (tr ("Not included"));
00083 layout->addWidget (labelExcluded, row++, 2);
00084
00085 m_listIncluded = new QListWidget;
00086 m_listIncluded->setSortingEnabled (false);
00087 m_listIncluded->setWhatsThis (tr ("List of curves to be included in the exported file.\n\n"
00088 "The order of the curves here does not affect the order in the exported file. That "
00089 "order is determined by the Curves settings."));
00090 m_listIncluded->setSelectionMode (QAbstractItemView::MultiSelection);
00091 layout->addWidget (m_listIncluded, row, 0, 4, 1);
00092 connect (m_listIncluded, SIGNAL (itemSelectionChanged ()), this, SLOT (slotListIncluded()));
00093
00094 m_listExcluded = new QListWidget;
00095 m_listExcluded->setSortingEnabled (false);
00096 m_listExcluded->setWhatsThis (tr ("List of curves to be excluded from the exported file"));
00097 m_listExcluded->setSelectionMode (QAbstractItemView::MultiSelection);
00098 layout->addWidget (m_listExcluded, row++, 2, 4, 1);
00099 connect (m_listExcluded, SIGNAL (itemSelectionChanged ()), this, SLOT (slotListExcluded()));
00100
00101 m_btnInclude = new QPushButton (tr ("<<Include"));
00102 m_btnInclude->setEnabled (false);
00103 m_btnInclude->setWhatsThis (tr ("Move the currently selected curve(s) from the excluded list"));
00104 layout->addWidget (m_btnInclude, row++, 1);
00105 connect (m_btnInclude, SIGNAL (released ()), this, SLOT (slotInclude()));
00106
00107 m_btnExclude = new QPushButton (tr ("Exclude>>"));
00108 m_btnExclude->setEnabled (false);
00109 m_btnExclude->setWhatsThis (tr ("Move the currently selected curve(s) from the included list"));
00110 layout->addWidget (m_btnExclude, row++, 1);
00111 connect (m_btnExclude, SIGNAL (released ()), this, SLOT (slotExclude()));
00112
00113 row++;
00114 }
00115
00116 void DlgSettingsExportFormat::createDelimiters (QHBoxLayout *layoutMisc)
00117 {
00118 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createDelimiters";
00119
00120 QGroupBox *groupDelimiters = new QGroupBox (tr ("Delimiters"));
00121 layoutMisc->addWidget (groupDelimiters, 1);
00122
00123 QVBoxLayout *layoutDelimiters = new QVBoxLayout;
00124 groupDelimiters->setLayout (layoutDelimiters);
00125
00126 m_btnDelimitersCommas = new QRadioButton (exportDelimiterToString (EXPORT_DELIMITER_COMMA));
00127 m_btnDelimitersCommas->setWhatsThis (tr ("Exported file will have commas between adjacent values, unless overridden by tabs in TSV files."));
00128 layoutDelimiters->addWidget (m_btnDelimitersCommas);
00129 connect (m_btnDelimitersCommas, SIGNAL (released ()), this, SLOT (slotDelimitersCommas()));
00130
00131 m_btnDelimitersSpaces = new QRadioButton (exportDelimiterToString (EXPORT_DELIMITER_SPACE));
00132 m_btnDelimitersSpaces->setWhatsThis (tr ("Exported file will have spaces between adjacent values, unless overridden by commas in CSV files, "
00133 "or tabs in TSV files."));
00134 layoutDelimiters->addWidget (m_btnDelimitersSpaces);
00135 connect (m_btnDelimitersSpaces, SIGNAL (released ()), this, SLOT (slotDelimitersSpaces()));
00136
00137 m_btnDelimitersTabs = new QRadioButton (exportDelimiterToString (EXPORT_DELIMITER_TAB));
00138 m_btnDelimitersTabs->setWhatsThis (tr ("Exported file will have tabs between adjacent values, unless overridden by commas in CSV files."));
00139 layoutDelimiters->addWidget (m_btnDelimitersTabs);
00140 connect (m_btnDelimitersTabs, SIGNAL (released ()), this, SLOT (slotDelimitersTabs()));
00141
00142 m_btnDelimitersSemicolons = new QRadioButton (exportDelimiterToString (EXPORT_DELIMITER_SEMICOLON));
00143 m_btnDelimitersSemicolons->setWhatsThis (tr ("Exported file will have semicolons between adjacent values, unless overridden by commas in CSV files."));
00144 layoutDelimiters->addWidget (m_btnDelimitersSemicolons);
00145 connect (m_btnDelimitersSemicolons, SIGNAL (released ()), this, SLOT (slotDelimitersSemicolons()));
00146
00147 m_chkOverrideCsvTsv = new QCheckBox (tr ("Override in CSV/TSV files"));
00148 m_chkOverrideCsvTsv->setWhatsThis (tr ("Comma-separated value (CSV) files and tab-separated value (TSV) files will use commas and tabs "
00149 "respectively, unless this setting is selected. Selecting this setting will apply the delimiter setting "
00150 "to every file."));
00151 connect (m_chkOverrideCsvTsv, SIGNAL (stateChanged (int)), this, SLOT (slotOverrideCsvTsv(int)));
00152 layoutDelimiters->addWidget (m_chkOverrideCsvTsv);
00153 }
00154
00155 void DlgSettingsExportFormat::createFileLayout (QHBoxLayout *layoutMisc)
00156 {
00157 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createFileLayout";
00158
00159 QGroupBox *groupLayout = new QGroupBox (tr ("Layout"));
00160 layoutMisc->addWidget (groupLayout, 1);
00161
00162 QVBoxLayout *layoutLayout = new QVBoxLayout;
00163 groupLayout->setLayout (layoutLayout);
00164
00165 m_btnCurvesLayoutAllCurves = new QRadioButton (tr ("All curves on each line"));
00166 m_btnCurvesLayoutAllCurves->setWhatsThis (tr ("Exported file will have, on each line, "
00167 "an X value, the Y value for the first curve, the Y value for the second curve,..."));
00168 layoutLayout->addWidget (m_btnCurvesLayoutAllCurves);
00169 connect (m_btnCurvesLayoutAllCurves, SIGNAL (released()), this, SLOT (slotFunctionsLayoutAllCurves ()));
00170
00171 m_btnCurvesLayoutOneCurve = new QRadioButton (tr ("One curve on each line"));
00172 m_btnCurvesLayoutOneCurve->setWhatsThis (tr ("Exported file will have all the points for "
00173 "the first curve, with one X-Y pair on each line, then the points for the second curve,..."));
00174 layoutLayout->addWidget (m_btnCurvesLayoutOneCurve);
00175 connect (m_btnCurvesLayoutOneCurve, SIGNAL (released()), this, SLOT (slotFunctionsLayoutOneCurve ()));
00176 }
00177
00178 void DlgSettingsExportFormat::createFunctionsPointsSelection (QHBoxLayout *layoutFunctions)
00179 {
00180 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createFunctionsPointsSelection";
00181
00182 QGroupBox *groupPointsSelection = new QGroupBox (tr ("Function Points Selection"));
00183 layoutFunctions->addWidget (groupPointsSelection, 1);
00184
00185 QGridLayout *layoutPointsSelections = new QGridLayout;
00186 groupPointsSelection->setLayout (layoutPointsSelections);
00187
00188 layoutPointsSelections->setColumnMinimumWidth(0, MIN_INDENT_COLUMN_WIDTH);
00189 layoutPointsSelections->setColumnStretch (0, 0);
00190 layoutPointsSelections->setColumnStretch (1, 0);
00191 layoutPointsSelections->setColumnStretch (2, 0);
00192 layoutPointsSelections->setColumnStretch (3, 1);
00193
00194 int row = 0;
00195
00196 m_btnFunctionsPointsAllCurves = new QRadioButton (tr ("Interpolate Ys at Xs from all curves"));
00197 m_btnFunctionsPointsAllCurves->setWhatsThis (tr ("Exported file will have values at every unique X "
00198 "value from every curve. Y values will be linearly interpolated if necessary"));
00199 layoutPointsSelections->addWidget (m_btnFunctionsPointsAllCurves, row++, 0, 1, 4);
00200 connect (m_btnFunctionsPointsAllCurves, SIGNAL (released()), this, SLOT (slotFunctionsPointsAllCurves()));
00201
00202 m_btnFunctionsPointsFirstCurve = new QRadioButton (tr ("Interpolate Ys at Xs from first curve"));
00203 m_btnFunctionsPointsFirstCurve->setWhatsThis (tr ("Exported file will have values at every unique X "
00204 "value from the first curve. Y values will be linearly interpolated if necessary"));
00205 layoutPointsSelections->addWidget (m_btnFunctionsPointsFirstCurve, row++, 0, 1, 4);
00206 connect (m_btnFunctionsPointsFirstCurve, SIGNAL (released()), this, SLOT (slotFunctionsPointsFirstCurve()));
00207
00208 m_btnFunctionsPointsEvenlySpaced = new QRadioButton (tr ("Interpolate Ys at evenly spaced X values."));
00209 m_btnFunctionsPointsEvenlySpaced->setWhatsThis (tr ("Exported file will have values at evenly spaced X values, separated by the interval selected below."));
00210 layoutPointsSelections->addWidget (m_btnFunctionsPointsEvenlySpaced, row++, 0, 1, 4);
00211 connect (m_btnFunctionsPointsEvenlySpaced, SIGNAL (released()), this, SLOT (slotFunctionsPointsEvenlySpaced()));
00212
00213 QLabel *labelInterval = new QLabel (tr ("Interval:"));
00214 layoutPointsSelections->addWidget (labelInterval, row, 1, 1, 1, Qt::AlignRight);
00215
00216 m_editFunctionsPointsEvenlySpacing = new QLineEdit;
00217 m_validatorFunctionsPointsEvenlySpacing = new QDoubleValidator;
00218 m_editFunctionsPointsEvenlySpacing->setValidator (m_validatorFunctionsPointsEvenlySpacing);
00219 m_editFunctionsPointsEvenlySpacing->setMinimumWidth (MIN_EDIT_WIDTH);
00220 m_editFunctionsPointsEvenlySpacing->setMaximumWidth (MAX_EDIT_WIDTH);
00221 m_editFunctionsPointsEvenlySpacing->setWhatsThis (tr ("Interval, in the units of X, between successive points in the X direction.\n\n"
00222 "If the scale is linear, then this interval is added to successive X values. If the scale is "
00223 "logarithmic, then this interval is multiplied to successive X values.\n\n"
00224 "The X values will be automatically aligned along simple numbers. If the first and/or last "
00225 "points are not along the aligned X values, then one or two additional points are added "
00226 "as necessary."));
00227 layoutPointsSelections->addWidget (m_editFunctionsPointsEvenlySpacing, row, 2, 1, 1, Qt::AlignLeft);
00228 connect (m_editFunctionsPointsEvenlySpacing, SIGNAL (textChanged(const QString &)), this, SLOT (slotFunctionsPointsEvenlySpacedInterval(const QString &)));
00229
00230 m_cmbFunctionsPointsEvenlySpacingUnits = new QComboBox;
00231 m_cmbFunctionsPointsEvenlySpacingUnits->setWhatsThis (tr ("Units for spacing interval.\n\n"
00232 "Pixel units are preferred when the spacing is to be independent of the X scale. The spacing will be "
00233 "consistent across the graph, even if the X scale is logarithmic.\n\n"
00234 "Graph units are preferred when the spacing is to depend on the X scale."));
00235 m_cmbFunctionsPointsEvenlySpacingUnits->addItem(exportPointsIntervalUnitsToString (EXPORT_POINTS_INTERVAL_UNITS_GRAPH),
00236 QVariant (EXPORT_POINTS_INTERVAL_UNITS_GRAPH));
00237 m_cmbFunctionsPointsEvenlySpacingUnits->addItem(exportPointsIntervalUnitsToString (EXPORT_POINTS_INTERVAL_UNITS_SCREEN),
00238 QVariant (EXPORT_POINTS_INTERVAL_UNITS_SCREEN));
00239 connect (m_cmbFunctionsPointsEvenlySpacingUnits, SIGNAL (activated (const QString &)),
00240 this, SLOT (slotFunctionsPointsEvenlySpacedIntervalUnits (const QString &)));
00241 layoutPointsSelections->addWidget (m_cmbFunctionsPointsEvenlySpacingUnits, row++, 3, 1, 1, Qt::AlignLeft);
00242
00243 m_btnFunctionsPointsRaw = new QRadioButton (tr ("Raw Xs and Ys"));
00244 m_btnFunctionsPointsRaw->setWhatsThis (tr ("Exported file will have only original X and Y values"));
00245 layoutPointsSelections->addWidget (m_btnFunctionsPointsRaw, row++, 0, 1, 4);
00246 connect (m_btnFunctionsPointsRaw, SIGNAL (released()), this, SLOT (slotFunctionsPointsRaw()));
00247 }
00248
00249 void DlgSettingsExportFormat::createHeader (QHBoxLayout *layoutMisc)
00250 {
00251 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createHeader";
00252
00253 const int COLUMN_RADIO_BUTTONS = 0, COLUMN_EMPTY = 1, COLUMN_LABEL = 2;
00254
00255 QGroupBox *groupHeader = new QGroupBox (tr ("Header"));
00256 layoutMisc->addWidget (groupHeader, 1);
00257
00258 QGridLayout *layoutHeader = new QGridLayout;
00259 layoutHeader->setColumnMinimumWidth(COLUMN_EMPTY,
00260 MIN_HEADER_EMPTY_COLUMN_WIDTH);
00261 groupHeader->setLayout (layoutHeader);
00262 int row = 0;
00263
00264 m_btnHeaderNone = new QRadioButton (exportHeaderToString (EXPORT_HEADER_NONE));
00265 m_btnHeaderNone->setWhatsThis (tr ("Exported file will have no header line"));
00266 layoutHeader->addWidget (m_btnHeaderNone, row++, COLUMN_RADIO_BUTTONS, 1, 1);
00267 connect (m_btnHeaderNone, SIGNAL (released ()), this, SLOT (slotHeaderNone()));
00268
00269 m_btnHeaderSimple = new QRadioButton (exportHeaderToString (EXPORT_HEADER_SIMPLE));
00270 m_btnHeaderSimple->setWhatsThis (tr ("Exported file will have simple header line"));
00271 layoutHeader->addWidget (m_btnHeaderSimple, row++, COLUMN_RADIO_BUTTONS, 1, 1);
00272 connect (m_btnHeaderSimple, SIGNAL (released ()), this, SLOT (slotHeaderSimple()));
00273
00274 m_btnHeaderGnuplot = new QRadioButton (exportHeaderToString (EXPORT_HEADER_GNUPLOT));
00275 m_btnHeaderGnuplot->setWhatsThis (tr ("Exported file will have gnuplot header line"));
00276 layoutHeader->addWidget (m_btnHeaderGnuplot, row++, COLUMN_RADIO_BUTTONS, 1, 1);
00277 connect (m_btnHeaderGnuplot, SIGNAL (released()), this, SLOT (slotHeaderGnuplot()));
00278
00279 createXLabel (layoutHeader,
00280 COLUMN_LABEL);
00281 }
00282
00283 void DlgSettingsExportFormat::createOptionalSaveDefault (QHBoxLayout *layout)
00284 {
00285 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createOptionalSaveDefault";
00286
00287 m_btnSaveDefault = new QPushButton (tr ("Save As Default"));
00288 m_btnSaveDefault->setWhatsThis (tr ("Save the settings for use as future defaults."));
00289 connect (m_btnSaveDefault, SIGNAL (released ()), this, SLOT (slotSaveDefault ()));
00290 layout->addWidget (m_btnSaveDefault, 0, Qt::AlignLeft);
00291 }
00292
00293 void DlgSettingsExportFormat::createPreview(QGridLayout *layout, int &row)
00294 {
00295 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createPreview";
00296
00297 QLabel *label = new QLabel (tr ("Preview"));
00298 layout->addWidget (label, row, 0, 1, 3);
00299
00300
00301 QLabel *labelLegend = new QLabel;
00302 labelLegend->setTextFormat (Qt::RichText);
00303 QString legendHtml = QString ("<span style=\"background-color: %1\"> Functions </span>"
00304 " "
00305 "<span style=\"background-color: %2\"> Relations </span>")
00306 .arg (COLOR_FUNCTIONS)
00307 .arg (COLOR_RELATIONS);
00308 labelLegend->setText (legendHtml);
00309 layout->addWidget (labelLegend, row++, 1, 1, 2, Qt::AlignRight);
00310
00311 m_editPreview = new QTextEdit;
00312 m_editPreview->setReadOnly (true);
00313 m_editPreview->setWhatsThis (tr ("Preview window shows how current settings affect the exported file.\n\n"
00314 "Functions (shown here in blue) are output first, followed by relations "
00315 "(shown here in green) if any exist."));
00316 m_editPreview->setMinimumHeight (MINIMUM_PREVIEW_HEIGHT);
00317 m_editPreview->document()->setDefaultStyleSheet("div { padding-left: 20px; }");
00318 QPalette p = m_editPreview->palette();
00319 p.setColor (QPalette::Base, QColor (240, 240, 240));
00320 m_editPreview->setPalette (p);
00321
00322 layout->addWidget (m_editPreview, row++, 0, 1, 3);
00323 }
00324
00325 void DlgSettingsExportFormat::createRelationsPointsSelection (QHBoxLayout *layoutRelations)
00326 {
00327 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createRelationsPointsSelection";
00328
00329 QGroupBox *groupPointsSelection = new QGroupBox (tr ("Relation Points Selection"));
00330 layoutRelations->addWidget (groupPointsSelection);
00331
00332 QGridLayout *layoutPointsSelections = new QGridLayout;
00333 groupPointsSelection->setLayout (layoutPointsSelections);
00334
00335 layoutPointsSelections->setColumnMinimumWidth(0, MIN_INDENT_COLUMN_WIDTH);
00336 layoutPointsSelections->setColumnStretch (0, 0);
00337 layoutPointsSelections->setColumnStretch (1, 0);
00338 layoutPointsSelections->setColumnStretch (2, 0);
00339 layoutPointsSelections->setColumnStretch (3, 1);
00340
00341 int row = 0;
00342
00343 m_btnRelationsPointsEvenlySpaced = new QRadioButton (tr ("Interpolate Xs and Ys at evenly spaced intervals."));
00344 m_btnRelationsPointsEvenlySpaced->setWhatsThis (tr ("Exported file will have points evenly spaced along each relation, separated by the interval "
00345 "selected below. If the last interval does not end at the last point, then a shorter last interval "
00346 "is added that ends on the last point."));
00347 layoutPointsSelections->addWidget (m_btnRelationsPointsEvenlySpaced, row++, 0, 1, 4);
00348 connect (m_btnRelationsPointsEvenlySpaced, SIGNAL (released()), this, SLOT (slotRelationsPointsEvenlySpaced()));
00349
00350 QLabel *labelInterval = new QLabel (tr ("Interval:"));
00351 layoutPointsSelections->addWidget (labelInterval, row, 1, 1, 1, Qt::AlignRight);
00352
00353 m_editRelationsPointsEvenlySpacing = new QLineEdit;
00354 m_validatorRelationsPointsEvenlySpacing = new QDoubleValidator;
00355 m_editRelationsPointsEvenlySpacing->setValidator (m_validatorRelationsPointsEvenlySpacing);
00356 m_editRelationsPointsEvenlySpacing->setMinimumWidth (MIN_EDIT_WIDTH);
00357 m_editRelationsPointsEvenlySpacing->setMaximumWidth (MAX_EDIT_WIDTH);
00358 m_editRelationsPointsEvenlySpacing->setWhatsThis (tr ("Interval between successive points when "
00359 "exporting at evenly spaced (X,Y) coordinates."));
00360 layoutPointsSelections->addWidget (m_editRelationsPointsEvenlySpacing, row, 2, 1, 1, Qt::AlignLeft);
00361 connect (m_editRelationsPointsEvenlySpacing, SIGNAL (textChanged(const QString &)), this, SLOT (slotRelationsPointsEvenlySpacedInterval(const QString &)));
00362
00363 m_cmbRelationsPointsEvenlySpacingUnits = new QComboBox;
00364 m_cmbRelationsPointsEvenlySpacingUnits->setWhatsThis (tr ("Units for spacing interval.\n\n"
00365 "Pixel units are preferred when the spacing is to be independent of the X and Y scales. The spacing will be "
00366 "consistent across the graph, even if a scale is logarithmic or the X and Y scales are different.\n\n"
00367 "Graph units are usually preferred when the X and Y scales are identical."));
00368 m_cmbRelationsPointsEvenlySpacingUnits->addItem(exportPointsIntervalUnitsToString (EXPORT_POINTS_INTERVAL_UNITS_GRAPH),
00369 QVariant (EXPORT_POINTS_INTERVAL_UNITS_GRAPH));
00370 m_cmbRelationsPointsEvenlySpacingUnits->addItem(exportPointsIntervalUnitsToString (EXPORT_POINTS_INTERVAL_UNITS_SCREEN),
00371 QVariant (EXPORT_POINTS_INTERVAL_UNITS_SCREEN));
00372 connect (m_cmbRelationsPointsEvenlySpacingUnits, SIGNAL (activated (const QString &)),
00373 this, SLOT (slotRelationsPointsEvenlySpacedIntervalUnits (const QString &)));
00374 layoutPointsSelections->addWidget (m_cmbRelationsPointsEvenlySpacingUnits, row++, 3, 1, 1, Qt::AlignLeft);
00375
00376 m_btnRelationsPointsRaw = new QRadioButton (tr ("Raw Xs and Ys"));
00377 m_btnRelationsPointsRaw->setWhatsThis (tr ("Exported file will have only original X and Y values"));
00378 layoutPointsSelections->addWidget (m_btnRelationsPointsRaw, row++, 0, 1, 4);
00379 connect (m_btnRelationsPointsRaw, SIGNAL (released()), this, SLOT (slotRelationsPointsRaw()));
00380 }
00381
00382 QWidget *DlgSettingsExportFormat::createSubPanel ()
00383 {
00384 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createSubPanel";
00385
00386 QWidget *subPanel = new QWidget ();
00387 QGridLayout *layout = new QGridLayout (subPanel);
00388 subPanel->setLayout (layout);
00389
00390 int row = 0;
00391 createCurveSelection (layout, row);
00392
00393 createTabWidget (layout,
00394 row);
00395
00396 QWidget *widgetMisc = new QWidget;
00397 layout->addWidget (widgetMisc, row++, 0, 1, 3);
00398 QHBoxLayout *layoutMisc = new QHBoxLayout;
00399 widgetMisc->setLayout (layoutMisc);
00400
00401 createDelimiters (layoutMisc);
00402 createHeader (layoutMisc);
00403 createFileLayout (layoutMisc);
00404
00405 createPreview (layout, row);
00406
00407 return subPanel;
00408 }
00409
00410 void DlgSettingsExportFormat::createTabWidget (QGridLayout *layout,
00411 int &row)
00412 {
00413 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createTabWidget";
00414
00415 m_tabWidget = new QTabWidget;
00416
00417 layout->addWidget (m_tabWidget, row++, 0, 1, 3);
00418
00419 QWidget *widgetFunctions = new QWidget;
00420 int indexFunctions = m_tabWidget->addTab (widgetFunctions, tr ("Functions"));
00421 QWidget *tabFunctions = m_tabWidget->widget (indexFunctions);
00422 tabFunctions->setWhatsThis (tr ("Functions Tab\n\n"
00423 "Controls for specifying the format of functions during export"));
00424 QHBoxLayout *layoutFunctions = new QHBoxLayout;
00425 widgetFunctions->setLayout (layoutFunctions);
00426
00427 QWidget *widgetRelations = new QWidget;
00428 int indexRelations = m_tabWidget->addTab (widgetRelations, tr ("Relations"));
00429 QWidget *tabRelations = m_tabWidget->widget (indexRelations);
00430 tabRelations->setWhatsThis (tr ("Relations Tab\n\n"
00431 "Controls for specifying the format of relations during export"));
00432 QHBoxLayout *layoutRelations = new QHBoxLayout;
00433 widgetRelations->setLayout (layoutRelations);
00434
00435
00436 connect (m_tabWidget, SIGNAL (currentChanged (int)), this, SLOT (slotTabChanged (int)));
00437
00438 createFunctionsPointsSelection (layoutFunctions);
00439 createRelationsPointsSelection (layoutRelations);
00440 }
00441
00442 void DlgSettingsExportFormat::createXLabel (QGridLayout *layoutHeader,
00443 int colLabel)
00444 {
00445 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createXLabel";
00446
00447 int row = 1;
00448
00449 QLabel *title;
00450 if (true) {
00451 title = new QLabel (tr ("X Label:"));
00452 } else {
00453 title = new QLabel (tr ("Theta Label:"));
00454 }
00455 layoutHeader->addWidget (title, row++, colLabel, 1, 1);
00456
00457 m_editXLabel = new QLineEdit;
00458 if (true) {
00459 m_editXLabel->setWhatsThis (tr ("Label in the header for x values"));
00460 } else {
00461 m_editXLabel->setWhatsThis (tr ("Label in the header for theta values"));
00462 }
00463 layoutHeader->addWidget (m_editXLabel, row++, colLabel, 1, 1);
00464 connect (m_editXLabel, SIGNAL (textChanged (const QString &)), this, SLOT (slotXLabel(const QString &)));
00465 }
00466
00467 QString DlgSettingsExportFormat::exportedTextToExportedHtml (const QString &text,
00468 const QString &color) const
00469 {
00470 QRegExp re ("<br>$");
00471
00472 QString textCopy (text);
00473 QString replaced = textCopy
00474 .replace ("\n", "<br>")
00475 .replace (" ", " ")
00476 .replace (re, "")
00477 .replace ("\t", " ");
00478
00479 QString html = QString ("<div style=\"display: inline; background-color: %1\">%2</div>")
00480 .arg (color)
00481 .arg (replaced);
00482
00483 return html;
00484 }
00485
00486 bool DlgSettingsExportFormat::goodIntervalFunctions() const
00487 {
00488
00489
00490 QString textFunctions = m_editFunctionsPointsEvenlySpacing->text();
00491 int posFunctions;
00492
00493 bool isGood = (m_validatorFunctionsPointsEvenlySpacing->validate (textFunctions, posFunctions) == QValidator::Acceptable);
00494
00495 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::goodIntervalFunctions"
00496 << " text=" << textFunctions.toLatin1().data()
00497 << " good=" << (isGood ? "true" : "false")
00498 << " bottom=" << m_validatorFunctionsPointsEvenlySpacing->bottom()
00499 << " top=" << m_validatorFunctionsPointsEvenlySpacing->top();
00500
00501 return isGood;
00502 }
00503
00504 bool DlgSettingsExportFormat::goodIntervalRelations() const
00505 {
00506
00507
00508 QString textRelations = m_editRelationsPointsEvenlySpacing->text();
00509 int posRelations;
00510
00511 bool isGood = (m_validatorRelationsPointsEvenlySpacing->validate (textRelations, posRelations) == QValidator::Acceptable);
00512
00513 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::goodIntervalRelations"
00514 << " text=" << textRelations.toLatin1().data()
00515 << " good=" << (isGood ? "true" : "false")
00516 << " bottom=" << m_validatorRelationsPointsEvenlySpacing->bottom()
00517 << " top=" << m_validatorRelationsPointsEvenlySpacing->top();
00518
00519 return isGood;
00520 }
00521
00522 void DlgSettingsExportFormat::handleOk ()
00523 {
00524 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::handleOk";
00525
00526 CmdSettingsExportFormat *cmd = new CmdSettingsExportFormat (mainWindow (),
00527 cmdMediator ().document(),
00528 *m_modelExportBefore,
00529 *m_modelExportAfter);
00530 cmdMediator ().push (cmd);
00531
00532 hide ();
00533 }
00534
00535 void DlgSettingsExportFormat::initializeIntervalConstraints ()
00536 {
00537 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::initializeIntervalConstraints";
00538
00539 const int MAX_POINTS_ACROSS_RANGE = 5000;
00540
00541
00542 CallbackBoundingRects ftor (mainWindow().transformation());
00543
00544 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
00545 &CallbackBoundingRects::callback);
00546 cmdMediator().iterateThroughCurvesPointsGraphs (ftorWithCallback);
00547
00548
00549 bool isEmpty;
00550 double maxSizeGraph = qMax (ftor.boundingRectGraph(isEmpty).width(),
00551 ftor.boundingRectGraph(isEmpty).height());
00552 double maxSizeScreen = qMax (ftor.boundingRectScreen(isEmpty).width(),
00553 ftor.boundingRectScreen(isEmpty).height());
00554 m_minIntervalGraph = maxSizeGraph / MAX_POINTS_ACROSS_RANGE;
00555 m_minIntervalScreen = maxSizeScreen / MAX_POINTS_ACROSS_RANGE;
00556 }
00557
00558 void DlgSettingsExportFormat::load (CmdMediator &cmdMediator)
00559 {
00560 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::load";
00561
00562 setCmdMediator (cmdMediator);
00563
00564
00565 if (m_modelExportBefore != 0) {
00566 delete m_modelExportBefore;
00567 }
00568 if (m_modelExportAfter != 0) {
00569 delete m_modelExportAfter;
00570 }
00571
00572
00573 m_modelExportBefore = new DocumentModelExportFormat (cmdMediator.document());
00574 m_modelExportAfter = new DocumentModelExportFormat (cmdMediator.document());
00575
00576
00577 m_listExcluded->clear();
00578 QStringList curveNamesExcluded = m_modelExportAfter->curveNamesNotExported();
00579 QStringList::const_iterator itr;
00580 for (itr = curveNamesExcluded.begin (); itr != curveNamesExcluded.end(); ++itr) {
00581 QString curveNameNotExported = *itr;
00582 m_listExcluded->addItem (curveNameNotExported);
00583 }
00584
00585
00586 m_listIncluded->clear();
00587 QStringList curveNamesAll = cmdMediator.document().curvesGraphsNames();
00588 for (itr = curveNamesAll.begin (); itr != curveNamesAll.end(); itr++) {
00589 QString curveName = *itr;
00590 if (!curveNamesExcluded.contains (curveName)) {
00591 m_listIncluded->addItem (curveName);
00592 }
00593 }
00594
00595 ExportPointsSelectionFunctions pointsSelectionFunctions = m_modelExportAfter->pointsSelectionFunctions();
00596 m_btnFunctionsPointsAllCurves->setChecked (pointsSelectionFunctions == EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES);
00597 m_btnFunctionsPointsFirstCurve->setChecked (pointsSelectionFunctions == EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_FIRST_CURVE);
00598 m_btnFunctionsPointsEvenlySpaced->setChecked (pointsSelectionFunctions == EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_PERIODIC);
00599 m_btnFunctionsPointsRaw->setChecked (pointsSelectionFunctions == EXPORT_POINTS_SELECTION_FUNCTIONS_RAW);
00600
00601 ExportLayoutFunctions layoutFunctions = m_modelExportAfter->layoutFunctions ();
00602 m_btnCurvesLayoutAllCurves->setChecked (layoutFunctions == EXPORT_LAYOUT_ALL_PER_LINE);
00603 m_btnCurvesLayoutOneCurve->setChecked (layoutFunctions == EXPORT_LAYOUT_ONE_PER_LINE);
00604
00605 ExportPointsSelectionRelations pointsSelectionRelations = m_modelExportAfter->pointsSelectionRelations();
00606 m_btnRelationsPointsEvenlySpaced->setChecked (pointsSelectionRelations == EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE);
00607 m_btnRelationsPointsRaw->setChecked (pointsSelectionRelations == EXPORT_POINTS_SELECTION_RELATIONS_RAW);
00608
00609 ExportDelimiter delimiter = m_modelExportAfter->delimiter ();
00610 m_btnDelimitersCommas->setChecked (delimiter == EXPORT_DELIMITER_COMMA);
00611 m_btnDelimitersSpaces->setChecked (delimiter == EXPORT_DELIMITER_SPACE);
00612 m_btnDelimitersTabs->setChecked (delimiter == EXPORT_DELIMITER_TAB);
00613 m_btnDelimitersSemicolons->setChecked (delimiter == EXPORT_DELIMITER_SEMICOLON);
00614
00615 m_chkOverrideCsvTsv->setChecked (m_modelExportAfter->overrideCsvTsv());
00616
00617 ExportHeader header = m_modelExportAfter->header ();
00618 m_btnHeaderNone->setChecked (header == EXPORT_HEADER_NONE);
00619 m_btnHeaderSimple->setChecked (header == EXPORT_HEADER_SIMPLE);
00620 m_btnHeaderGnuplot->setChecked (header == EXPORT_HEADER_GNUPLOT);
00621
00622 m_editXLabel->setText (m_modelExportAfter->xLabel());
00623
00624 m_editFunctionsPointsEvenlySpacing->setText (QString::number (m_modelExportAfter->pointsIntervalFunctions()));
00625 m_editRelationsPointsEvenlySpacing->setText (QString::number (m_modelExportAfter->pointsIntervalRelations()));
00626
00627 ExportPointsIntervalUnits pointsIntervalUnitsFunctions = m_modelExportAfter->pointsIntervalUnitsFunctions();
00628 ExportPointsIntervalUnits pointsIntervalUnitsRelations = m_modelExportAfter->pointsIntervalUnitsRelations();
00629 int indexFunctions = m_cmbFunctionsPointsEvenlySpacingUnits->findData (QVariant (pointsIntervalUnitsFunctions));
00630 int indexRelations = m_cmbRelationsPointsEvenlySpacingUnits->findData (QVariant (pointsIntervalUnitsRelations));
00631 m_cmbFunctionsPointsEvenlySpacingUnits->setCurrentIndex (indexFunctions);
00632 m_cmbRelationsPointsEvenlySpacingUnits->setCurrentIndex (indexRelations);
00633
00634 initializeIntervalConstraints ();
00635
00636 updateControlsUponLoad ();
00637 updateControls();
00638 updateIntervalConstraints();
00639 enableOk (false);
00640 updatePreview();
00641 }
00642
00643 void DlgSettingsExportFormat::setSmallDialogs(bool smallDialogs)
00644 {
00645 if (!smallDialogs) {
00646 setMinimumHeight (MINIMUM_HEIGHT);
00647 }
00648 }
00649
00650 void DlgSettingsExportFormat::slotDelimitersCommas()
00651 {
00652 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotDelimitersCommas";
00653
00654 m_modelExportAfter->setDelimiter(EXPORT_DELIMITER_COMMA);
00655 updateControls();
00656 updatePreview();
00657 }
00658
00659 void DlgSettingsExportFormat::slotDelimitersSemicolons()
00660 {
00661 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotDelimitersSemicolons";
00662
00663 m_modelExportAfter->setDelimiter(EXPORT_DELIMITER_SEMICOLON);
00664 updateControls();
00665 updatePreview();
00666 }
00667
00668 void DlgSettingsExportFormat::slotDelimitersSpaces()
00669 {
00670 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotDelimitersSpaces";
00671
00672 m_modelExportAfter->setDelimiter(EXPORT_DELIMITER_SPACE);
00673 updateControls();
00674 updatePreview();
00675 }
00676
00677 void DlgSettingsExportFormat::slotDelimitersTabs()
00678 {
00679 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotDelimitersTabs";
00680
00681 m_modelExportAfter->setDelimiter(EXPORT_DELIMITER_TAB);
00682 updateControls();
00683 updatePreview();
00684 }
00685
00686 void DlgSettingsExportFormat::slotExclude ()
00687 {
00688 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotExclude";
00689
00690
00691 int i;
00692 QStringList excluded;
00693 for (i = 0; i < m_listIncluded->count(); i++) {
00694 if (m_listIncluded->item(i)->isSelected()) {
00695 excluded += m_listIncluded->item(i)->text();
00696 }
00697 }
00698
00699
00700 for (i = 0; i < excluded.count(); i++) {
00701 QString curveName = excluded.at (i);
00702 m_listExcluded->addItem (curveName);
00703 }
00704
00705
00706 for (i = m_listIncluded->count() - 1; i>= 0; i--) {
00707 QString curveName = m_listIncluded->item(i)->text();
00708 if (excluded.contains (curveName)) {
00709 QListWidgetItem *item = m_listIncluded->item (i);
00710 m_listIncluded->removeItemWidget (item);
00711 delete item;
00712 }
00713 }
00714
00715 m_modelExportAfter->setCurveNamesNotExported(excluded);
00716 updateControls();
00717 updatePreview();
00718 }
00719
00720 void DlgSettingsExportFormat::slotFunctionsLayoutAllCurves()
00721 {
00722 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsLayoutAllCurves";
00723
00724 m_modelExportAfter->setLayoutFunctions(EXPORT_LAYOUT_ALL_PER_LINE);
00725 updateControls();
00726 updatePreview();
00727 }
00728
00729 void DlgSettingsExportFormat::slotFunctionsLayoutOneCurve()
00730 {
00731 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsLayoutOneCurve";
00732
00733 m_modelExportAfter->setLayoutFunctions(EXPORT_LAYOUT_ONE_PER_LINE);
00734 updateControls();
00735 updatePreview();
00736 }
00737
00738 void DlgSettingsExportFormat::slotFunctionsPointsAllCurves()
00739 {
00740 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsAllCurves";
00741
00742 m_modelExportAfter->setPointsSelectionFunctions(EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_ALL_CURVES);
00743 updateControls();
00744 updatePreview();
00745 }
00746
00747 void DlgSettingsExportFormat::slotFunctionsPointsEvenlySpaced()
00748 {
00749 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsEvenlySpaced";
00750
00751 m_modelExportAfter->setPointsSelectionFunctions(EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_PERIODIC);
00752 updateControls();
00753 updatePreview();
00754 }
00755
00756 void DlgSettingsExportFormat::slotFunctionsPointsEvenlySpacedInterval(const QString &)
00757 {
00758 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsEvenlySpacedInterval";
00759
00760
00761 if (goodIntervalFunctions()) {
00762 m_modelExportAfter->setPointsIntervalFunctions(m_editFunctionsPointsEvenlySpacing->text().toDouble());
00763 updateControls();
00764 updatePreview();
00765 } else {
00766 m_editPreview->setText(EMPTY_PREVIEW);
00767 }
00768 }
00769
00770 void DlgSettingsExportFormat::slotFunctionsPointsEvenlySpacedIntervalUnits(const QString &)
00771 {
00772 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsEvenlySpacedIntervalUnits";
00773
00774 int index = m_cmbFunctionsPointsEvenlySpacingUnits->currentIndex();
00775 ExportPointsIntervalUnits units = (ExportPointsIntervalUnits) m_cmbFunctionsPointsEvenlySpacingUnits->itemData (index).toInt();
00776
00777 m_modelExportAfter->setPointsIntervalUnitsFunctions(units);
00778 updateIntervalConstraints();
00779 updateControls();
00780 updatePreview();
00781 }
00782
00783 void DlgSettingsExportFormat::slotFunctionsPointsFirstCurve()
00784 {
00785 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsFirstCurve";
00786
00787 m_modelExportAfter->setPointsSelectionFunctions(EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_FIRST_CURVE);
00788 updateControls();
00789 updatePreview();
00790 }
00791
00792 void DlgSettingsExportFormat::slotFunctionsPointsRaw()
00793 {
00794 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotFunctionsPointsRaw";
00795
00796 m_modelExportAfter->setPointsSelectionFunctions(EXPORT_POINTS_SELECTION_FUNCTIONS_RAW);
00797 updateControls();
00798 updatePreview();
00799 }
00800
00801 void DlgSettingsExportFormat::slotHeaderGnuplot()
00802 {
00803 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotHeaderGnuplot";
00804
00805 m_modelExportAfter->setHeader(EXPORT_HEADER_GNUPLOT);
00806 updateControls();
00807 updatePreview();
00808 }
00809
00810 void DlgSettingsExportFormat::slotHeaderNone()
00811 {
00812 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotHeaderNone";
00813
00814 m_modelExportAfter->setHeader(EXPORT_HEADER_NONE);
00815 updateControls();
00816 updatePreview();
00817 }
00818
00819 void DlgSettingsExportFormat::slotHeaderSimple()
00820 {
00821 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotHeaderSimple";
00822
00823 m_modelExportAfter->setHeader(EXPORT_HEADER_SIMPLE);
00824 updateControls();
00825 updatePreview();
00826 }
00827
00828 void DlgSettingsExportFormat::slotInclude ()
00829 {
00830 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotInclude";
00831
00832
00833 int i;
00834 QStringList included;
00835 for (i = 0; i < m_listExcluded->count(); i++) {
00836 if (m_listExcluded->item(i)->isSelected()) {
00837 included += m_listExcluded->item(i)->text();
00838 }
00839 }
00840
00841
00842 for (i = 0; i < included.count(); i++) {
00843 QString curveName = included.at (i);
00844 m_listIncluded->addItem (curveName);
00845 }
00846
00847
00848 QStringList excluded;
00849 for (i = m_listExcluded->count() - 1; i>= 0; i--) {
00850 QString curveName = m_listExcluded->item(i)->text();
00851 QListWidgetItem *item = m_listExcluded->item (i);
00852 if (included.contains (curveName)) {
00853 m_listExcluded->removeItemWidget (item);
00854 delete item;
00855 } else {
00856 excluded += item->text();
00857 }
00858 }
00859
00860 m_modelExportAfter->setCurveNamesNotExported(excluded);
00861 updateControls();
00862 updatePreview();
00863 }
00864
00865 void DlgSettingsExportFormat::slotListExcluded()
00866 {
00867 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotListExcluded";
00868
00869 updateControls();
00870
00871 }
00872
00873 void DlgSettingsExportFormat::slotListIncluded()
00874 {
00875 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotListIncluded";
00876
00877 updateControls();
00878
00879 }
00880
00881 void DlgSettingsExportFormat::slotOverrideCsvTsv(int)
00882 {
00883 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotOverrideCsvTsv";
00884
00885 m_modelExportAfter->setOverrideCsvTsv(m_chkOverrideCsvTsv->isChecked());
00886 updateControls();
00887 updatePreview();
00888 }
00889
00890 void DlgSettingsExportFormat::slotRelationsPointsEvenlySpaced()
00891 {
00892 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotRelationsPointsEvenlySpaced";
00893
00894 m_modelExportAfter->setPointsSelectionRelations(EXPORT_POINTS_SELECTION_RELATIONS_INTERPOLATE);
00895 updateControls();
00896 updatePreview();
00897 }
00898
00899 void DlgSettingsExportFormat::slotRelationsPointsEvenlySpacedInterval(const QString &)
00900 {
00901 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotRelationsPointsEvenlySpacedInterval";
00902
00903 m_modelExportAfter->setPointsIntervalRelations(m_editRelationsPointsEvenlySpacing->text().toDouble());
00904 updateControls();
00905 updatePreview();
00906 }
00907
00908 void DlgSettingsExportFormat::slotRelationsPointsEvenlySpacedIntervalUnits(const QString &)
00909 {
00910 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotRelationsPointsEvenlySpacedIntervalUnits";
00911
00912 int index = m_cmbRelationsPointsEvenlySpacingUnits->currentIndex();
00913 ExportPointsIntervalUnits units = (ExportPointsIntervalUnits) m_cmbRelationsPointsEvenlySpacingUnits->itemData (index).toInt();
00914
00915 m_modelExportAfter->setPointsIntervalUnitsRelations(units);
00916 updateIntervalConstraints();
00917 updateControls();
00918 updatePreview();
00919 }
00920
00921 void DlgSettingsExportFormat::slotRelationsPointsRaw()
00922 {
00923 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotRelationsPointsRaw";
00924
00925 m_modelExportAfter->setPointsSelectionRelations(EXPORT_POINTS_SELECTION_RELATIONS_RAW);
00926 updateControls();
00927 updatePreview();
00928 }
00929
00930 void DlgSettingsExportFormat::slotSaveDefault()
00931 {
00932 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotSaveDefault";
00933
00934 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
00935 settings.beginGroup (SETTINGS_GROUP_EXPORT);
00936
00937 settings.setValue (SETTINGS_EXPORT_DELIMITER,
00938 QVariant (m_modelExportAfter->delimiter()));
00939 settings.setValue (SETTINGS_EXPORT_HEADER,
00940 QVariant (m_modelExportAfter->header()));
00941 settings.setValue (SETTINGS_EXPORT_LAYOUT_FUNCTIONS,
00942 QVariant (m_modelExportAfter->layoutFunctions()));
00943 settings.setValue (SETTINGS_EXPORT_POINTS_INTERVAL_FUNCTIONS,
00944 QVariant (m_modelExportAfter->pointsIntervalFunctions()));
00945 settings.setValue (SETTINGS_EXPORT_POINTS_INTERVAL_RELATIONS,
00946 QVariant (m_modelExportAfter->pointsIntervalRelations()));
00947 settings.setValue (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_FUNCTIONS,
00948 QVariant (m_modelExportAfter->pointsIntervalUnitsFunctions()));
00949 settings.setValue (SETTINGS_EXPORT_POINTS_INTERVAL_UNITS_RELATIONS,
00950 QVariant (m_modelExportAfter->pointsIntervalUnitsRelations()));
00951 settings.setValue (SETTINGS_EXPORT_POINTS_SELECTION_FUNCTIONS,
00952 QVariant (m_modelExportAfter->pointsSelectionFunctions()));
00953 settings.setValue (SETTINGS_EXPORT_POINTS_SELECTION_RELATIONS,
00954 QVariant (m_modelExportAfter->pointsSelectionRelations()));
00955 settings.setValue (SETTINGS_EXPORT_X_LABEL,
00956 QVariant (m_modelExportAfter->xLabel()));
00957
00958 settings.endGroup ();
00959 }
00960
00961 void DlgSettingsExportFormat::slotTabChanged (int)
00962 {
00963 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotTabChanged";
00964
00965 updatePreview();
00966 }
00967
00968 void DlgSettingsExportFormat::slotXLabel(const QString &)
00969 {
00970 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::slotXLabel";
00971
00972 m_modelExportAfter->setXLabel (m_editXLabel->text());
00973 updateControls();
00974 updatePreview();
00975 }
00976
00977 void DlgSettingsExportFormat::updateControls ()
00978 {
00979 bool isGoodState = goodIntervalFunctions() &&
00980 goodIntervalRelations();
00981 enableOk (isGoodState);
00982
00983 int selectedForInclude = m_listExcluded->selectedItems().count();
00984 int selectedForExclude = m_listIncluded->selectedItems().count();
00985 int inInclude = m_listIncluded->count();
00986
00987 m_btnInclude->setEnabled (selectedForInclude > 0);
00988 m_btnExclude->setEnabled ((selectedForExclude > 0) && (inInclude - selectedForExclude > 0));
00989
00990 m_editFunctionsPointsEvenlySpacing->setEnabled (m_haveFunction && m_btnFunctionsPointsEvenlySpaced->isChecked ());
00991 m_editRelationsPointsEvenlySpacing->setEnabled (m_haveRelation && m_btnRelationsPointsEvenlySpaced->isChecked ());
00992
00993 m_editXLabel->setEnabled (!m_btnHeaderNone->isChecked());
00994 }
00995
00996 void DlgSettingsExportFormat::updateControlsUponLoad ()
00997 {
00998 CurveStyles curveStyles = cmdMediator().document().modelCurveStyles();
00999
01000 m_haveFunction = false;
01001 m_haveRelation = false;
01002
01003 QStringList curveNames = curveStyles.curveNames();
01004
01005 QStringList::const_iterator itr;
01006 for (itr = curveNames.begin(); itr != curveNames.end (); itr++) {
01007 QString curveName = *itr;
01008 CurveStyle curveStyle = curveStyles.curveStyle (curveName);
01009 CurveConnectAs curveConnectAs = curveStyle.lineStyle().curveConnectAs();
01010 if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH || curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
01011 m_haveFunction = true;
01012 } else if (curveConnectAs == CONNECT_AS_RELATION_SMOOTH || curveConnectAs == CONNECT_AS_RELATION_STRAIGHT) {
01013 m_haveRelation = true;
01014 }
01015 }
01016
01017
01018 m_btnFunctionsPointsAllCurves->setEnabled (m_haveFunction);
01019 m_btnFunctionsPointsFirstCurve->setEnabled (m_haveFunction);
01020 m_btnFunctionsPointsEvenlySpaced->setEnabled (m_haveFunction);
01021 m_editFunctionsPointsEvenlySpacing->setEnabled (m_haveFunction);
01022 m_cmbFunctionsPointsEvenlySpacingUnits->setEnabled (m_haveFunction);
01023 m_btnFunctionsPointsRaw->setEnabled (m_haveFunction);
01024
01025
01026 m_btnRelationsPointsEvenlySpaced->setEnabled (m_haveRelation);
01027 m_editRelationsPointsEvenlySpacing->setEnabled (m_haveRelation);
01028 m_cmbRelationsPointsEvenlySpacingUnits->setEnabled (m_haveRelation);
01029 m_btnRelationsPointsRaw->setEnabled (m_haveRelation);
01030
01031
01032 if (!m_haveRelation) {
01033 m_tabWidget->setCurrentIndex (TAB_WIDGET_INDEX_FUNCTIONS);
01034 } else if (!m_haveFunction) {
01035 m_tabWidget->setCurrentIndex (TAB_WIDGET_INDEX_RELATIONS);
01036 }
01037 }
01038
01039 void DlgSettingsExportFormat::updateIntervalConstraints ()
01040 {
01041 double functionsMin = (m_modelExportAfter->pointsIntervalUnitsFunctions() == EXPORT_POINTS_INTERVAL_UNITS_GRAPH ?
01042 m_minIntervalGraph :
01043 m_minIntervalScreen);
01044 double relationsMin = (m_modelExportAfter->pointsIntervalUnitsRelations() == EXPORT_POINTS_INTERVAL_UNITS_GRAPH ?
01045 m_minIntervalGraph :
01046 m_minIntervalScreen);
01047
01048 if (m_tabWidget->currentIndex() == TAB_WIDGET_INDEX_FUNCTIONS) {
01049
01050 if (m_modelExportAfter->pointsIntervalFunctions() < functionsMin) {
01051
01052 m_editFunctionsPointsEvenlySpacing->setText (QString::number (functionsMin));
01053
01054 }
01055
01056 m_validatorFunctionsPointsEvenlySpacing->setBottom (functionsMin);
01057
01058 } else {
01059
01060 if (m_modelExportAfter->pointsIntervalRelations() < relationsMin) {
01061
01062 m_editRelationsPointsEvenlySpacing->setText (QString::number (relationsMin));
01063
01064 }
01065
01066 m_validatorRelationsPointsEvenlySpacing->setBottom (relationsMin);
01067 }
01068 }
01069
01070 void DlgSettingsExportFormat::updatePreview()
01071 {
01072
01073 int scrollPosition = m_editPreview->verticalScrollBar()->value();
01074
01075 QString exportedTextFunctions, exportedTextRelations, exportedHtml;
01076 QTextStream strFunctions (&exportedTextFunctions);
01077 QTextStream strRelations (&exportedTextRelations);
01078
01079 if (mainWindow().transformation().transformIsDefined()) {
01080
01081 unsigned int numWritesSoFar = 0;
01082
01083 ExportFileFunctions exportStrategyFunctions;
01084 exportStrategyFunctions.exportToFile (*m_modelExportAfter,
01085 cmdMediator().document(),
01086 mainWindow().modelMainWindow(),
01087 mainWindow().transformation(),
01088 strFunctions,
01089 numWritesSoFar);
01090
01091 ExportFileRelations exportStrategyRelations;
01092 exportStrategyRelations.exportToFile (*m_modelExportAfter,
01093 cmdMediator().document(),
01094 mainWindow().modelMainWindow(),
01095 mainWindow().transformation(),
01096 strRelations,
01097 numWritesSoFar);
01098
01099
01100
01101
01102
01103 QString exportedHtmlFunctions, exportedHtmlRelations;
01104 if (! exportedTextFunctions.isEmpty ()) {
01105
01106 exportedHtmlFunctions = exportedTextToExportedHtml (exportedTextFunctions, COLOR_FUNCTIONS);
01107 }
01108 if (! exportedTextRelations.isEmpty ()) {
01109
01110 exportedHtmlRelations = exportedTextToExportedHtml (exportedTextRelations, COLOR_RELATIONS);
01111 }
01112
01113 exportedHtml = exportedHtmlFunctions + exportedHtmlRelations;
01114
01115 } else {
01116
01117 exportedHtml = tr ("Preview is unavailable until axis points are defined.");
01118 }
01119
01120 m_editPreview->setHtml (exportedHtml);
01121
01122
01123 m_editPreview->verticalScrollBar()->setValue (scrollPosition);
01124 }