--- a/src/model.cpp Wed Sep 22 14:03:43 2021 +0300 +++ b/src/model.cpp Mon Sep 27 21:04:45 2021 +0300 @@ -17,6 +17,7 @@ */ #include <QBrush> +#include <QFile> #include <QFont> #include "model.h" #include "modeleditcontext.h" @@ -25,8 +26,17 @@ * @brief Constructs a model * @param parent QObject parent to pass forward */ -Model::Model(QObject* parent) : - QAbstractListModel{parent} +Model::Model(QObject* parent) : + Model{"", parent} {} + +/** + * @brief Constructs a model + * @param path Path that was used to open the model + * @param parent QObject parent to pass forward + */ +Model::Model(const QString& path, QObject *parent) : + QAbstractListModel{parent}, + path{path} { connect(this, &Model::dataChanged, [&](){ this->needRecache = true; }); } @@ -256,3 +266,20 @@ { return this->body[unsigned_cast(index.row())].get(); } + +/** + * @brief Write out the model as text + */ +void Model::save() const +{ + QFile file{this->path}; + if (file.open(QIODevice::WriteOnly)) + { + QTextStream out{&file}; + for (const ModelObjectPointer& object : this->body) + { + out << object.get()->textRepresentation() << "\r\n"; + } + file.close(); + } +} \ No newline at end of file