Engauge Digitizer 2
Loading...
Searching...
No Matches
SettingsForGraph.cpp
Go to the documentation of this file.
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
15
16QString 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
32QString 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}
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
const QString SETTINGS_ENGAUGE
const QString SETTINGS_GROUP_CURVE_GRAPH
const QString SETTINGS_GROUP_CURVE_GRAPH_PLACEHOLDER
const QString SETTINGS_DIGITIZER
const QString SETTINGS_CURVE_NAME
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.
int numberOfCurvesForImport() const
Return the number of curve names to be generated. Value is maximum of 1 and the number in the configu...
SettingsForGraph()
Single constructor.