src/model.cpp

changeset 140
2f383e88acf4
parent 137
fb9990772357
child 141
185eb297dc1e
equal deleted inserted replaced
139:72098474d362 140:2f383e88acf4
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include <QBrush> 19 #include <QBrush>
20 #include <QFile>
20 #include <QFont> 21 #include <QFont>
21 #include "model.h" 22 #include "model.h"
22 #include "modeleditcontext.h" 23 #include "modeleditcontext.h"
23 24
24 /** 25 /**
25 * @brief Constructs a model 26 * @brief Constructs a model
26 * @param parent QObject parent to pass forward 27 * @param parent QObject parent to pass forward
27 */ 28 */
28 Model::Model(QObject* parent) : 29 Model::Model(QObject* parent) :
29 QAbstractListModel{parent} 30 Model{"", parent} {}
31
32 /**
33 * @brief Constructs a model
34 * @param path Path that was used to open the model
35 * @param parent QObject parent to pass forward
36 */
37 Model::Model(const QString& path, QObject *parent) :
38 QAbstractListModel{parent},
39 path{path}
30 { 40 {
31 connect(this, &Model::dataChanged, [&](){ this->needRecache = true; }); 41 connect(this, &Model::dataChanged, [&](){ this->needRecache = true; });
32 } 42 }
33 43
34 /** 44 /**
254 */ 264 */
255 const ldraw::Object* Model::objectAt(const QModelIndex& index) const 265 const ldraw::Object* Model::objectAt(const QModelIndex& index) const
256 { 266 {
257 return this->body[unsigned_cast(index.row())].get(); 267 return this->body[unsigned_cast(index.row())].get();
258 } 268 }
269
270 /**
271 * @brief Write out the model as text
272 */
273 void Model::save() const
274 {
275 QFile file{this->path};
276 if (file.open(QIODevice::WriteOnly))
277 {
278 QTextStream out{&file};
279 for (const ModelObjectPointer& object : this->body)
280 {
281 out << object.get()->textRepresentation() << "\r\n";
282 }
283 file.close();
284 }
285 }

mercurial