[TD]protect against bad pref value
- this is a temporary measure to prevent problems caused by a bad value for LineStandard parameter. A previous devel version stored on invalid value. This patch can be removed before moving to production. - this condition can be corrected by editing LineStandard to 0, 1 or 2. a plethora of warning messages is issued until the parameter is corrected.
This commit is contained in:
@@ -362,6 +362,17 @@ std::string LineGenerator::getLineStandardsBody()
|
||||
{
|
||||
int activeStandard = Preferences::lineStandard();
|
||||
std::vector<std::string> choices = getAvailableLineStandards();
|
||||
if (activeStandard < 0 ||
|
||||
(size_t) activeStandard >= choices.size()) {
|
||||
// there is a condition where the LineStandard parameter exists, but is -1 (the
|
||||
// qt value for no current index in a combobox). This is likely caused by an old
|
||||
// development version writing an unvalidated value. In this case, the existing but
|
||||
// invalid value will be returned. This is a temporary fix and can be removed for
|
||||
// production.
|
||||
// Preferences::lineStandard() will print a message about this every time it is called
|
||||
// (lots of messages!).
|
||||
activeStandard = 0;
|
||||
}
|
||||
return getBodyFromString(choices.at(activeStandard));
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <string>
|
||||
|
||||
# include <QApplication>
|
||||
# include <QString>
|
||||
#endif
|
||||
|
||||
@@ -422,6 +422,18 @@ bool Preferences::SectionUsePreviousCut()
|
||||
//! an index into the list of available line standards/version found in LineGroupDirectory
|
||||
int Preferences::lineStandard()
|
||||
{
|
||||
// there is a condition where the LineStandard parameter exists, but is -1 (the
|
||||
// qt value for no current index in a combobox). This is likely caused by an old
|
||||
// development version writing an unvalidated value. In this case, the
|
||||
// existing but invalid value will be returned. This is a temporary fix and
|
||||
// can be removed for production.
|
||||
// this message will appear many times if the parameter is invalid.
|
||||
int parameterValue = getPreferenceGroup("Standards")->GetInt("LineStandard", 1);
|
||||
if (parameterValue < 0) {
|
||||
Base::Console().Warning(qPrintable(QApplication::translate(
|
||||
"Preferences", "The LineStandard parameter is invalid. Using zero instead.", nullptr)));
|
||||
return 0;
|
||||
}
|
||||
return getPreferenceGroup("Standards")->GetInt("LineStandard", 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user