src/model.cpp

changeset 8
44679e468ba9
parent 3
55a55a9ec2c2
child 12
fe67489523b5
equal deleted inserted replaced
7:68443f5be176 8:44679e468ba9
1 #include <QBrush>
2 #include <QFont>
1 #include "model.h" 3 #include "model.h"
2 #include "modeleditcontext.h" 4 #include "modeleditcontext.h"
3 5
4 Model::Model() 6 Model::Model()
5 { 7 {
13 15
14 Model::EditContext Model::edit() 16 Model::EditContext Model::edit()
15 { 17 {
16 return {*this}; 18 return {*this};
17 } 19 }
20
21 int Model::rowCount(const QModelIndex&) const
22 {
23 return size();
24 }
25
26 QVariant Model::data(const QModelIndex& index, int role) const
27 {
28 const int row = index.row();
29 modelobjects::BaseObject* object = this->body[row].get();
30 switch(role)
31 {
32 case Qt::DisplayRole:
33 return object->textRepresentation();
34 case Qt::ForegroundRole:
35 return object->textRepresentationForeground();
36 case Qt::BackgroundRole:
37 return object->textRepresentationBackground();
38 case Qt::FontRole:
39 return object->textRepresentationFont();
40 default:
41 return {};
42 }
43 }
44
45 QVariant Model::getHeaderProperty(const HeaderProperty property)
46 {
47 switch (property)
48 {
49 case HeaderProperty::Name:
50 return header.name;
51 default:
52 return {};
53 }
54 }
55
56 void Model::append(ModelObjectPointer&& object)
57 {
58 this->body.push_back(std::move(object));
59 }

mercurial