src/libraries.h

Tue, 24 May 2022 16:11:10 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 24 May 2022 16:11:10 +0300
changeset 188
64ea7282611e
parent 41
0abada2a9802
child 201
5d201ee4a9c3
permissions
-rw-r--r--

more work on circle tool + cleanup

/*
 *  LDForge: LDraw parts authoring CAD
 *  Copyright (C) 2013 - 2020 Teemu Piippo
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once
#include <QDir>
#include <QAbstractTableModel>
#include "main.h"
#include "colors.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};
};

bool operator==(const Library& one, const Library& other);

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

class LibraryManager : public QAbstractTableModel
{
	Q_OBJECT
public:
	LibraryManager(QObject* parent = nullptr);
	LibraryManager(Configuration* 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(Configuration* settings);
	void storeToSettings(Configuration* 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;
	ldraw::ColorTable loadColorTable(QTextStream& errors);
private:
	enum Column
	{
		RoleColumn,
		PathColumn
	};
	void signalLibraryChange(int library);
	Libraries libraries;
};

mercurial