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);