# HG changeset patch # User Teemu Piippo # Date 1655287553 -10800 # Node ID a1f3f7d9078bf5bab3bbff3530b8a3a6f1b7ed4b # Parent 38d86002d548cd8bf2cddd395829f266d0021a4a rename LibraryManager -> LibrariesModel diff -r 38d86002d548 -r a1f3f7d9078b src/documentmanager.cpp --- a/src/documentmanager.cpp Wed Jun 15 13:03:33 2022 +0300 +++ b/src/documentmanager.cpp Wed Jun 15 13:05:53 2022 +0300 @@ -172,7 +172,7 @@ void DocumentManager::setModelPath( const ModelId modelId, const QString &newPath, - const LibraryManager &libraries, + const LibrariesModel &libraries, QTextStream &errorStream) { ModelInfo* info = findInMap(this->openModels, modelId); @@ -337,7 +337,7 @@ static QString findFile( QString referenceName, const QString& modelPath, - const LibraryManager& libraries) + const LibrariesModel& libraries) { // Try to find the file in the same place as the model itself referenceName.replace("\\", "/"); @@ -377,7 +377,7 @@ static std::set resolveReferencePaths( const DocumentManager::ModelInfo* modelInfo, - const LibraryManager* libraries) + const LibrariesModel* libraries) { std::set result; const std::set refNames = referenceNames(modelInfo->model.get()); @@ -395,7 +395,7 @@ static void loadDependenciesForModel( DocumentManager::ModelInfo* info, DocumentManager* documents, - const LibraryManager* libraries, + const LibrariesModel* libraries, std::map& missing) { bool repeat = true; @@ -425,7 +425,7 @@ } } -std::map DocumentManager::loadDependenciesForAllModels(const LibraryManager& libraries) +std::map DocumentManager::loadDependenciesForAllModels(const LibrariesModel& libraries) { std::map missing; for (auto& modelInfoPair : this->openModels) diff -r 38d86002d548 -r a1f3f7d9078b src/documentmanager.h --- a/src/documentmanager.h Wed Jun 15 13:03:33 2022 +0300 +++ b/src/documentmanager.h Wed Jun 15 13:05:53 2022 +0300 @@ -51,13 +51,13 @@ Model* findDependencyByName(const ModelId modelId, const QString& name); Model* getModelById(ModelId modelId); std::optional openModel(const QString& path, QTextStream& errorStream, const OpenType openType); - std::map loadDependenciesForAllModels(const LibraryManager &libraries); + std::map loadDependenciesForAllModels(const LibrariesModel &libraries); void closeDocument(const ModelId modelId); const QString* modelPath(ModelId modelId) const; void setModelPath( const ModelId modelId, const QString& newPath, - const LibraryManager &libraries, + const LibrariesModel &libraries, QTextStream &errorStream); bool saveModel(const ModelId modelId, QTextStream& errors); std::optional findIdForModel(const Model* model) const; diff -r 38d86002d548 -r a1f3f7d9078b src/libraries.cpp --- a/src/libraries.cpp Wed Jun 15 13:03:33 2022 +0300 +++ b/src/libraries.cpp Wed Jun 15 13:05:53 2022 +0300 @@ -24,7 +24,7 @@ * @brief Constructs a new library manager * @param parent Parent object */ -LibraryManager::LibraryManager(QObject* parent): +LibrariesModel::LibrariesModel(QObject* parent): QAbstractTableModel{parent} { } @@ -33,7 +33,7 @@ * @brief Yields a begin-terator for the libraries * @return iterator */ -QVector::const_iterator LibraryManager::begin() const +QVector::const_iterator LibrariesModel::begin() const { return this->libraries.begin(); } @@ -42,7 +42,7 @@ * @brief Yields an end-iterator for the libraries * @return iterator */ -QVector::const_iterator LibraryManager::end() const +QVector::const_iterator LibrariesModel::end() const { return this->libraries.end(); } @@ -52,7 +52,7 @@ * @param fileName File to search for * @return Full path to the file, or empty string if not found. */ -QString LibraryManager::findFile(QString fileName) const +QString LibrariesModel::findFile(QString fileName) const { QString path; fileName.replace("\\", "/"); @@ -83,7 +83,7 @@ * @brief Adds a new library to the end of the libraries list. * @param library Library to add */ -void LibraryManager::addLibrary(const Library& library) +void LibrariesModel::addLibrary(const Library& library) { Q_EMIT layoutAboutToBeChanged(); libraries.append(library); @@ -94,7 +94,7 @@ * @brief Removes a library by index. Does nothing if the index is not valid. * @param libraryIndex Index of the library */ -void LibraryManager::removeLibrary(const int libraryIndex) +void LibrariesModel::removeLibrary(const int libraryIndex) { Q_ASSERT(isValidIndex(libraryIndex)); if (isValidIndex(libraryIndex)) @@ -111,7 +111,7 @@ * @param libraryIndex Index of the library * @return const reference */ -const Library& LibraryManager::library(int libraryIndex) const +const Library& LibrariesModel::library(int libraryIndex) const { Q_ASSERT(isValidIndex(libraryIndex)); return this->libraries[libraryIndex]; @@ -122,7 +122,7 @@ * @param libraryIndex Index of the library * @param path New path */ -void LibraryManager::setLibraryPath(int libraryIndex, const QDir& path) +void LibrariesModel::setLibraryPath(int libraryIndex, const QDir& path) { if (this->isValidIndex(libraryIndex)) { @@ -136,7 +136,7 @@ * @param libraryIndex Index of the library * @param role New role */ -void LibraryManager::setLibraryRole(int libraryIndex, const Library::Role role) +void LibrariesModel::setLibraryRole(int libraryIndex, const Library::Role role) { if (this->isValidIndex(libraryIndex)) { @@ -150,7 +150,7 @@ * changes are lost. * @param settings Settings object to restore from. */ -void LibraryManager::restoreFromSettings() +void LibrariesModel::restoreFromSettings() { this->libraries = setting(); } @@ -159,7 +159,7 @@ * @brief Saves the libraries to the specified settings object. * @param settings Settings object to modify. */ -void LibraryManager::storeToSettings() +void LibrariesModel::storeToSettings() { setSetting(this->libraries); } @@ -167,12 +167,12 @@ /** * @returns the amount of libraries */ -int LibraryManager::count() const +int LibrariesModel::count() const { return this->libraries.size(); } -void LibraryManager::moveLibrary(const int libraryFromIndex, const int libraryToIndex) +void LibrariesModel::moveLibrary(const int libraryFromIndex, const int libraryToIndex) { if (isValidIndex(libraryFromIndex) and (isValidIndex(libraryToIndex) or libraryToIndex == count()) and @@ -199,7 +199,7 @@ * @param libraryIndex Index to check * @returns whether or not it is valid */ -bool LibraryManager::isValidIndex(const int libraryIndex) const +bool LibrariesModel::isValidIndex(const int libraryIndex) const { return libraryIndex >= 0 && libraryIndex < this->libraries.size(); } @@ -209,7 +209,7 @@ * @param errors Where to stream any encountered errors * @return color table */ -ColorTable LibraryManager::loadColorTable(QTextStream& errors) const +ColorTable LibrariesModel::loadColorTable(QTextStream& errors) const { ColorTable result; for (const Library& library : this->libraries) @@ -238,11 +238,11 @@ switch (role) { case Library::OfficialLibrary: - return LibraryManager::tr("Official library"); + return LibrariesModel::tr("Official library"); case Library::UnofficialLibrary: - return LibraryManager::tr("Unofficial library"); + return LibrariesModel::tr("Unofficial library"); case Library::WorkingLibrary: - return LibraryManager::tr("Working library"); + return LibrariesModel::tr("Working library"); } return "???"; } @@ -252,7 +252,7 @@ * @param index * @return Item flags */ -Qt::ItemFlags LibraryManager::flags(const QModelIndex& index) const +Qt::ItemFlags LibrariesModel::flags(const QModelIndex& index) const { Q_UNUSED(index); return Qt::ItemIsEnabled | Qt::ItemIsSelectable; @@ -265,7 +265,7 @@ * @param role Role of the data (role as in Qt model-view role, not LDraw library role) * @returns variant */ -QVariant LibraryManager::data(const QModelIndex& index, int role) const +QVariant LibrariesModel::data(const QModelIndex& index, int role) const { if (role != Qt::DisplayRole) { @@ -294,7 +294,7 @@ * @param role Role of the data (role as in Qt model-view role, not LDraw library role) * @returns variant */ -QVariant LibraryManager::headerData(int section, Qt::Orientation orientation, int role) const +QVariant LibrariesModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal and role == Qt::DisplayRole) { @@ -318,7 +318,7 @@ * @returns how many rows there are in the table. Since there is one row per library, this returns * the amount of libraries. */ -int LibraryManager::rowCount(const QModelIndex&) const +int LibrariesModel::rowCount(const QModelIndex&) const { return this->count(); } @@ -327,7 +327,7 @@ * @brief LibraryManager::columnCount * @returns how many columns there are in the table. */ -int LibraryManager::columnCount(const QModelIndex&) const +int LibrariesModel::columnCount(const QModelIndex&) const { return 2; } @@ -337,7 +337,7 @@ * to update the table widget know when libraries are changed. * @param libraryIndex Index of the library. */ -void LibraryManager::signalLibraryChange(int libraryIndex) +void LibrariesModel::signalLibraryChange(int libraryIndex) { Q_ASSERT(isValidIndex(libraryIndex)); const QModelIndex topLeft = this->index(libraryIndex, 0); diff -r 38d86002d548 -r a1f3f7d9078b src/libraries.h --- a/src/libraries.h Wed Jun 15 13:03:33 2022 +0300 +++ b/src/libraries.h Wed Jun 15 13:05:53 2022 +0300 @@ -50,11 +50,11 @@ class Configuration; -class LibraryManager : public QAbstractTableModel +class LibrariesModel : public QAbstractTableModel { Q_OBJECT public: - LibraryManager(QObject* parent = nullptr); + LibrariesModel(QObject* parent = nullptr); QVector::const_iterator begin() const; QVector::const_iterator end() const; QString findFile(QString fileName) const; diff -r 38d86002d548 -r a1f3f7d9078b src/main.cpp --- a/src/main.cpp Wed Jun 15 13:03:33 2022 +0300 +++ b/src/main.cpp Wed Jun 15 13:05:53 2022 +0300 @@ -79,7 +79,7 @@ static std::optional openModelFromPath( const QString& path, - const LibraryManager* libraries, + const LibrariesModel* libraries, DocumentManager* documents, QWidget* parent) { @@ -199,7 +199,7 @@ return title; } -static ColorTable loadColors(const LibraryManager* libraries) +static ColorTable loadColors(const LibrariesModel* libraries) { QTextStream errors; return libraries->loadColorTable(errors); @@ -330,7 +330,7 @@ DocumentManager documents; QString currentLanguage = "en"; QTranslator translator{&mainWindow}; - LibraryManager libraries{&mainWindow}; + LibrariesModel libraries{&mainWindow}; QStringList recentlyOpenedFiles; ColorTable colorTable; gl::RenderPreferences renderPreferences; diff -r 38d86002d548 -r a1f3f7d9078b src/settingseditor/librarieseditor.h --- a/src/settingseditor/librarieseditor.h Wed Jun 15 13:03:33 2022 +0300 +++ b/src/settingseditor/librarieseditor.h Wed Jun 15 13:05:53 2022 +0300 @@ -24,7 +24,7 @@ RoleColumn, PathColumn }; - LibraryManager libraries; + LibrariesModel libraries; class Ui_LibrariesEditor& ui; int currentLibraryIndex() const; }; diff -r 38d86002d548 -r a1f3f7d9078b src/settingseditor/settingseditor.h --- a/src/settingseditor/settingseditor.h Wed Jun 15 13:03:33 2022 +0300 +++ b/src/settingseditor/settingseditor.h Wed Jun 15 13:05:53 2022 +0300 @@ -17,7 +17,7 @@ void handleAccepted(); private: class Ui_SettingsEditor& ui; - LibraryManager libraries; + LibrariesModel libraries; LibrariesEditor librariesEditor; const uiutilities::KeySequenceMap defaultKeyboardShortcuts; void loadLocales();