Engauge Digitizer  2
ChecklistGuidePageCurves.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 "ChecklistGuidePageCurves.h"
8 #include "ChecklistLineEdit.h"
9 #include "Curve.h"
10 #include "Logger.h"
11 #include <QHeaderView>
12 #include <QRadioButton>
13 #include <QTableWidget>
14 #include "SettingsForGraph.h"
15 
17  ChecklistGuidePage (title)
18 {
19  LOG4CPP_INFO_S ((*mainCat)) << "ChecklistGuidePageCurves::ChecklistGuidePageCurves";
20 
21  const QString WHATS_THIS_CURVE (tr ("Curve name. Empty if unused."));
22  const QString WHATS_THIS_LINES (tr ("Draw lines between points in each curve."));
23  const QString WHATS_THIS_POINTS (tr ("Draw points in each curve, without lines between the points."));
24 
25  addHtml (tr ("<p>What are the names of the curves that are to be digitized? At least one entry is required.</p>"));
26 
27  m_edit = new ChecklistLineEdit* [NUM_CURVE_NAMES()];
28 
29  for (int i = 0; i < NUM_CURVE_NAMES(); i++) {
30  m_edit [i] = new ChecklistLineEdit;
31  connect (m_edit [i], SIGNAL (signalKeyRelease()), this, SLOT (slotTableChanged()));
32  addLineEdit (m_edit [i],
33  WHATS_THIS_CURVE);
34  }
35 
36  SettingsForGraph settingsForGraph;
37  QString curveName = settingsForGraph.defaultCurveName (1,
38  DEFAULT_GRAPH_CURVE_NAME);
39 
40  m_edit [0]->setText (curveName);
41 
42  addHtml ("<p>&nbsp;</p>");
43 
44  addHtml (tr ("<p>How are those curves drawn?</p>"));
45 
46  m_btnLines = addLabelAndRadioButton (tr ("With lines (with or without points)"),
47  WHATS_THIS_LINES);
48  m_btnPoints = addLabelAndRadioButton (tr ("With points only (no lines between points)"),
49  WHATS_THIS_POINTS);
50 
51  m_btnLines->setChecked (true); // Default encourages digitizing using the lines, since that is easier
52 }
53 
55 {
56  QStringList curveNames;
57 
58  for (int i = 0; i < NUM_CURVE_NAMES(); i++) {
59  const QLineEdit *edit = m_edit [i];
60  QString text = edit->text();
61  if (!text.isEmpty()) {
62  curveNames << text;
63  }
64  }
65 
66  return curveNames;
67 }
68 
69 bool ChecklistGuidePageCurves::curveNamesAreAllUnique() const
70 {
71  LOG4CPP_INFO_S ((*mainCat)) << "ChecklistGuidePageCurves::curveNamesAreAllUnique";
72 
73  QStringList names = curveNames();
74 
75  int numberDuplicatesRemoved = names.removeDuplicates();
76 
77  return (numberDuplicatesRemoved == 0);
78 }
79 
81 {
82  LOG4CPP_INFO_S ((*mainCat)) << "ChecklistGuidePageCurves::isComplete";
83 
84  return !curveNames().isEmpty () &&
85  curveNamesAreAllUnique ();
86 }
87 
89 {
90  LOG4CPP_INFO_S ((*mainCat)) << "ChecklistGuidePageCurves::slotTableChanged";
91 
92  emit completeChanged();
93 }
94 
96 {
97  return m_btnLines->isChecked();
98 }
Manage storage and retrieval of the settings for the curves.
ChecklistGuidePageCurves(const QString &title)
Single constructor.
QStringList curveNames() const
Wizard selection for curve names.
This class customizes QWizardPage for ChecklistGuideWizard.
void addLineEdit(ChecklistLineEdit *edit, const QString &whatsThis)
Insert line edit.
virtual bool isComplete() const
Validate the contents of this page.
QRadioButton * addLabelAndRadioButton(const QString &label, const QString &whatsThis)
Insert radio button and corresponding label.
void addHtml(const QString &html)
Insert html for display.
Adds key event handling to QLineEdit.
QString defaultCurveName(int indexOneBased, const QString &defaultName) const
Default graph name for the specified curve index.
bool withLines() const
Drawn with lines, else points.
void slotTableChanged()
Update after curve table update.