Renamed sets to palettes.

This commit is contained in:
Leonardo Zide 2019-12-08 19:19:02 -08:00
parent 4ace604dcc
commit 9ad9675062
4 changed files with 69 additions and 60 deletions

View file

@ -185,7 +185,7 @@ void lcPartSelectionListModel::SetModelsCategory()
SetFilter(mFilter); SetFilter(mFilter);
} }
void lcPartSelectionListModel::SetCustomSetCategory(int SetIndex) void lcPartSelectionListModel::SetPaletteCategory(int SetIndex)
{ {
ClearRequests(); ClearRequests();
@ -194,8 +194,8 @@ void lcPartSelectionListModel::SetCustomSetCategory(int SetIndex)
mParts.clear(); mParts.clear();
lcPartSelectionWidget* PartSelectionWidget = mListView->GetPartSelectionWidget(); lcPartSelectionWidget* PartSelectionWidget = mListView->GetPartSelectionWidget();
const std::vector<lcPartCategoryCustomSet>& CustomSets = PartSelectionWidget->GetCustomSets(); const std::vector<lcPartPalette>& Palettes = PartSelectionWidget->GetPartPalettes();
std::vector<PieceInfo*> PartsList = lcGetPiecesLibrary()->GetPartsFromSet(CustomSets[SetIndex].Parts); std::vector<PieceInfo*> PartsList = lcGetPiecesLibrary()->GetPartsFromSet(Palettes[SetIndex].Parts);
auto lcPartSortFunc = [](const PieceInfo* a, const PieceInfo* b) auto lcPartSortFunc = [](const PieceInfo* a, const PieceInfo* b)
{ {
@ -513,14 +513,14 @@ void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos)
QModelIndex Index = indexAt(Pos); QModelIndex Index = indexAt(Pos);
mContextInfo = Index.isValid() ? mListModel->GetPieceInfo(Index.row()) : nullptr; mContextInfo = Index.isValid() ? mListModel->GetPieceInfo(Index.row()) : nullptr;
QMenu* SetMenu = Menu->addMenu(tr("Add to Set")); QMenu* SetMenu = Menu->addMenu(tr("Add to Palette"));
const std::vector<lcPartCategoryCustomSet>& CustomSets = mPartSelectionWidget->GetCustomSets(); const std::vector<lcPartPalette>& Palettes = mPartSelectionWidget->GetPartPalettes();
if (!CustomSets.empty()) if (!Palettes.empty())
{ {
for (const lcPartCategoryCustomSet& Set : CustomSets) for (const lcPartPalette& Palette : Palettes)
SetMenu->addAction(Set.Name, mPartSelectionWidget, SLOT(AddToSet())); SetMenu->addAction(Palette.Name, mPartSelectionWidget, SLOT(AddToPalette()));
} }
else else
{ {
@ -528,8 +528,8 @@ void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos)
Action->setEnabled(false); Action->setEnabled(false);
} }
QAction* RemoveAction = Menu->addAction(tr("Remove from Set"), mPartSelectionWidget, SLOT(RemoveFromSet())); QAction* RemoveAction = Menu->addAction(tr("Remove from Palette"), mPartSelectionWidget, SLOT(RemoveFromPalette()));
RemoveAction->setEnabled(mCategoryType == lcPartCategoryType::CustomSet); RemoveAction->setEnabled(mCategoryType == lcPartCategoryType::Palette);
Menu->exec(viewport()->mapToGlobal(Pos)); Menu->exec(viewport()->mapToGlobal(Pos));
delete Menu; delete Menu;
@ -551,8 +551,8 @@ void lcPartSelectionListView::SetCategory(lcPartCategoryType Type, int Index)
case lcPartCategoryType::Submodels: case lcPartCategoryType::Submodels:
mListModel->SetModelsCategory(); mListModel->SetModelsCategory();
break; break;
case lcPartCategoryType::CustomSet: case lcPartCategoryType::Palette:
mListModel->SetCustomSetCategory(Index); mListModel->SetPaletteCategory(Index);
break; break;
case lcPartCategoryType::Category: case lcPartCategoryType::Category:
mListModel->SetCategory(Index); mListModel->SetCategory(Index);
@ -714,7 +714,7 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent)
connect(mFilterWidget, SIGNAL(textChanged(const QString&)), this, SLOT(FilterChanged(const QString&))); connect(mFilterWidget, SIGNAL(textChanged(const QString&)), this, SLOT(FilterChanged(const QString&)));
connect(mCategoriesWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(CategoryChanged(QTreeWidgetItem*, QTreeWidgetItem*))); connect(mCategoriesWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(CategoryChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
LoadCustomSets(); LoadPartPalettes();
UpdateCategories(); UpdateCategories();
mSplitter->setStretchFactor(0, 0); mSplitter->setStretchFactor(0, 0);
@ -843,6 +843,9 @@ void lcPartSelectionWidget::OptionsMenuAboutToShow()
QMenu* Menu = (QMenu*)sender(); QMenu* Menu = (QMenu*)sender();
Menu->clear(); Menu->clear();
Menu->addAction("Configure Palettes...", this, SLOT(ConfigurePartPalettes()));
Menu->addSeparator();
lcPartSelectionListModel* ListModel = mPartsWidget->GetListModel(); lcPartSelectionListModel* ListModel = mPartsWidget->GetListModel();
if (gSupportsFramebufferObjectARB || gSupportsFramebufferObjectEXT) if (gSupportsFramebufferObjectARB || gSupportsFramebufferObjectEXT)
@ -904,6 +907,11 @@ void lcPartSelectionWidget::OptionsMenuAboutToShow()
} }
} }
void lcPartSelectionWidget::ConfigurePartPalettes()
{
}
void lcPartSelectionWidget::Redraw() void lcPartSelectionWidget::Redraw()
{ {
mPartsWidget->GetListModel()->Redraw(); mPartsWidget->GetListModel()->Redraw();
@ -923,68 +931,68 @@ void lcPartSelectionWidget::SetDefaultPart()
} }
} }
void lcPartSelectionWidget::LoadCustomSets() void lcPartSelectionWidget::LoadPartPalettes()
{ {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QByteArray Buffer = lcGetProfileBuffer(LC_PROFILE_PART_SETS); QByteArray Buffer = lcGetProfileBuffer(LC_PROFILE_PART_PALETTES);
QJsonDocument Document = QJsonDocument::fromJson(Buffer); QJsonDocument Document = QJsonDocument::fromJson(Buffer);
if (Document.isNull()) if (Document.isNull())
Document = QJsonDocument::fromJson((QString("{ \"Version\":1, \"Sets\": { \"%1\": [] } }").arg(tr("Favorites"))).toUtf8()); Document = QJsonDocument::fromJson((QString("{ \"Version\":1, \"Palettes\": { \"%1\": [] } }").arg(tr("Favorites"))).toUtf8());
QJsonObject RootObject = Document.object(); QJsonObject RootObject = Document.object();
mCustomSets.clear(); mPartPalettes.clear();
int Version = RootObject["Version"].toInt(0); int Version = RootObject["Version"].toInt(0);
if (Version != 1) if (Version != 1)
return; return;
QJsonObject SetsObject = RootObject["Sets"].toObject(); QJsonObject PalettesObject = RootObject["Palettes"].toObject();
for (QJsonObject::const_iterator ElementIt = SetsObject.constBegin(); ElementIt != SetsObject.constEnd(); ElementIt++) for (QJsonObject::const_iterator ElementIt = PalettesObject.constBegin(); ElementIt != PalettesObject.constEnd(); ElementIt++)
{ {
if (!ElementIt.value().isArray()) if (!ElementIt.value().isArray())
continue; continue;
lcPartCategoryCustomSet Set; lcPartPalette Palette;
Set.Name = ElementIt.key(); Palette.Name = ElementIt.key();
QJsonArray Parts = ElementIt.value().toArray(); QJsonArray Parts = ElementIt.value().toArray();
for (const QJsonValue& Part : Parts) for (const QJsonValue& Part : Parts)
Set.Parts.emplace_back(Part.toString().toStdString()); Palette.Parts.emplace_back(Part.toString().toStdString());
mCustomSets.emplace_back(std::move(Set)); mPartPalettes.emplace_back(std::move(Palette));
} }
#endif #endif
} }
void lcPartSelectionWidget::SaveCustomSets() void lcPartSelectionWidget::SavePartPalettes()
{ {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QJsonObject RootObject; QJsonObject RootObject;
RootObject["Version"] = 1; RootObject["Version"] = 1;
QJsonObject SetsObject; QJsonObject PalettesObject;
for (const lcPartCategoryCustomSet& Set: mCustomSets) for (const lcPartPalette& Palette : mPartPalettes)
{ {
QJsonArray Parts; QJsonArray Parts;
for (const std::string& PartId : Set.Parts) for (const std::string& PartId : Palette.Parts)
Parts.append(QString::fromStdString(PartId)); Parts.append(QString::fromStdString(PartId));
SetsObject[Set.Name] = Parts; PalettesObject[Palette.Name] = Parts;
} }
RootObject["Sets"] = SetsObject; RootObject["Palettes"] = PalettesObject;
QByteArray Buffer = QJsonDocument(RootObject).toJson(); QByteArray Buffer = QJsonDocument(RootObject).toJson();
lcSetProfileBuffer(LC_PROFILE_PART_SETS, Buffer); lcSetProfileBuffer(LC_PROFILE_PART_PALETTES, Buffer);
#endif #endif
} }
void lcPartSelectionWidget::AddToSet() void lcPartSelectionWidget::AddToPalette()
{ {
PieceInfo* Info = mPartsWidget->GetContextInfo(); PieceInfo* Info = mPartsWidget->GetContextInfo();
if (!Info) if (!Info)
@ -992,45 +1000,45 @@ void lcPartSelectionWidget::AddToSet()
QString SetName = ((QAction*)sender())->text(); QString SetName = ((QAction*)sender())->text();
std::vector<lcPartCategoryCustomSet>::iterator SetIt = std::find_if(mCustomSets.begin(), mCustomSets.end(), [&SetName](const lcPartCategoryCustomSet& Set) std::vector<lcPartPalette>::iterator SetIt = std::find_if(mPartPalettes.begin(), mPartPalettes.end(), [&SetName](const lcPartPalette& Set)
{ {
return Set.Name == SetName; return Set.Name == SetName;
}); });
if (SetIt == mCustomSets.end()) if (SetIt == mPartPalettes.end())
return; return;
std::string PartId = lcGetPiecesLibrary()->GetPartId(Info); std::string PartId = lcGetPiecesLibrary()->GetPartId(Info);
std::vector<std::string>& SetParts = SetIt->Parts; std::vector<std::string>& Parts = SetIt->Parts;
if (std::find(SetParts.begin(), SetParts.end(), PartId) == SetParts.end()) if (std::find(Parts.begin(), Parts.end(), PartId) == Parts.end())
{ {
SetParts.emplace_back(PartId); Parts.emplace_back(PartId);
SaveCustomSets(); SavePartPalettes();
} }
} }
void lcPartSelectionWidget::RemoveFromSet() void lcPartSelectionWidget::RemoveFromPalette()
{ {
PieceInfo* Info = mPartsWidget->GetContextInfo(); PieceInfo* Info = mPartsWidget->GetContextInfo();
if (!Info) if (!Info)
return; return;
QTreeWidgetItem* CurrentItem = mCategoriesWidget->currentItem(); QTreeWidgetItem* CurrentItem = mCategoriesWidget->currentItem();
if (!CurrentItem || CurrentItem->data(0, static_cast<int>(lcPartCategoryRole::Type)) != static_cast<int>(lcPartCategoryType::CustomSet)) if (!CurrentItem || CurrentItem->data(0, static_cast<int>(lcPartCategoryRole::Type)) != static_cast<int>(lcPartCategoryType::Palette))
return; return;
int SetIndex = CurrentItem->data(0, static_cast<int>(lcPartCategoryRole::Index)).toInt(); int SetIndex = CurrentItem->data(0, static_cast<int>(lcPartCategoryRole::Index)).toInt();
lcPartCategoryCustomSet& Set = mCustomSets[SetIndex]; lcPartPalette& Palette = mPartPalettes[SetIndex];
std::string PartId = lcGetPiecesLibrary()->GetPartId(Info); std::string PartId = lcGetPiecesLibrary()->GetPartId(Info);
std::vector<std::string>::iterator PartIt = std::find(Set.Parts.begin(), Set.Parts.end(), PartId); std::vector<std::string>::iterator PartIt = std::find(Palette.Parts.begin(), Palette.Parts.end(), PartId);
if (PartIt != Set.Parts.end()) if (PartIt != Palette.Parts.end())
{ {
Set.Parts.erase(PartIt); Palette.Parts.erase(PartIt);
mPartsWidget->SetCategory(lcPartCategoryType::CustomSet, SetIndex); mPartsWidget->SetCategory(lcPartCategoryType::Palette, SetIndex);
SaveCustomSets(); SavePartPalettes();
} }
} }
@ -1049,11 +1057,11 @@ void lcPartSelectionWidget::UpdateCategories()
QTreeWidgetItem* SubmodelsCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Submodels"))); QTreeWidgetItem* SubmodelsCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Submodels")));
SubmodelsCategoryItem->setData(0, static_cast<int>(lcPartCategoryRole::Type), static_cast<int>(lcPartCategoryType::Submodels)); SubmodelsCategoryItem->setData(0, static_cast<int>(lcPartCategoryRole::Type), static_cast<int>(lcPartCategoryType::Submodels));
for (int SetIdx = 0; SetIdx < static_cast<int>(mCustomSets.size()); SetIdx++) for (int SetIdx = 0; SetIdx < static_cast<int>(mPartPalettes.size()); SetIdx++)
{ {
const lcPartCategoryCustomSet& Set = mCustomSets[SetIdx]; const lcPartPalette& Set = mPartPalettes[SetIdx];
QTreeWidgetItem* SetCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(Set.Name)); QTreeWidgetItem* SetCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(Set.Name));
SetCategoryItem->setData(0, static_cast<int>(lcPartCategoryRole::Type), static_cast<int>(lcPartCategoryType::CustomSet)); SetCategoryItem->setData(0, static_cast<int>(lcPartCategoryRole::Type), static_cast<int>(lcPartCategoryType::Palette));
SetCategoryItem->setData(0, static_cast<int>(lcPartCategoryRole::Index), SetIdx); SetCategoryItem->setData(0, static_cast<int>(lcPartCategoryRole::Index), SetIdx);
} }

