Engauge Digitizer  2
SettingsForGraph.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 "EngaugeAssert.h"
8 #include <QSettings>
9 #include "Settings.h"
10 #include "SettingsForGraph.h"
11 
13 {
14 }
15 
16 QString SettingsForGraph::defaultCurveName (int indexOneBased,
17  const QString &defaultName) const
18 {
19  QString groupName = groupNameForNthCurve (indexOneBased);
20 
21  QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
22  settings.beginGroup (groupName);
23 
24  QString curveName = settings.value (SETTINGS_CURVE_NAME,
25  defaultName).toString();
26 
27  settings.endGroup ();
28 
29  return curveName;
30 }
31 
32 QString SettingsForGraph::groupNameForNthCurve (int indexOneBased) const
33 {
34  ENGAUGE_ASSERT (indexOneBased != 0); // Make sure index is one-based versus zero-based
35 
36  QString groupNameWithPlaceholder = SETTINGS_GROUP_CURVE_GRAPH;
37  QString groupName = groupNameWithPlaceholder.replace (SETTINGS_GROUP_CURVE_GRAPH_PLACEHOLDER,
38  QString::number (indexOneBased));
39 
40  return groupName;
41 }
42 
44 {
45  const QString EMPTY_CURVE_NAME;
46 
47  // Loop until the configuration file returns an empty string
48  int indexOneBased = 1;
49  while (defaultCurveName (indexOneBased + 1, EMPTY_CURVE_NAME) != EMPTY_CURVE_NAME) {
50  ++indexOneBased;
51  }
52 
53  return indexOneBased;
54 }
SettingsForGraph()
Single constructor.
int numberOfCurvesForImport() const
Return the number of curve names to be generated. Value is maximum of 1 and the number in the configu...
QString groupNameForNthCurve(int indexOneBased) const
Return the group name, that appears in the settings file/registry, for the specified curve index...
QString defaultCurveName(int indexOneBased, const QString &defaultName) const
Default graph name for the specified curve index.