src/model.cpp

changeset 333
07e65a4c6611
parent 329
6d75fa09cc0c
child 335
c5830bce1c23
--- a/src/model.cpp	Mon Jul 04 15:37:22 2022 +0300
+++ b/src/model.cpp	Mon Jul 04 19:53:13 2022 +0300
@@ -113,9 +113,6 @@
 	return std::visit(overloaded{
 		[](const Colored<SubfileReference>& ref) {
 			QString result;
-			if (ref.inverted) {
-				result += QStringLiteral("0 BFC INVERTNEXT\r\n");
-			}
 			result += QStringLiteral("1 %1 %2 %3")
 				.arg(ref.color.index)
 				.arg(transformToString(ref.transformation))
@@ -169,50 +166,6 @@
 	}, element);
 }
 
-Model::Model(QObject *parent) :
-	QAbstractListModel{parent}
-{
-}
-
-Model::~Model()
-{
-}
-
-ElementId Model::append(const ModelElement &value)
-{
-	const std::size_t position = this->size();
-	const ElementId id = this->runningId;
-	this->runningId.value += 1;
-	const int row = narrow<int>(signed_cast(this->size()));
-	Q_EMIT this->beginInsertRows({}, row, row);
-	this->body.push_back({value, id});
-	this->positions[id] = position;
-	Q_EMIT this->endInsertRows();
-	return id;
-}
-
-const ModelElement &Model::at(std::size_t position) const
-{
-	return this->body[position].data;
-}
-
-ElementId Model::idAt(std::size_t position) const
-{
-	return this->body[position].id;
-}
-
-void Model::assignAt(std::size_t position, const ModelElement &element)
-{
-	this->body[position].data = element;
-	const QModelIndex index = this->index(narrow<int>(signed_cast(position)));
-	Q_EMIT this->dataChanged(index, index);
-}
-
-std::optional<std::size_t> Model::find(ElementId id) const
-{
-	return pointerToOptional(findInMap(this->positions, id));
-}
-
 template<typename K, typename V>
 void removeFromMap(std::map<K, V>& map, const K& key)
 {
@@ -222,72 +175,9 @@
 	}
 }
 
-void Model::remove(const std::size_t index)
-{
-	if (index <  this->body.size()) {
-		const int row = narrow<int>(signed_cast(index));
-		Q_EMIT this->beginRemoveRows({}, row, row);
-		removeFromMap(this->positions, this->body[index].id);
-		this->body.erase(this->body.begin() + row);
-		for (std::size_t i = index; i < this->body.size(); ++i) {
-			this->positions[this->body[i].id] = i;
-		}
-		Q_EMIT this->endRemoveRows();
-	}
-}
-
-int Model::rowCount(const QModelIndex &) const
-{
-	return narrow<int>(signed_cast(this->size()));
-}
-
-QVariant Model::data(const QModelIndex &index, int role) const
-{
-	const std::size_t i = unsigned_cast(index.row());
-	const ModelElement& element = this->body[i].data;
-	switch(role)
-	{
-	case Qt::DecorationRole:
-		return iconForElement(element);
-	case Qt::DisplayRole:
-		return modelElementToString(element);
-	/*
-	case Qt::ForegroundRole:
-		return object->textRepresentationForeground();
-	case Qt::BackgroundRole:
-		return object->textRepresentationBackground();
-	case Qt::FontRole:
-		return object->textRepresentationFont();
-	*/
-	default:
-		return {};
-	}
-}
-
-const ModelElement &Model::operator[](std::size_t index) const
-{
-	return this->body[index].data;
-}
-
-std::size_t Model::size() const
-{
-	return this->body.size();
-}
-
-void Model::clear()
-{
-	this->beginResetModel();
-	this->body.clear();
-	this->positions.clear();
-	this->runningId = {1};
-	this->endResetModel();
-}
-
 void save(const Model &model, QTextStream* stream)
 {
-	for (std::size_t i = 0; i < model.size(); ++i) {
-		(*stream) << modelElementToString(model[i]) << "\r\n";
-	}
+	*stream << model.toPlainText();
 }
 
 /**
@@ -296,6 +186,7 @@
  */
 void updateHeaderNameField(Model& model, const QString &name)
 {
+#if 0
 	// Update the "Name: 1234.dat" comment
 	if (model.size() >= 2) {
 		if (const Comment* nameObject = std::get_if<Comment>(&model[1])) {
@@ -304,4 +195,5 @@
 			}
 		}
 	}
+#endif
 }

mercurial