Fix build warnings

Mon, 27 Jun 2022 01:09:18 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 27 Jun 2022 01:09:18 +0300
changeset 265
b2b7af293c46
parent 264
76a025db4948
child 266
2800a15e2a2f

Fix build warnings

src/libraries.cpp file | annotate | diff | comparison | revisions
src/libraries.h file | annotate | diff | comparison | revisions
src/settingseditor/librarieseditor.cpp file | annotate | diff | comparison | revisions
src/settingseditor/librarieseditor.h file | annotate | diff | comparison | revisions
--- 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;
-}
-*/
--- a/src/libraries.h	Sun Jun 26 21:32:51 2022 +0300
+++ b/src/libraries.h	Mon Jun 27 01:09:18 2022 +0300
@@ -44,13 +44,7 @@
 Q_DECLARE_METATYPE(Library::Role)
 QDataStream &operator<<(QDataStream&, const Library&);
 QDataStream &operator>>(QDataStream&, Library&);
-
-using Libraries = QList<Library>;
-//QDataStream &operator<<(QDataStream&, const Libraries&);
-//QDataStream &operator>>(QDataStream&, Libraries&);
-//Q_DECLARE_METATYPE(Libraries)
-
-class Configuration;
+using Libraries = QVector<Library>;
 
 class LibrariesModel : public QAbstractTableModel
 {
@@ -61,14 +55,14 @@
 	auto end() const { return this->libraries.end(); }
 	QString findFile(QString fileName) const;
 	void addLibrary(const Library& library);
-	void removeLibrary(const std::size_t libraryIndex);
-	const Library& library(std::size_t libraryIndex) const;
-	void setLibraryPath(std::size_t libraryIndex, const QDir& path);
-	void setLibraryRole(std::size_t libraryIndex, const Library::Role role);
+	void removeLibrary(const qsizetype libraryIndex);
+	const Library& library(qsizetype libraryIndex) const;
+	void setLibraryPath(qsizetype libraryIndex, const QDir& path);
+	void setLibraryRole(qsizetype libraryIndex, const Library::Role role);
 	void restoreFromSettings();
 	void storeToSettings();
-	std::size_t count() const;
-	void moveLibrary(const std::size_t libraryFromIndex, const std::size_t libraryToIndex);
+	qsizetype count() const;
+	void moveLibrary(const qsizetype libraryFromIndex, const qsizetype libraryToIndex);
 	// Definitions for QAbstractTableModel
 	Qt::ItemFlags flags(const QModelIndex& index) const override;
 	QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
@@ -78,7 +72,7 @@
 		int role = Qt::DisplayRole) const override;
 	int rowCount(const QModelIndex&) const override;
 	int columnCount(const QModelIndex&) const override;
-	bool isValidIndex(const std::size_t libraryIndex) const;
+	bool isValidIndex(const qsizetype libraryIndex) const;
 	ColorTable loadColorTable(QTextStream& errors) const;
 private:
 	enum Column
@@ -86,6 +80,6 @@
 		RoleColumn,
 		PathColumn
 	};
-	void signalLibraryChange(std::size_t library);
+	void signalLibraryChange(const qsizetype library);
 	Libraries libraries;
 };
--- a/src/settingseditor/librarieseditor.cpp	Sun Jun 26 21:32:51 2022 +0300
+++ b/src/settingseditor/librarieseditor.cpp	Mon Jun 27 01:09:18 2022 +0300
@@ -71,7 +71,7 @@
 
 void LibrariesEditor::showContextMenu(const QPoint position)
 {
-	const std::size_t libraryIndex = this->currentLibraryIndex();
+	const qsizetype libraryIndex = this->currentLibraryIndex();
 	LibrariesModel* model = this->currentModel();
 	if (model != nullptr and model->isValidIndex(libraryIndex))
 	{
@@ -118,7 +118,7 @@
 void LibrariesEditor::setCurrentLibraryRole()
 {
 	if (LibrariesModel* model = this->currentModel()) {
-		const std::size_t libraryIndex = currentLibraryIndex();
+		const qsizetype libraryIndex = currentLibraryIndex();
 		QObject* senderObject = sender();
 		QAction* senderAction = qobject_cast<QAction*>(senderObject);
 		const Library::Role role = senderAction->data().value<Library::Role>();
@@ -136,7 +136,7 @@
 void LibrariesEditor::moveCurrentLibraryUp()
 {
 	if (LibrariesModel* model = this->currentModel()) {
-		const std::size_t libraryIndex = this->currentLibraryIndex();
+		const qsizetype libraryIndex = this->currentLibraryIndex();
 		model->moveLibrary(libraryIndex, libraryIndex - 1);
 	}
 }
@@ -144,7 +144,7 @@
 void LibrariesEditor::moveCurrentLibraryDown()
 {
 	if (LibrariesModel* model = this->currentModel()) {
-		const std::size_t libraryIndex = this->currentLibraryIndex();
+		const qsizetype libraryIndex = this->currentLibraryIndex();
 		model->moveLibrary(libraryIndex + 1, libraryIndex);
 	}
 }
@@ -154,10 +154,9 @@
 	return qobject_cast<LibrariesModel*>(this->ui.librariesTable->model());
 }
 
-std::size_t LibrariesEditor::currentLibraryIndex() const
+qsizetype LibrariesEditor::currentLibraryIndex() const
 {
-	const int row = this->ui.librariesTable->selectionModel()->currentIndex().row();
-	return static_cast<std::size_t>(row);
+	return this->ui.librariesTable->selectionModel()->currentIndex().row();
 }
 
 void LibrariesEditor::saveSettings()
--- a/src/settingseditor/librarieseditor.h	Sun Jun 26 21:32:51 2022 +0300
+++ b/src/settingseditor/librarieseditor.h	Mon Jun 27 01:09:18 2022 +0300
@@ -27,5 +27,5 @@
 	};
 	class Ui_LibrariesEditor& ui;
 	LibrariesModel* currentModel();
-	std::size_t currentLibraryIndex() const;
+	qsizetype currentLibraryIndex() const;
 };

mercurial