# HG changeset patch # User Teemu Piippo # Date 1494152998 -10800 # Node ID 851ab72bb850db89b62ec306a7e47cad15f25b5e # Parent 83b8ed70890916cefcd91c8d586549b0fccc8380 Worked more on the library collection thing diff -r 83b8ed708909 -r 851ab72bb850 src/basics.h --- a/src/basics.h Mon Mar 27 14:56:05 2017 +0300 +++ b/src/basics.h Sun May 07 13:29:58 2017 +0300 @@ -36,6 +36,7 @@ template using Pair = std::pair; +using std::vector; enum Axis { diff -r 83b8ed708909 -r 851ab72bb850 src/dialogs/configdialog.ui --- a/src/dialogs/configdialog.ui Mon Mar 27 14:56:05 2017 +0300 +++ b/src/dialogs/configdialog.ui Sun May 07 13:29:58 2017 +0300 @@ -51,6 +51,11 @@ + Libraries + + + + Shortcuts @@ -79,7 +84,7 @@ - 0 + 3 @@ -533,6 +538,22 @@ + + + + + + Libraries + + + + + + + + + + diff -r 83b8ed708909 -r 851ab72bb850 src/documentmanager.cpp --- a/src/documentmanager.cpp Mon Mar 27 14:56:05 2017 +0300 +++ b/src/documentmanager.cpp Sun May 07 13:29:58 2017 +0300 @@ -41,7 +41,7 @@ m_logoedStud (nullptr), m_logoedStud2 (nullptr) { - m_libraries.addLibrary(configuration().lDrawPath(), "LDraw library"); + m_libraries.addLibrary(configuration().lDrawPath(), "LDraw library", true); } DocumentManager::~DocumentManager() diff -r 83b8ed708909 -r 851ab72bb850 src/librarycollection.cpp --- a/src/librarycollection.cpp Mon Mar 27 14:56:05 2017 +0300 +++ b/src/librarycollection.cpp Sun May 07 13:29:58 2017 +0300 @@ -20,9 +20,9 @@ const QStringList LibraryCollection::directoryNames = {"parts", "p"}; -void LibraryCollection::addLibrary(QDir dir, QString name) +void LibraryCollection::addLibrary(QDir dir, QString name, bool frozen) { - Super::append({dir, name}); + _libraries.emplace_back(dir, name, frozen); } /* @@ -34,11 +34,11 @@ // slashes so that Qt understands them on all platforms. relativePath.replace('\\', '/'); - for (const Library& library : *this) + for (const Library& library : _libraries) { for (const QString& directoryName : directoryNames) { - QDir dir = library.path; + QDir dir = library.path(); if (dir.exists() and dir.cd(directoryName) and dir.exists(relativePath)) return QDir::cleanPath(dir.absoluteFilePath(relativePath)); @@ -63,7 +63,7 @@ */ QString LibraryCollection::find(const FileSpec& spec) const { - for (const Library& library : *this) + for (const Library& library : _libraries) { try { @@ -78,14 +78,22 @@ } /* + * Constructs a new library. + */ +Library::Library(const QDir& path, const QString& name, bool frozen) : + _path {path}, + _name {name}, + _frozen {frozen} {} + +/* * Returns the appropriate subdirectory for the given file type. */ QDir Library::subdirectory(FileType type) const { QString subdirectory = subdirectoryName(type); - if (path.exists(subdirectory)) - return path.absolutePath() + "/" + subdirectory; + if (path().exists(subdirectory)) + return path().absolutePath() + "/" + subdirectory; else throw SubdirectoryNotFoundError {}; } @@ -115,3 +123,25 @@ return ""; } + +QDir Library::path() const +{ + return _path; +} + +std::vector::iterator LibraryCollection::begin() +{ + return _libraries.begin(); +} + +std::vector::iterator LibraryCollection::end() +{ + return _libraries.end(); +} + +LibraryCollectionTableModel::LibraryCollectionTableModel(LibraryCollection& collection, QObject* parent) : + QAbstractTableModel {parent}, + _collection {collection} +{ + +} diff -r 83b8ed708909 -r 851ab72bb850 src/librarycollection.h --- a/src/librarycollection.h Mon Mar 27 14:56:05 2017 +0300 +++ b/src/librarycollection.h Sun May 07 13:29:58 2017 +0300 @@ -20,8 +20,12 @@ #include #include "main.h" -struct Library +/* + * Models an LDraw library. + */ +class Library { +public: class SubdirectoryNotFoundError : public std::exception {}; enum FileType @@ -33,18 +37,25 @@ LowResolutionPrimitive, }; - QDir path; - QString name; + Library(const QDir& path, const QString& name, bool frozen); + bool frozen() const; + QDir path() const; + QString name() const; QDir subdirectory(FileType type) const; static QString subdirectoryName(FileType type); + +private: + QDir _path; + QString _name; + bool _frozen; }; /* * Models a collection of libraries. A library is a folder containing directories named "p" and * "parts" that contains part and subpart files. */ -class LibraryCollection : public QObject, private QVector +class LibraryCollection : public QObject { Q_OBJECT using Super = QVector; @@ -56,10 +67,25 @@ Library::FileType type; }; - void addLibrary(QDir dir, QString name); + void addLibrary(QDir dir, QString name, bool frozen); QString find(QString relativePath) const; QString find(const QString& name, Library::FileType type) const; QString find(const FileSpec& spec) const; + std::vector::iterator begin(); + std::vector::iterator end(); static const QStringList directoryNames; + +private: + std::vector _libraries; }; + +#include +class LibraryCollectionTableModel : public QAbstractTableModel +{ +public: + LibraryCollectionTableModel(LibraryCollection& collection, QObject* parent = nullptr); + +private: + LibraryCollection& _collection; +};