1 /*
2 notes_table_model.cpp MindForger thinking notebook
3
4 Copyright (C) 2016-2020 Martin Dvorak <martin.dvorak@mindforger.com>
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "outlines_table_model.h"
20
21 namespace m8r {
22
23 using namespace std;
24
OutlinesTableModel(QObject * parent,HtmlOutlineRepresentation * htmlRepresentation)25 OutlinesTableModel::OutlinesTableModel(QObject* parent, HtmlOutlineRepresentation* htmlRepresentation)
26 : QStandardItemModel(parent), htmlRepresentation(htmlRepresentation)
27 {
28 setColumnCount(5);
29 setRowCount(0);
30 }
31
removeAllRows()32 void OutlinesTableModel::removeAllRows()
33 {
34 QStandardItemModel::clear();
35
36 QStringList tableHeader;
37 tableHeader
38 << tr("Notebooks")
39 << tr("Importance")
40 << tr("Urgency")
41 << tr("Done")
42 << tr("Ns")
43 << tr("Rs")
44 << tr("Ws")
45 << tr("Modified");
46 // IMPROVE set tooltips: items w/ tooltips instead of just strings
47 setHorizontalHeaderLabels(tableHeader);
48 }
49
addRow(Outline * outline)50 void OutlinesTableModel::addRow(Outline* outline)
51 {
52 QList<QStandardItem*> items;
53 QStandardItem* item;
54
55 string html{}, tooltip{};
56 html.reserve(500);
57 tooltip.reserve(500);
58
59 if(outline->getName().size()) {
60 tooltip = outline->getName();
61 html = tooltip;
62 } else {
63 tooltip = outline->getKey();
64 // IMPROVE parse out file name
65 string dir{};
66 pathToDirectoryAndFile(tooltip, dir, html);
67 }
68 htmlRepresentation->tagsToHtml(outline->getTags(), html);
69 // IMPROVE make showing of type configurable
70 htmlRepresentation->outlineTypeToHtml(outline->getType(), html);
71 // item
72 item = new QStandardItem(QString::fromStdString(html));
73 item->setToolTip(QString::fromStdString(tooltip));
74 // TODO under which ROLE this is > I should declare CUSTOM role (user+1 as constant)
75 item->setData(QVariant::fromValue(outline));
76 items += item;
77
78 // IMPROVE refactor to methods
79 QString s;
80
81 s.clear();
82 // stupid and ugly: correct sorting is ensured by making appropriate HTML (alpha sort), don't know how to sort using data role
83 s += "<div title='";
84 s += outline->getImportance();
85 s += "'>";
86 if(outline->getImportance() > 0) {
87 for(int i=0; i<=4; i++) {
88 if(outline->getImportance()>i) {
89 s += QChar(9733);
90 } else {
91 s += QChar(9734);
92 }
93 }
94 }
95 s += "</div>";
96 item = new QStandardItem(s);
97 item->setData(QVariant::fromValue((int8_t)(outline->getImportance())), Qt::UserRole);
98 items += item;
99
100 s.clear();
101 if(outline->getUrgency()>0) {
102 for(int i=0; i<=4; i++) {
103 if(outline->getUrgency()>i) {
104 s += QChar(0x25D5); // timer clock
105 //s += QChar(0x29D7); // sand clocks - not in fonts on macOS and Fedora
106 } else {
107 s += QChar(0x25F4); // timer clocks
108 //s += QChar(0x29D6); // sand clocks
109 }
110 }
111 }
112 item = new QStandardItem(s);
113 item->setData(QVariant::fromValue((int8_t)(outline->getUrgency())), Qt::UserRole);
114 items += item;
115
116 s.clear();
117 if(outline->getProgress() > 0) {
118 s += QString::number(outline->getProgress());
119 s += "%";
120 }
121 items += new QStandardItem(s);
122
123 item = new QStandardItem();
124 item->setData(QVariant::fromValue((unsigned)(outline->getNotesCount())), Qt::DisplayRole);
125 items += item;
126
127 item = new QStandardItem();
128 item->setData(QVariant(outline->getReads()), Qt::DisplayRole);
129 items += item;
130
131 item = new QStandardItem();
132 item->setData(QVariant(outline->getRevision()), Qt::DisplayRole);
133 items += item;
134
135 s.clear();
136 s += outline->getModifiedPretty().c_str();
137 items += new QStandardItem(s);
138
139 appendRow(items);
140 }
141
142 } // m8r namespace
143