View file

@ -11,7 +11,7 @@ enum class lcPartCategoryType
AllParts, AllParts,
PartsInUse, PartsInUse,
Submodels, Submodels,
CustomSet, Palette,
Category Category
}; };
@ -21,7 +21,7 @@ enum class lcPartCategoryRole
Index Index
}; };
struct lcPartCategoryCustomSet struct lcPartPalette
{ {
QString Name; QString Name;
std::vector<std::string> Parts; std::vector<std::string> Parts;
@ -103,7 +103,7 @@ public:
void ToggleListMode(); void ToggleListMode();
void SetCategory(int CategoryIndex); void SetCategory(int CategoryIndex);
void SetModelsCategory(); void SetModelsCategory();
void SetCustomSetCategory(int SetIndex); void SetPaletteCategory(int SetIndex);
void SetCurrentModelCategory(); void SetCurrentModelCategory();
void SetFilter(const QString& Filter); void SetFilter(const QString& Filter);
void RequestPreview(int InfoIndex); void RequestPreview(int InfoIndex);
@ -209,14 +209,14 @@ public:
mPartsWidget->GetListModel()->SetColorIndex(ColorIndex); mPartsWidget->GetListModel()->SetColorIndex(ColorIndex);
} }
const std::vector<lcPartCategoryCustomSet>& GetCustomSets() const const std::vector<lcPartPalette>& GetPartPalettes() const
{ {
return mCustomSets; return mPartPalettes;
} }
public slots: public slots:
void AddToSet(); void AddToPalette();
void RemoveFromSet(); void RemoveFromPalette();
protected slots: protected slots:
void DockLocationChanged(Qt::DockWidgetArea Area); void DockLocationChanged(Qt::DockWidgetArea Area);
@ -225,10 +225,11 @@ protected slots:
void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous); void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous);
void PartChanged(const QModelIndex& Current, const QModelIndex& Previous); void PartChanged(const QModelIndex& Current, const QModelIndex& Previous);
void OptionsMenuAboutToShow(); void OptionsMenuAboutToShow();
void ConfigurePartPalettes();
protected: protected:
void LoadCustomSets(); void LoadPartPalettes();
void SaveCustomSets(); void SavePartPalettes();
virtual void resizeEvent(QResizeEvent* Event); virtual void resizeEvent(QResizeEvent* Event);
virtual bool event(QEvent* Event); virtual bool event(QEvent* Event);
@ -238,5 +239,5 @@ protected:
QAction* mFilterAction; QAction* mFilterAction;
lcPartSelectionListView* mPartsWidget; lcPartSelectionListView* mPartsWidget;
QSplitter* mSplitter; QSplitter* mSplitter;
std::vector<lcPartCategoryCustomSet> mCustomSets; std::vector<lcPartPalette> mPartPalettes;
}; };

