Modernize profile functions.

• Replace legacy union/char* profile storage with std::variant<int,uint,float,QString,QStringList,QByteArray> and QString for section/key; remove LC_PROFILE_ENTRY_TYPE/mType.
• Update getters/setters to use std::get_if defaults; add lcProfileInit() and fix a "Settgins" typo.
• Convert color profile accessors to unsigned (lcGet/SetProfileUInt) where appropriate.
• Add LC_PROFILE_PARTS_LIST_COLOR_LOCKED and migrate PartsList color logic (preserves legacy -1 behavior).
This commit is contained in:
Leonardo Zide
2026-08-30 17:22:28 -07:00
parent 720003b555
commit 56eeee9266
11 changed files with 116 additions and 106 deletions
+2
View File
@@ -0,0 +1,2 @@
# Coding conventions
- Use PascalCase for local variables, prefix class member variables with m and globals with g
+45 -43
View File
@@ -27,39 +27,39 @@ void lcPreferences::LoadDefaults()
mMouseSensitivity = lcGetProfileInt(LC_PROFILE_MOUSE_SENSITIVITY);
mShadingMode = static_cast<lcShadingMode>(lcGetProfileInt(LC_PROFILE_SHADING_MODE));
mBackgroundGradient = lcGetProfileInt(LC_PROFILE_BACKGROUND_GRADIENT);
mBackgroundSolidColor = lcGetProfileInt(LC_PROFILE_BACKGROUND_COLOR);
mBackgroundGradientColorTop = lcGetProfileInt(LC_PROFILE_GRADIENT_COLOR_TOP);
mBackgroundGradientColorBottom = lcGetProfileInt(LC_PROFILE_GRADIENT_COLOR_BOTTOM);
mBackgroundSolidColor = lcGetProfileUInt(LC_PROFILE_BACKGROUND_COLOR);
mBackgroundGradientColorTop = lcGetProfileUInt(LC_PROFILE_GRADIENT_COLOR_TOP);
mBackgroundGradientColorBottom = lcGetProfileUInt(LC_PROFILE_GRADIENT_COLOR_BOTTOM);
mDrawAxes = lcGetProfileInt(LC_PROFILE_DRAW_AXES);
mAxisIconLocation = static_cast<lcAxisIconLocation>(lcGetProfileInt(LC_PROFILE_DRAW_AXES_LOCATION));
mAxesColor = lcGetProfileInt(LC_PROFILE_AXES_COLOR);
mTextColor = lcGetProfileInt(LC_PROFILE_TEXT_COLOR);
mMarqueeBorderColor = lcGetProfileInt(LC_PROFILE_MARQUEE_BORDER_COLOR);
mMarqueeFillColor = lcGetProfileInt(LC_PROFILE_MARQUEE_FILL_COLOR);
mOverlayColor = lcGetProfileInt(LC_PROFILE_OVERLAY_COLOR);
mActiveViewColor = lcGetProfileInt(LC_PROFILE_ACTIVE_VIEW_COLOR);
mInactiveViewColor = lcGetProfileInt(LC_PROFILE_INACTIVE_VIEW_COLOR);
mAxesColor = lcGetProfileUInt(LC_PROFILE_AXES_COLOR);
mTextColor = lcGetProfileUInt(LC_PROFILE_TEXT_COLOR);
mMarqueeBorderColor = lcGetProfileUInt(LC_PROFILE_MARQUEE_BORDER_COLOR);
mMarqueeFillColor = lcGetProfileUInt(LC_PROFILE_MARQUEE_FILL_COLOR);
mOverlayColor = lcGetProfileUInt(LC_PROFILE_OVERLAY_COLOR);
mActiveViewColor = lcGetProfileUInt(LC_PROFILE_ACTIVE_VIEW_COLOR);
mInactiveViewColor = lcGetProfileUInt(LC_PROFILE_INACTIVE_VIEW_COLOR);
mDrawEdgeLines = lcGetProfileInt(LC_PROFILE_DRAW_EDGE_LINES);
mDrawConditionalLines = lcGetProfileInt(LC_PROFILE_DRAW_CONDITIONAL_LINES);
mLineWidth = lcGetProfileFloat(LC_PROFILE_LINE_WIDTH);
mAllowLOD = lcGetProfileInt(LC_PROFILE_ALLOW_LOD);
mMeshLODDistance = lcGetProfileFloat(LC_PROFILE_LOD_DISTANCE);
mFadeSteps = lcGetProfileInt(LC_PROFILE_FADE_STEPS);
mFadeStepsColor = lcGetProfileInt(LC_PROFILE_FADE_STEPS_COLOR);
mFadeStepsColor = lcGetProfileUInt(LC_PROFILE_FADE_STEPS_COLOR);
mHighlightNewParts = lcGetProfileInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS);
mHighlightNewPartsColor = lcGetProfileInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS_COLOR);
mHighlightNewPartsColor = lcGetProfileUInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS_COLOR);
mDrawGridStuds = lcGetProfileInt(LC_PROFILE_GRID_STUDS);
mGridStudColor = lcGetProfileInt(LC_PROFILE_GRID_STUD_COLOR);
mGridStudColor = lcGetProfileUInt(LC_PROFILE_GRID_STUD_COLOR);
mDrawGridLines = lcGetProfileInt(LC_PROFILE_GRID_LINES);
mGridLineSpacing = lcGetProfileInt(LC_PROFILE_GRID_LINE_SPACING);
mGridLineColor = lcGetProfileInt(LC_PROFILE_GRID_LINE_COLOR);
mGridLineColor = lcGetProfileUInt(LC_PROFILE_GRID_LINE_COLOR);
mDrawGridOrigin = lcGetProfileInt(LC_PROFILE_GRID_ORIGIN);
mViewSphereEnabled = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_ENABLED);
mViewSphereLocation = static_cast<lcViewSphereLocation>(lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_LOCATION));
mViewSphereSize = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_SIZE);
mViewSphereColor = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_COLOR);
mViewSphereTextColor = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_TEXT_COLOR);
mViewSphereHighlightColor = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_HIGHLIGHT_COLOR);
mViewSphereColor = lcGetProfileUInt(LC_PROFILE_VIEW_SPHERE_COLOR);
mViewSphereTextColor = lcGetProfileUInt(LC_PROFILE_VIEW_SPHERE_TEXT_COLOR);
mViewSphereHighlightColor = lcGetProfileUInt(LC_PROFILE_VIEW_SPHERE_HIGHLIGHT_COLOR);
mAutoLoadMostRecent = lcGetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT);
mRestoreTabLayout = lcGetProfileInt(LC_PROFILE_RESTORE_TAB_LAYOUT);
mColorTheme = static_cast<lcColorTheme>(lcGetProfileInt(LC_PROFILE_COLOR_THEME));
@@ -68,13 +68,13 @@ void lcPreferences::LoadDefaults()
mPreviewViewSphereLocation = static_cast<lcViewSphereLocation>(lcGetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION));
mDrawPreviewAxis = lcGetProfileInt(LC_PROFILE_PREVIEW_DRAW_AXES);
mStudCylinderColorEnabled = lcGetProfileInt(LC_PROFILE_STUD_CYLINDER_COLOR_ENABLED);
mStudCylinderColor = lcGetProfileInt(LC_PROFILE_STUD_CYLINDER_COLOR);
mStudCylinderColor = lcGetProfileUInt(LC_PROFILE_STUD_CYLINDER_COLOR);
mPartEdgeColorEnabled = lcGetProfileInt(LC_PROFILE_PART_EDGE_COLOR_ENABLED);
mPartEdgeColor = lcGetProfileInt(LC_PROFILE_PART_EDGE_COLOR);
mPartEdgeColor = lcGetProfileUInt(LC_PROFILE_PART_EDGE_COLOR);
mBlackEdgeColorEnabled = lcGetProfileInt(LC_PROFILE_BLACK_EDGE_COLOR_ENABLED);
mBlackEdgeColor = lcGetProfileInt(LC_PROFILE_BLACK_EDGE_COLOR);
mBlackEdgeColor = lcGetProfileUInt(LC_PROFILE_BLACK_EDGE_COLOR);
mDarkEdgeColorEnabled = lcGetProfileInt(LC_PROFILE_DARK_EDGE_COLOR_ENABLED);
mDarkEdgeColor = lcGetProfileInt(LC_PROFILE_DARK_EDGE_COLOR);
mDarkEdgeColor = lcGetProfileUInt(LC_PROFILE_DARK_EDGE_COLOR);
mPartEdgeContrast = lcGetProfileFloat(LC_PROFILE_PART_EDGE_CONTRAST);
mPartColorValueLDIndex = lcGetProfileFloat(LC_PROFILE_PART_COLOR_VALUE_LD_INDEX);
mAutomateEdgeColor = lcGetProfileInt(LC_PROFILE_AUTOMATE_EDGE_COLOR);
@@ -93,38 +93,38 @@ void lcPreferences::SaveDefaults()
lcSetProfileInt(LC_PROFILE_SHADING_MODE, static_cast<int>(mShadingMode));
lcSetProfileInt(LC_PROFILE_DRAW_AXES, mDrawAxes);
lcSetProfileInt(LC_PROFILE_DRAW_AXES_LOCATION, static_cast<int>(mAxisIconLocation));
lcSetProfileInt(LC_PROFILE_AXES_COLOR, mAxesColor);
lcSetProfileInt(LC_PROFILE_TEXT_COLOR, mTextColor);
lcSetProfileUInt(LC_PROFILE_AXES_COLOR, mAxesColor);
lcSetProfileUInt(LC_PROFILE_TEXT_COLOR, mTextColor);
lcSetProfileInt(LC_PROFILE_BACKGROUND_GRADIENT, mBackgroundGradient);
lcSetProfileInt(LC_PROFILE_BACKGROUND_COLOR, mBackgroundSolidColor);
lcSetProfileInt(LC_PROFILE_GRADIENT_COLOR_TOP, mBackgroundGradientColorTop);
lcSetProfileInt(LC_PROFILE_GRADIENT_COLOR_BOTTOM, mBackgroundGradientColorBottom);
lcSetProfileInt(LC_PROFILE_MARQUEE_BORDER_COLOR, mMarqueeBorderColor);
lcSetProfileInt(LC_PROFILE_MARQUEE_FILL_COLOR, mMarqueeFillColor);
lcSetProfileInt(LC_PROFILE_OVERLAY_COLOR, mOverlayColor);
lcSetProfileInt(LC_PROFILE_ACTIVE_VIEW_COLOR, mActiveViewColor);
lcSetProfileInt(LC_PROFILE_INACTIVE_VIEW_COLOR, mInactiveViewColor);
lcSetProfileUInt(LC_PROFILE_BACKGROUND_COLOR, mBackgroundSolidColor);
lcSetProfileUInt(LC_PROFILE_GRADIENT_COLOR_TOP, mBackgroundGradientColorTop);
lcSetProfileUInt(LC_PROFILE_GRADIENT_COLOR_BOTTOM, mBackgroundGradientColorBottom);
lcSetProfileUInt(LC_PROFILE_MARQUEE_BORDER_COLOR, mMarqueeBorderColor);
lcSetProfileUInt(LC_PROFILE_MARQUEE_FILL_COLOR, mMarqueeFillColor);
lcSetProfileUInt(LC_PROFILE_OVERLAY_COLOR, mOverlayColor);
lcSetProfileUInt(LC_PROFILE_ACTIVE_VIEW_COLOR, mActiveViewColor);
lcSetProfileUInt(LC_PROFILE_INACTIVE_VIEW_COLOR, mInactiveViewColor);
lcSetProfileInt(LC_PROFILE_DRAW_EDGE_LINES, mDrawEdgeLines);
lcSetProfileInt(LC_PROFILE_DRAW_CONDITIONAL_LINES, mDrawConditionalLines);
lcSetProfileFloat(LC_PROFILE_LINE_WIDTH, mLineWidth);
lcSetProfileInt(LC_PROFILE_ALLOW_LOD, mAllowLOD);
lcSetProfileFloat(LC_PROFILE_LOD_DISTANCE, mMeshLODDistance);
lcSetProfileInt(LC_PROFILE_FADE_STEPS, mFadeSteps);
lcSetProfileInt(LC_PROFILE_FADE_STEPS_COLOR, mFadeStepsColor);
lcSetProfileUInt(LC_PROFILE_FADE_STEPS_COLOR, mFadeStepsColor);
lcSetProfileInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS, mHighlightNewParts);
lcSetProfileInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS_COLOR, mHighlightNewPartsColor);
lcSetProfileUInt(LC_PROFILE_HIGHLIGHT_NEW_PARTS_COLOR, mHighlightNewPartsColor);
lcSetProfileInt(LC_PROFILE_GRID_STUDS, mDrawGridStuds);
lcSetProfileInt(LC_PROFILE_GRID_STUD_COLOR, mGridStudColor);
lcSetProfileUInt(LC_PROFILE_GRID_STUD_COLOR, mGridStudColor);
lcSetProfileInt(LC_PROFILE_GRID_LINES, mDrawGridLines);
lcSetProfileInt(LC_PROFILE_GRID_LINE_SPACING, mGridLineSpacing);
lcSetProfileInt(LC_PROFILE_GRID_LINE_COLOR, mGridLineColor);
lcSetProfileUInt(LC_PROFILE_GRID_LINE_COLOR, mGridLineColor);
lcSetProfileInt(LC_PROFILE_GRID_ORIGIN, mDrawGridOrigin);
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_ENABLED, mViewSphereSize ? 1 : 0);
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_LOCATION, static_cast<int>(mViewSphereLocation));
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_SIZE, mViewSphereSize);
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_COLOR, mViewSphereColor);
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_TEXT_COLOR, mViewSphereTextColor);
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_HIGHLIGHT_COLOR, mViewSphereHighlightColor);
lcSetProfileUInt(LC_PROFILE_VIEW_SPHERE_COLOR, mViewSphereColor);
lcSetProfileUInt(LC_PROFILE_VIEW_SPHERE_TEXT_COLOR, mViewSphereTextColor);
lcSetProfileUInt(LC_PROFILE_VIEW_SPHERE_HIGHLIGHT_COLOR, mViewSphereHighlightColor);
lcSetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT, mAutoLoadMostRecent);
lcSetProfileInt(LC_PROFILE_RESTORE_TAB_LAYOUT, mRestoreTabLayout);
lcSetProfileInt(LC_PROFILE_COLOR_THEME, static_cast<int>(mColorTheme));
@@ -132,13 +132,13 @@ void lcPreferences::SaveDefaults()
lcSetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION, static_cast<int>(mPreviewViewSphereLocation));
lcSetProfileInt(LC_PROFILE_PREVIEW_DRAW_AXES, mDrawPreviewAxis);
lcSetProfileInt(LC_PROFILE_STUD_CYLINDER_COLOR_ENABLED, mStudCylinderColorEnabled);
lcSetProfileInt(LC_PROFILE_STUD_CYLINDER_COLOR, mStudCylinderColor);
lcSetProfileUInt(LC_PROFILE_STUD_CYLINDER_COLOR, mStudCylinderColor);
lcSetProfileInt(LC_PROFILE_PART_EDGE_COLOR_ENABLED, mPartEdgeColorEnabled);
lcSetProfileInt(LC_PROFILE_PART_EDGE_COLOR, mPartEdgeColor);
lcSetProfileUInt(LC_PROFILE_PART_EDGE_COLOR, mPartEdgeColor);
lcSetProfileInt(LC_PROFILE_BLACK_EDGE_COLOR_ENABLED, mBlackEdgeColorEnabled);
lcSetProfileInt(LC_PROFILE_BLACK_EDGE_COLOR, mBlackEdgeColor);
lcSetProfileUInt(LC_PROFILE_BLACK_EDGE_COLOR, mBlackEdgeColor);
lcSetProfileInt(LC_PROFILE_DARK_EDGE_COLOR_ENABLED, mDarkEdgeColorEnabled);
lcSetProfileInt(LC_PROFILE_DARK_EDGE_COLOR, mDarkEdgeColor);
lcSetProfileUInt(LC_PROFILE_DARK_EDGE_COLOR, mDarkEdgeColor);
lcSetProfileFloat(LC_PROFILE_PART_EDGE_CONTRAST, mPartEdgeContrast);
lcSetProfileFloat(LC_PROFILE_PART_COLOR_VALUE_LD_INDEX, mPartColorValueLDIndex);
lcSetProfileInt(LC_PROFILE_AUTOMATE_EDGE_COLOR, mAutomateEdgeColor);
@@ -159,7 +159,7 @@ void lcPreferences::SetInterfaceColors(lcColorTheme ColorTheme)
mBackgroundSolidColor = LC_RGB(49, 52, 55);
mBackgroundGradientColorTop = LC_RGB(0, 0, 191);
mBackgroundGradientColorBottom = LC_RGB(255, 255, 255);
mOverlayColor = lcGetProfileInt(LC_PROFILE_OVERLAY_COLOR);
mOverlayColor = lcGetProfileUInt(LC_PROFILE_OVERLAY_COLOR);
mActiveViewColor = LC_RGBA(41, 128, 185, 255);
mGridStudColor = LC_RGBA(24, 24, 24, 192);
mGridLineColor = LC_RGBA(24, 24, 24, 255);
@@ -191,6 +191,8 @@ lcApplication::lcApplication(int& Argc, char** Argv)
gApplication = this;
mDefaultStyle = style()->objectName();
lcProfileInit();
mPreferences.LoadDefaults();
}
+1
View File
@@ -22,6 +22,7 @@
#include <memory>
#include <optional>
#include <unordered_map>
#include <variant>
#if _MSC_VER
#pragma warning(default : 4062) // enumerator 'identifier' in switch of enum 'enumeration' is not handled
+9 -3
View File
@@ -2555,6 +2555,7 @@ void lcMainWindow::ImportInventory()
else
delete NewProject;
}
bool lcMainWindow::SaveProject(const QString& FileName)
{
QString SaveFileName = FileName;
@@ -2579,12 +2580,17 @@ bool lcMainWindow::SaveProject(const QString& FileName)
if (QFileInfo(SaveFileName).suffix().toLower() == QLatin1String("lcd"))
{
QMessageBox::warning(this, tr("Error"), tr("Saving files in LCD format is no longer supported, please use the LDR or MPD formats instead."));
QMessageBox::warning(this, tr("Save Project"), tr("Saving files in LCD format is no longer supported, please use the LDR or MPD formats instead."));
return false;
}
if (!Project->Save(SaveFileName))
lcResult<void> SaveResult = Project->Save(SaveFileName);
if (!SaveResult)
{
QMessageBox::warning(this, tr("Save Project"), SaveResult.error());
return false;
}
AddRecentFile(SaveFileName);
UpdateTitle();
+2 -2
View File
@@ -29,12 +29,12 @@
void lcModelProperties::LoadDefaults()
{
mAuthor = lcGetProfileString(LC_PROFILE_DEFAULT_AUTHOR_NAME);
mAmbientColor = lcVector3FromColor(lcGetProfileInt(LC_PROFILE_DEFAULT_AMBIENT_COLOR));
mAmbientColor = lcVector3FromColor(lcGetProfileUInt(LC_PROFILE_DEFAULT_AMBIENT_COLOR));
}
void lcModelProperties::SaveDefaults()
{
lcSetProfileInt(LC_PROFILE_DEFAULT_AMBIENT_COLOR, lcColorFromVector3(mAmbientColor));
lcSetProfileUInt(LC_PROFILE_DEFAULT_AMBIENT_COLOR, lcColorFromVector3(mAmbientColor));
}
void lcModelProperties::SaveLDraw(QTextStream& Stream) const
+18 -5
View File
@@ -52,16 +52,20 @@ lcPartSelectionListModel::lcPartSelectionListModel(QObject* Parent)
mPartDescriptionFilter = lcGetProfileInt(LC_PROFILE_PARTS_LIST_PART_DESCRIPTION_FILTER);
mPartFilterType = static_cast<lcPartFilterType>(lcGetProfileInt(LC_PROFILE_PARTS_LIST_PART_FILTER));
int ColorCode = lcGetProfileInt(LC_PROFILE_PARTS_LIST_COLOR);
if (ColorCode == -1)
int ColorCodeInt = lcGetProfileInt(LC_PROFILE_PARTS_LIST_COLOR);
int LockedFlag = lcGetProfileInt(LC_PROFILE_PARTS_LIST_COLOR_LOCKED);
if (ColorCodeInt == -1 && LockedFlag == 0)
{
mColorIndex = gMainWindow->mColorIndex;
mColorLocked = false;
}
else
{
mColorIndex = lcGetColorIndex(ColorCode);
mColorLocked = true;
uint ColorCodeValue = (ColorCodeInt == -1) ? lcGetColorCode(gMainWindow->mColorIndex) : static_cast<uint>(ColorCodeInt);
mColorIndex = lcGetColorIndex(ColorCodeValue);
mColorLocked = (LockedFlag != 0) || (ColorCodeInt != -1);
}
connect(lcGetPiecesLibrary()->GetThumbnailManager(), &lcThumbnailManager::ThumbnailReady, this, &lcPartSelectionListModel::ThumbnailReady);
@@ -98,7 +102,16 @@ void lcPartSelectionListModel::ToggleColorLocked()
mColorLocked = !mColorLocked;
SetColorIndex(gMainWindow->mColorIndex);
lcSetProfileInt(LC_PROFILE_PARTS_LIST_COLOR, mColorLocked ? lcGetColorCode(mColorIndex) : -1);
if (mColorLocked)
{
lcSetProfileUInt(LC_PROFILE_PARTS_LIST_COLOR, lcGetColorCode(mColorIndex));
lcSetProfileInt(LC_PROFILE_PARTS_LIST_COLOR_LOCKED, 1);
}
else
{
lcSetProfileInt(LC_PROFILE_PARTS_LIST_COLOR_LOCKED, 0);
lcSetProfileUInt(LC_PROFILE_PARTS_LIST_COLOR, 0);
}
}
void lcPartSelectionListModel::ToggleListMode()
+29 -24
View File
@@ -9,50 +9,44 @@
lcProfileEntry::lcProfileEntry(const char* Section, const char* Key, int DefaultValue)
{
mType = LC_PROFILE_ENTRY_INT;
mSection = Section;
mKey = Key;
mDefault.IntValue = DefaultValue;
mDefault = DefaultValue;
}
lcProfileEntry::lcProfileEntry(const char* Section, const char* Key, uint DefaultValue)
{
mType = LC_PROFILE_ENTRY_INT;
mSection = Section;
mKey = Key;
mDefault.UIntValue = DefaultValue;
mDefault = DefaultValue;
}
lcProfileEntry::lcProfileEntry(const char* Section, const char* Key, float DefaultValue)
{
mType = LC_PROFILE_ENTRY_FLOAT;
mSection = Section;
mKey = Key;
mDefault.FloatValue = DefaultValue;
mDefault = DefaultValue;
}
lcProfileEntry::lcProfileEntry(const char* Section, const char* Key, const char* DefaultValue)
{
mType = LC_PROFILE_ENTRY_STRING;
mSection = Section;
mKey = Key;
mDefault.StringValue = DefaultValue;
mDefault = QString(DefaultValue);
}
lcProfileEntry::lcProfileEntry(const char* Section, const char* Key, const QStringList& /*StringList*/)
{
mType = LC_PROFILE_ENTRY_STRINGLIST;
mSection = Section;
mKey = Key;
mDefault.IntValue = 0;
mDefault = QStringList();
}
lcProfileEntry::lcProfileEntry(const char* Section, const char* Key)
{
mType = LC_PROFILE_ENTRY_BUFFER;
mSection = Section;
mKey = Key;
mDefault.IntValue = 0;
mDefault = QByteArray();
}
static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
@@ -125,7 +119,8 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
lcProfileEntry("Settings", "ImageExtension", ".png"), // LC_PROFILE_IMAGE_EXTENSION
lcProfileEntry("Settings", "PartsListIcons", 64), // LC_PROFILE_PARTS_LIST_ICONS
lcProfileEntry("Settings", "PartsListNames", 0), // LC_PROFILE_PARTS_LIST_NAMES
lcProfileEntry("Settings", "PartsListFixedColor", -1), // LC_PROFILE_PARTS_LIST_FIXED_COLOR
lcProfileEntry("Settings", "PartsListFixedColor", -1), // LC_PROFILE_PARTS_LIST_COLOR
lcProfileEntry("Settings", "PartsListColorLocked", false), // LC_PROFILE_PARTS_LIST_COLOR_LOCKED
lcProfileEntry("Settings", "PartsListDecorated", 1), // LC_PROFILE_PARTS_LIST_DECORATED
lcProfileEntry("Settings", "PartsListAliases", 1), // LC_PROFILE_PARTS_LIST_ALIASES
lcProfileEntry("Settings", "PartsListListMode", 0), // LC_PROFILE_PARTS_LIST_LISTMODE
@@ -157,7 +152,7 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
lcProfileEntry("Blender", "AddonVersionCheck", 1), // LC_PROFILE_BLENDER_ADDON_VERSION_CHECK
lcProfileEntry("Blender", "ImportModule", ""), // LC_PROFILE_BLENDER_IMPORT_MODULE
lcProfileEntry("Settgins", "PreviewViewSphereEnabled", 0), // LC_PROFILE_PREVIEW_VIEW_SPHERE_ENABLED
lcProfileEntry("Settings", "PreviewViewSphereEnabled", 0), // LC_PROFILE_PREVIEW_VIEW_SPHERE_ENABLED
lcProfileEntry("Settings", "PreviewViewSphereSize", 75), // LC_PROFILE_PREVIEW_VIEW_SPHERE_SIZE
lcProfileEntry("Settings", "PreviewViewSphereLocation", (int)lcViewSphereLocation::TopRight), // LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION
lcProfileEntry("Settings", "DrawPreviewAxis", 0), // LC_PROFILE_PREVIEW_DRAW_AXES
@@ -175,6 +170,11 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
lcProfileEntry("Settings", "AutomateEdgeColor", 0) // LC_PROFILE_AUTOMATE_EDGE_COLOR
};
void lcProfileInit()
{
gProfileEntries[LC_PROFILE_PROJECTS_PATH].mDefault = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
}
void lcRemoveProfileKey(LC_PROFILE_KEY Key)
{
lcProfileEntry& Entry = gProfileEntries[Key];
@@ -186,41 +186,46 @@ void lcRemoveProfileKey(LC_PROFILE_KEY Key)
int lcGetProfileInt(LC_PROFILE_KEY Key)
{
lcProfileEntry& Entry = gProfileEntries[Key];
QSettings Settings;
int* DefaultInt = std::get_if<int>(&Entry.mDefault);
int DefaultValue = DefaultInt ? *DefaultInt : 0;
return Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Entry.mDefault.IntValue).toInt();
return QSettings().value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), DefaultValue).toInt();
}
uint lcGetProfileUInt(LC_PROFILE_KEY Key)
{
lcProfileEntry& Entry = gProfileEntries[Key];
QSettings Settings;
uint* DefaultUInt = std::get_if<uint>(&Entry.mDefault);
uint DefaultValue = DefaultUInt ? *DefaultUInt : 0;
return Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Entry.mDefault.UIntValue).toUInt();
return QSettings().value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), DefaultValue).toUInt();
}
float lcGetProfileFloat(LC_PROFILE_KEY Key)
{
lcProfileEntry& Entry = gProfileEntries[Key];
QSettings Settings;
float* DefaultFloat = std::get_if<float>(&Entry.mDefault);
float DefaultValue = DefaultFloat ? *DefaultFloat : 0.0f;
return Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Entry.mDefault.FloatValue).toFloat();
return QSettings().value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), DefaultValue).toFloat();
}
QString lcGetProfileString(LC_PROFILE_KEY Key)
{
lcProfileEntry& Entry = gProfileEntries[Key];
QSettings Settings;
QString* DefaultString = std::get_if<QString>(&Entry.mDefault);
QString DefaultValue = DefaultString ? *DefaultString : QString();
return Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Entry.mDefault.StringValue).toString();
return QSettings().value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), DefaultValue).toString();
}
QStringList lcGetProfileStringList(LC_PROFILE_KEY Key)
{
lcProfileEntry& Entry = gProfileEntries[Key];
QSettings Settings;
QStringList* DefaultStringList = std::get_if<QStringList>(&Entry.mDefault);
QStringList DefaultValue = DefaultStringList ? *DefaultStringList : QStringList();
return Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), QStringList()).toStringList();
return QSettings().value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), DefaultValue).toStringList();
}
QByteArray lcGetProfileBuffer(LC_PROFILE_KEY Key)
+5 -20
View File
@@ -72,6 +72,7 @@ enum LC_PROFILE_KEY
LC_PROFILE_PARTS_LIST_ICONS,
LC_PROFILE_PARTS_LIST_NAMES,
LC_PROFILE_PARTS_LIST_COLOR,
LC_PROFILE_PARTS_LIST_COLOR_LOCKED,
LC_PROFILE_PARTS_LIST_DECORATED,
LC_PROFILE_PARTS_LIST_ALIASES,
LC_PROFILE_PARTS_LIST_LISTMODE,
@@ -122,15 +123,6 @@ enum LC_PROFILE_KEY
LC_NUM_PROFILE_KEYS
};
enum LC_PROFILE_ENTRY_TYPE
{
LC_PROFILE_ENTRY_INT,
LC_PROFILE_ENTRY_FLOAT,
LC_PROFILE_ENTRY_STRING,
LC_PROFILE_ENTRY_STRINGLIST,
LC_PROFILE_ENTRY_BUFFER
};
class lcProfileEntry
{
public:
@@ -141,20 +133,13 @@ public:
lcProfileEntry(const char* Section, const char* Key, const QStringList& StringList);
lcProfileEntry(const char* Section, const char* Key);
LC_PROFILE_ENTRY_TYPE mType;
QString mSection;
QString mKey;
const char* mSection;
const char* mKey;
union
{
int IntValue;
uint UIntValue;
float FloatValue;
const char* StringValue;
} mDefault;
std::variant<int, uint, float, QString, QStringList, QByteArray> mDefault;
};
void lcProfileInit();
void lcRemoveProfileKey(LC_PROFILE_KEY Key);
int lcGetProfileInt(LC_PROFILE_KEY Key);
-1
View File
@@ -3,7 +3,6 @@
// We can't use std::expected because we only require C++17.
#include <stdexcept>
#include <variant>
class lcUnexpected
{
+4 -7
View File
@@ -490,17 +490,14 @@ bool Project::Load(const QString& FileName, bool ShowErrors)
return true;
}
bool Project::Save(const QString& FileName)
lcResult<void> Project::Save(const QString& FileName)
{
SetFileName(QString());
QFile File(FileName);
if (!File.open(QIODevice::WriteOnly))
{
QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
return false;
}
return lcUnexpected(tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
QTextStream Stream(&File);
bool Success = Save(Stream);
@@ -511,8 +508,8 @@ bool Project::Save(const QString& FileName)
SetFileName(FileName);
mModified = false;
}
return Success;
return lcResult<void>();
}
bool Project::Save(QTextStream& Stream)
+1 -1
View File
@@ -94,7 +94,7 @@ public:
void ShowModelListDialog();
bool Load(const QString& FileName, bool ShowErrors);
bool Save(const QString& FileName);
lcResult<void> Save(const QString& FileName);
bool Save(QTextStream& Stream);
void Merge(Project* Other);
bool ImportLDD(const QString& FileName);