Fix build warnings, size_type of QVector changes from Qt5 to Qt6 so we need an alias for it

Tue, 28 Jun 2022 19:47:34 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 28 Jun 2022 19:47:34 +0300
changeset 300
3a4b132b8353
parent 299
cf9a854b56a9
child 301
8ccd6fdb30dc

Fix build warnings, size_type of QVector changes from Qt5 to Qt6 so we need an alias for it

src/basics.h file | annotate | diff | comparison | revisions
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/basics.h	Tue Jun 28 19:43:55 2022 +0300
+++ b/src/basics.h	Tue Jun 28 19:47:34 2022 +0300
@@ -46,6 +46,9 @@
 //! \brief Return type of qHash. unsigned int on Qt5, unsigned long on Qt6.
 using hash_t = decltype(qHash(0));
 
+//! \brief Index type of QVector, int on Qt5, qsizetype on Qt6
+using index_t = QVector<int>::size_type;
+
 Q_DECLARE_METATYPE(glm::vec3)
 Q_DECLARE_METATYPE(glm::mat4)
 
--- a/src/libraries.cpp	Tue Jun 28 19:43:55 2022 +0300
+++ b/src/libraries.cpp	Tue Jun 28 19:47:34 2022 +0300
@@ -76,7 +76,7 @@
  * @brief Removes a library by index. Does nothing if the index is not valid.
  * @param libraryIndex Index of the library
  */
-void LibrariesModel::removeLibrary(const qsizetype libraryIndex)
+void LibrariesModel::removeLibrary(const index_t libraryIndex)
 {
 	Q_ASSERT(this->isValidIndex(libraryIndex));
 	if (this->isValidIndex(libraryIndex))
@@ -93,7 +93,7 @@
  * @param libraryIndex Index of the library
  * @return const reference
  */
-const Library& LibrariesModel::library(qsizetype libraryIndex) const
+const Library& LibrariesModel::library(index_t libraryIndex) const
 {
 	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(qsizetype libraryIndex, const QDir& path)
+void LibrariesModel::setLibraryPath(index_t 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(qsizetype libraryIndex, const Library::Role role)
+void LibrariesModel::setLibraryRole(index_t libraryIndex, const Library::Role role)
 {
 	if (this->isValidIndex(libraryIndex))
 	{
@@ -149,12 +149,12 @@
 /**
  * @returns the amount of libraries
  */
-qsizetype LibrariesModel::count() const
+index_t LibrariesModel::count() const
 {
 	return this->libraries.size();
 }
 
-void LibrariesModel::moveLibrary(const qsizetype libraryFromIndex, const qsizetype libraryToIndex)
+void LibrariesModel::moveLibrary(const index_t libraryFromIndex, const index_t libraryToIndex)
 {
 	if (isValidIndex(libraryFromIndex) and
 		(isValidIndex(libraryToIndex) or libraryToIndex == count()) and
@@ -181,7 +181,7 @@
  * @param libraryIndex Index to check
  * @returns whether or not it is valid
  */
-bool LibrariesModel::isValidIndex(const qsizetype libraryIndex) const
+bool LibrariesModel::isValidIndex(const index_t libraryIndex) const
 {
 	return libraryIndex >= 0 && libraryIndex < this->libraries.size();
 }
@@ -318,7 +318,7 @@
  * to update the table widget know when libraries are changed.
  * @param libraryIndex Index of the library.
  */
-void LibrariesModel::signalLibraryChange(const qsizetype libraryIndex)
+void LibrariesModel::signalLibraryChange(const index_t libraryIndex)
 {
 	Q_ASSERT(isValidIndex(libraryIndex));
 	const QModelIndex topLeft = this->index(static_cast<int>(libraryIndex), 0);
--- a/src/libraries.h	Tue Jun 28 19:43:55 2022 +0300
+++ b/src/libraries.h	Tue Jun 28 19:47:34 2022 +0300
@@ -55,14 +55,14 @@
 	auto end() const { return this->libraries.end(); }
 	QString findFile(QString fileName) const;
 	void addLibrary(const Library& library);
-	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 removeLibrary(const index_t libraryIndex);
+	const Library& library(index_t libraryIndex) const;
+	void setLibraryPath(index_t libraryIndex, const QDir& path);
+	void setLibraryRole(index_t libraryIndex, const Library::Role role);
 	void restoreFromSettings();
 	void storeToSettings();
-	qsizetype count() const;
-	void moveLibrary(const qsizetype libraryFromIndex, const qsizetype libraryToIndex);
+	index_t count() const;
+	void moveLibrary(const index_t libraryFromIndex, const index_t libraryToIndex);
 	// Definitions for QAbstractTableModel
 	Qt::ItemFlags flags(const QModelIndex& index) const override;
 	QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
@@ -72,7 +72,7 @@
 		int role = Qt::DisplayRole) const override;
 	int rowCount(const QModelIndex&) const override;
 	int columnCount(const QModelIndex&) const override;
-	bool isValidIndex(const qsizetype libraryIndex) const;
+	bool isValidIndex(const index_t libraryIndex) const;
 	ColorTable loadColorTable(QTextStream& errors) const;
 private:
 	enum Column
@@ -80,6 +80,6 @@
 		RoleColumn,
 		PathColumn
 	};
-	void signalLibraryChange(const qsizetype library);
+	void signalLibraryChange(const index_t library);
 	Libraries libraries;
 };
--- a/src/settingseditor/librarieseditor.cpp	Tue Jun 28 19:43:55 2022 +0300
+++ b/src/settingseditor/librarieseditor.cpp	Tue Jun 28 19:47:34 2022 +0300
@@ -71,7 +71,7 @@
 
 void LibrariesEditor::showContextMenu(const QPoint position)
 {
-	const qsizetype libraryIndex = this->currentLibraryIndex();
+	const index_t 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 qsizetype libraryIndex = currentLibraryIndex();
+		const index_t 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 qsizetype libraryIndex = this->currentLibraryIndex();
+		const index_t libraryIndex = this->currentLibraryIndex();
 		model->moveLibrary(libraryIndex, libraryIndex - 1);
 	}
 }
@@ -144,7 +144,7 @@
 void LibrariesEditor::moveCurrentLibraryDown()
 {
 	if (LibrariesModel* model = this->currentModel()) {
-		const qsizetype libraryIndex = this->currentLibraryIndex();
+		const index_t libraryIndex = this->currentLibraryIndex();
 		model->moveLibrary(libraryIndex + 1, libraryIndex);
 	}
 }
@@ -154,7 +154,7 @@
 	return qobject_cast<LibrariesModel*>(this->ui.librariesTable->model());
 }
 
-qsizetype LibrariesEditor::currentLibraryIndex() const
+index_t LibrariesEditor::currentLibraryIndex() const
 {
 	return this->ui.librariesTable->selectionModel()->currentIndex().row();
 }
--- a/src/settingseditor/librarieseditor.h	Tue Jun 28 19:43:55 2022 +0300
+++ b/src/settingseditor/librarieseditor.h	Tue Jun 28 19:47:34 2022 +0300
@@ -27,5 +27,5 @@
 	};
 	class Ui_LibrariesEditor& ui;
 	LibrariesModel* currentModel();
-	qsizetype currentLibraryIndex() const;
+	index_t currentLibraryIndex() const;
 };

mercurial