src/libraries.h

Sun, 19 Jan 2020 02:54:48 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 19 Jan 2020 02:54:48 +0200
changeset 22
6da867fa5429
parent 12
fe67489523b5
child 24
1a0faaaceb84
permissions
-rw-r--r--

commit work on GL rendering

#pragma once
#include <QDir>
#include <QAbstractTableModel>
#include "main.h"

class QSettings;

struct Library
{
	enum Role
	{
		OfficialLibrary,
		UnofficialLibrary,
		WorkingLibrary,
	} role;
	QDir path;
	static QString libraryRoleName(const Role role);
	static bool isValidRole(const Role role);
	constexpr static const Role allRoles[] = {OfficialLibrary, UnofficialLibrary, WorkingLibrary};
};

Q_DECLARE_METATYPE(Library)
Q_DECLARE_METATYPE(Library::Role)
QDataStream &operator<<(QDataStream&, const Library&);
QDataStream &operator>>(QDataStream&, Library&);

using Libraries = QVector<Library>;
Q_DECLARE_METATYPE(Libraries)

class LibraryManager : public QAbstractTableModel
{
	Q_OBJECT
public:
	LibraryManager(QObject* parent = nullptr);
	LibraryManager(QSettings* settings, QObject* parent = nullptr);
	QVector<Library>::const_iterator begin() const;
	QVector<Library>::const_iterator end() const;
	QString findFile(QString fileName) const;
	void addLibrary(const Library& library);
	void removeLibrary(const int libraryIndex);
	const Library& library(int libraryIndex) const;
	void setLibraryPath(int libraryIndex, const QDir& path);
	void setLibraryRole(int libraryIndex, const Library::Role role);
	void restoreFromSettings(QSettings* settings);
	void storeToSettings(QSettings* settings);
	int count() const;
	void moveLibrary(const int libraryFromIndex, const int libraryToIndex);
	// Definitions for QAbstractTableModel
	Qt::ItemFlags flags(const QModelIndex& index) const override;
	QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
	QVariant headerData(
		int section,
		Qt::Orientation orientation,
		int role = Qt::DisplayRole) const override;
	int rowCount(const QModelIndex&) const override;
	int columnCount(const QModelIndex&) const override;
	bool isValidIndex(const int libraryIndex) const;
private:
	enum Column
	{
		RoleColumn,
		PathColumn
	};
	void signalLibraryChange(int library);
	Libraries libraries;
};

mercurial