--- a/src/libraries.cpp Sun Jun 26 21:32:51 2022 +0300 +++ b/src/libraries.cpp Mon Jun 27 01:09:18 2022 +0300 @@ -76,10 +76,10 @@ * @brief Removes a library by index. Does nothing if the index is not valid. * @param libraryIndex Index of the library */ -void LibrariesModel::removeLibrary(const std::size_t libraryIndex) +void LibrariesModel::removeLibrary(const qsizetype libraryIndex) { - Q_ASSERT(isValidIndex(libraryIndex)); - if (isValidIndex(libraryIndex)) + Q_ASSERT(this->isValidIndex(libraryIndex)); + if (this->isValidIndex(libraryIndex)) { Q_EMIT layoutAboutToBeChanged(); this->libraries.erase(this->libraries.begin() + static_cast<long>(libraryIndex)); @@ -93,9 +93,9 @@ * @param libraryIndex Index of the library * @return const reference */ -const Library& LibrariesModel::library(std::size_t libraryIndex) const +const Library& LibrariesModel::library(qsizetype libraryIndex) const { - Q_ASSERT(isValidIndex(libraryIndex)); + Q_ASSERT(this->isValidIndex(libraryIndex)); return this->libraries[libraryIndex]; } @@ -104,7 +104,7 @@ * @param libraryIndex Index of the library * @param path New path */ -void LibrariesModel::setLibraryPath(std::size_t libraryIndex, const QDir& path) +void LibrariesModel::setLibraryPath(qsizetype libraryIndex, const QDir& path) { if (this->isValidIndex(libraryIndex)) { @@ -118,7 +118,7 @@ * @param libraryIndex Index of the library * @param role New role */ -void LibrariesModel::setLibraryRole(std::size_t libraryIndex, const Library::Role role) +void LibrariesModel::setLibraryRole(qsizetype libraryIndex, const Library::Role role) { if (this->isValidIndex(libraryIndex)) { @@ -149,12 +149,12 @@ /** * @returns the amount of libraries */ -std::size_t LibrariesModel::count() const +qsizetype LibrariesModel::count() const { return this->libraries.size(); } -void LibrariesModel::moveLibrary(const std::size_t libraryFromIndex, const std::size_t libraryToIndex) +void LibrariesModel::moveLibrary(const qsizetype libraryFromIndex, const qsizetype libraryToIndex) { if (isValidIndex(libraryFromIndex) and (isValidIndex(libraryToIndex) or libraryToIndex == count()) and @@ -162,17 +162,15 @@ { Q_EMIT layoutAboutToBeChanged(); const Library library = this->library(libraryFromIndex); - const auto from = this->libraries.begin() + signed_cast(libraryFromIndex); - const auto to = this->libraries.begin() + signed_cast(libraryToIndex); - if (to > from) + if (libraryToIndex > libraryFromIndex) { - this->libraries.insert(to, library); - this->libraries.erase(from); + this->libraries.insert(libraryToIndex, library); + this->libraries.removeAt(libraryFromIndex); } else if (libraryToIndex < libraryFromIndex) { - this->libraries.erase(from); - this->libraries.insert(to, library); + this->libraries.removeAt(libraryFromIndex); + this->libraries.insert(libraryToIndex, library); } Q_EMIT layoutChanged(); } @@ -183,7 +181,7 @@ * @param libraryIndex Index to check * @returns whether or not it is valid */ -bool LibrariesModel::isValidIndex(const std::size_t libraryIndex) const +bool LibrariesModel::isValidIndex(const qsizetype libraryIndex) const { return libraryIndex >= 0 && libraryIndex < this->libraries.size(); } @@ -257,9 +255,8 @@ } else { - const int row = index.row(); const Column column = static_cast<Column>(index.column()); - const Library& library = this->library(static_cast<std::size_t>(row)); + const Library& library = this->library(index.row()); switch (column) { case RoleColumn: @@ -321,7 +318,7 @@ * to update the table widget know when libraries are changed. * @param libraryIndex Index of the library. */ -void LibrariesModel::signalLibraryChange(std::size_t libraryIndex) +void LibrariesModel::signalLibraryChange(const qsizetype libraryIndex) { Q_ASSERT(isValidIndex(libraryIndex)); const QModelIndex topLeft = this->index(static_cast<int>(libraryIndex), 0); @@ -362,26 +359,3 @@ { return one.role == other.role and one.path == other.path; } - -/* -QDataStream &operator<<(QDataStream& stream, const Libraries& libs) -{ - const auto size = static_cast<std::uint32_t>(libs.size()); - stream << size; - for (std::uint32_t i = 0; i < size; ++i) { - stream << libs[i]; - } - return stream; -} - -QDataStream &operator>>(QDataStream& stream, Libraries& libs) -{ - std::uint32_t size; - stream >> size; - libs.resize(size); - for (std::uint32_t i = 0; i < size; ++i) { - stream >> libs[i]; - } - return stream; -} -*/