Array cleanup.

This commit is contained in:
Leonardo Zide 2020-01-10 17:40:14 -08:00
parent 220fb26a3a
commit b43675f323
6 changed files with 35 additions and 36 deletions

View file

@ -32,7 +32,7 @@ struct lcPreferencesDialogOptions
int AASamples;
int StudLogo;
lcArray<lcLibraryCategory> Categories;
std::vector<lcLibraryCategory> Categories;
bool CategoriesModified;
bool CategoriesDefault;

View file

@ -3,7 +3,7 @@
#include "lc_file.h"
#include "lc_profile.h"
lcArray<lcLibraryCategory> gCategories;
std::vector<lcLibraryCategory> gCategories;
void lcResetDefaultCategories()
{
@ -30,7 +30,7 @@ void lcSaveDefaultCategories()
lcSetProfileBuffer(LC_PROFILE_CATEGORIES, ByteArray);
}
void lcResetCategories(lcArray<lcLibraryCategory>& Categories, bool BuiltInLibrary)
void lcResetCategories(std::vector<lcLibraryCategory>& Categories, bool BuiltInLibrary)
{
const char DefaultCategories[] =
{
@ -86,7 +86,7 @@ void lcResetCategories(lcArray<lcLibraryCategory>& Categories, bool BuiltInLibra
lcLoadCategories(Buffer, Categories);
}
bool lcLoadCategories(const QString& FileName, lcArray<lcLibraryCategory>& Categories)
bool lcLoadCategories(const QString& FileName, std::vector<lcLibraryCategory>& Categories)
{
QFile File(FileName);
@ -98,9 +98,9 @@ bool lcLoadCategories(const QString& FileName, lcArray<lcLibraryCategory>& Categ
return lcLoadCategories(FileData, Categories);
}
bool lcLoadCategories(const QByteArray& Buffer, lcArray<lcLibraryCategory>& Categories)
bool lcLoadCategories(const QByteArray& Buffer, std::vector<lcLibraryCategory>& Categories)
{
Categories.RemoveAll();
Categories.clear();
QTextStream Stream(Buffer);
@ -114,16 +114,18 @@ bool lcLoadCategories(const QByteArray& Buffer, lcArray<lcLibraryCategory>& Cate
QString Name = Line.left(Equals);
QString Keywords = Line.mid(Equals + 1);
lcLibraryCategory& Category = Categories.Add();
lcLibraryCategory Category;
Category.Name = Name.toLatin1().constData();
Category.Keywords = Keywords.toLatin1().constData();
Category.Name = Name;
Category.Keywords = Keywords.toLatin1();
Categories.emplace_back(std::move(Category));
}
return true;
}
bool lcSaveCategories(const QString& FileName, const lcArray<lcLibraryCategory>& Categories)
bool lcSaveCategories(const QString& FileName, const std::vector<lcLibraryCategory>& Categories)
{
QFile File(FileName);
@ -135,7 +137,7 @@ bool lcSaveCategories(const QString& FileName, const lcArray<lcLibraryCategory>&
return lcSaveCategories(Stream, Categories);
}
bool lcSaveCategories(QTextStream& Stream, const lcArray<lcLibraryCategory>& Categories)
bool lcSaveCategories(QTextStream& Stream, const std::vector<lcLibraryCategory>& Categories)
{
QString Format("%1=%2\r\n");

View file

@ -1,24 +1,21 @@
#pragma once
#include "lc_array.h"
struct lcLibraryCategory
{
QString Name;
QByteArray Keywords;
};
extern lcArray<lcLibraryCategory> gCategories;
extern std::vector<lcLibraryCategory> gCategories;
void lcResetDefaultCategories();
void lcLoadDefaultCategories(bool BuiltInLibrary = false);
void lcSaveDefaultCategories();
void lcResetCategories(lcArray<lcLibraryCategory>& Categories, bool BuiltInLibrary = false);
bool lcLoadCategories(const QString& FileName, lcArray<lcLibraryCategory>& Categories);
bool lcLoadCategories(const QByteArray& Buffer, lcArray<lcLibraryCategory>& Categories);
bool lcSaveCategories(const QString& FileName, const lcArray<lcLibraryCategory>& Categories);
bool lcSaveCategories(QTextStream& Stream, const lcArray<lcLibraryCategory>& Categories);
void lcResetCategories(std::vector<lcLibraryCategory>& Categories, bool BuiltInLibrary = false);
bool lcLoadCategories(const QString& FileName, std::vector<lcLibraryCategory>& Categories);
bool lcLoadCategories(const QByteArray& Buffer, std::vector<lcLibraryCategory>& Categories);
bool lcSaveCategories(const QString& FileName, const std::vector<lcLibraryCategory>& Categories);
bool lcSaveCategories(QTextStream& Stream, const std::vector<lcLibraryCategory>& Categories);
bool lcMatchCategory(const char* PieceName, const char* Expression);

View file

@ -1729,7 +1729,7 @@ bool lcPiecesLibrary::PieceInCategory(PieceInfo* Info, const char* CategoryKeywo
void lcPiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces)
{
if (CategoryIndex >= 0 && CategoryIndex < gCategories.GetSize())
if (CategoryIndex >= 0 && CategoryIndex < static_cast<int>(gCategories.size()))
GetCategoryEntries(gCategories[CategoryIndex].Keywords.constData(), GroupPieces, SinglePieces, GroupedPieces);
}

View file

@ -1110,7 +1110,7 @@ void lcPartSelectionWidget::UpdateCategories()
CurrentItem = PaletteCategoryItem;
}
for (int CategoryIdx = 0; CategoryIdx < gCategories.GetSize(); CategoryIdx++)
for (int CategoryIdx = 0; CategoryIdx < static_cast<int>(gCategories.size()); CategoryIdx++)
{
QTreeWidgetItem* CategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(gCategories[CategoryIdx].Name));
CategoryItem->setData(0, static_cast<int>(lcPartCategoryRole::Type), static_cast<int>(lcPartCategoryType::Category));

View file

@ -377,19 +377,19 @@ void lcQPreferencesDialog::on_ViewSphereSizeCombo_currentIndexChanged(int Index)
void lcQPreferencesDialog::updateCategories()
{
QTreeWidgetItem *categoryItem;
QTreeWidget *tree = ui->categoriesTree;
QTreeWidgetItem* CategoryItem;
QTreeWidget* CategoriesTree = ui->categoriesTree;
tree->clear();
CategoriesTree->clear();
for (int categoryIndex = 0; categoryIndex < mOptions->Categories.GetSize(); categoryIndex++)
for (int CategoryIndex = 0; CategoryIndex < static_cast<int>(mOptions->Categories.size()); CategoryIndex++)
{
categoryItem = new QTreeWidgetItem(tree, QStringList(mOptions->Categories[categoryIndex].Name));
categoryItem->setData(0, CategoryRole, QVariant(categoryIndex));
CategoryItem = new QTreeWidgetItem(CategoriesTree, QStringList(mOptions->Categories[CategoryIndex].Name));
CategoryItem->setData(0, CategoryRole, QVariant(CategoryIndex));
}
categoryItem = new QTreeWidgetItem(tree, QStringList(tr("Unassigned")));
categoryItem->setData(0, CategoryRole, QVariant(-1));
CategoryItem = new QTreeWidgetItem(CategoriesTree, QStringList(tr("Unassigned")));
CategoryItem->setData(0, CategoryRole, QVariant(-1));
}
void lcQPreferencesDialog::updateParts()
@ -429,13 +429,13 @@ void lcQPreferencesDialog::updateParts()
{
PieceInfo* Info = PartIt.second;
for (categoryIndex = 0; categoryIndex < mOptions->Categories.GetSize(); categoryIndex++)
for (categoryIndex = 0; categoryIndex < static_cast<int>(mOptions->Categories.size()); categoryIndex++)
{
if (Library->PieceInCategory(Info, mOptions->Categories[categoryIndex].Keywords.constData()))
break;
}
if (categoryIndex == mOptions->Categories.GetSize())
if (categoryIndex == static_cast<int>(mOptions->Categories.size()))
{
QStringList rowList(Info->m_strDescription);
rowList.append(Info->mFileName);
@ -459,10 +459,10 @@ void lcQPreferencesDialog::on_newCategory_clicked()
mOptions->CategoriesModified = true;
mOptions->CategoriesDefault = false;
mOptions->Categories.Add(category);
mOptions->Categories.emplace_back(std::move(category));
updateCategories();
ui->categoriesTree->setCurrentItem(ui->categoriesTree->topLevelItem(mOptions->Categories.GetSize() - 1));
ui->categoriesTree->setCurrentItem(ui->categoriesTree->topLevelItem(static_cast<int>(mOptions->Categories.size()) - 1));
}
void lcQPreferencesDialog::on_editCategory_clicked()
@ -508,7 +508,7 @@ void lcQPreferencesDialog::on_deleteCategory_clicked()
mOptions->CategoriesModified = true;
mOptions->CategoriesDefault = false;
mOptions->Categories.RemoveIndex(categoryIndex);
mOptions->Categories.erase(mOptions->Categories.begin() + categoryIndex);
updateCategories();
}
@ -520,7 +520,7 @@ void lcQPreferencesDialog::on_importCategories_clicked()
if (FileName.isEmpty())
return;
lcArray<lcLibraryCategory> Categories;
std::vector<lcLibraryCategory> Categories;
if (!lcLoadCategories(FileName, Categories))
{
QMessageBox::warning(this, "LeoCAD", tr("Error loading categories file."));