Skip to content

Commit

Permalink
[TD]protect against bad pref value
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
WandererFan committed Mar 23, 2024
1 parent 300bff8 commit 6337b45
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/Mod/TechDraw/App/LineGenerator.cpp
Expand Up @@ -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));
}

Expand Down
14 changes: 13 additions & 1 deletion src/Mod/TechDraw/App/Preferences.cpp
Expand Up @@ -23,7 +23,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <string>

# include <QApplication>
# include <QString>
#endif

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 6337b45

Please sign in to comment.