View file

@ -77,7 +77,7 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
lcProfileEntry("Settings", "CheckUpdates", 1), // LC_PROFILE_CHECK_UPDATES lcProfileEntry("Settings", "CheckUpdates", 1), // LC_PROFILE_CHECK_UPDATES
lcProfileEntry("Settings", "ProjectsPath", ""), // LC_PROFILE_PROJECTS_PATH lcProfileEntry("Settings", "ProjectsPath", ""), // LC_PROFILE_PROJECTS_PATH
lcProfileEntry("Settings", "PartsLibrary", ""), // LC_PROFILE_PARTS_LIBRARY lcProfileEntry("Settings", "PartsLibrary", ""), // LC_PROFILE_PARTS_LIBRARY
lcProfileEntry("Settings", "PartSets"), // LC_PROFILE_PART_SETS lcProfileEntry("Settings", "PartPalettes"), // LC_PROFILE_PART_PALETTES
lcProfileEntry("Settings", "MinifigSettings", ""), // LC_PROFILE_MINIFIG_SETTINGS lcProfileEntry("Settings", "MinifigSettings", ""), // LC_PROFILE_MINIFIG_SETTINGS
lcProfileEntry("Settings", "ColorConfig", ""), // LC_PROFILE_COLOR_CONFIG lcProfileEntry("Settings", "ColorConfig", ""), // LC_PROFILE_COLOR_CONFIG
lcProfileEntry("Settings", "Shortcuts"), // LC_PROFILE_KEYBOARD_SHORTCUTS lcProfileEntry("Settings", "Shortcuts"), // LC_PROFILE_KEYBOARD_SHORTCUTS

View file

@ -25,7 +25,7 @@ enum LC_PROFILE_KEY
LC_PROFILE_CHECK_UPDATES, LC_PROFILE_CHECK_UPDATES,
LC_PROFILE_PROJECTS_PATH, LC_PROFILE_PROJECTS_PATH,
LC_PROFILE_PARTS_LIBRARY, LC_PROFILE_PARTS_LIBRARY,
LC_PROFILE_PART_SETS, LC_PROFILE_PART_PALETTES,
LC_PROFILE_MINIFIG_SETTINGS, LC_PROFILE_MINIFIG_SETTINGS,
LC_PROFILE_COLOR_CONFIG, LC_PROFILE_COLOR_CONFIG,
LC_PROFILE_KEYBOARD_SHORTCUTS, LC_PROFILE_KEYBOARD_SHORTCUTS,