src/librarycollection.cpp

changeset 1212
851ab72bb850
parent 1211
83b8ed708909
--- 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<Library>::iterator LibraryCollection::begin()
+{
+	return _libraries.begin();
+}
+
+std::vector<Library>::iterator LibraryCollection::end()
+{
+	return _libraries.end();
+}
+
+LibraryCollectionTableModel::LibraryCollectionTableModel(LibraryCollection& collection, QObject* parent) :
+    QAbstractTableModel {parent},
+    _collection {collection}
+{
+
+}

mercurial