1 /*
2  assoc_leaderboard_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 "assoc_leaderboard_model.h"
20 
21 namespace m8r {
22 
AssocLeaderboardModel(QObject * parent)23 AssocLeaderboardModel::AssocLeaderboardModel(QObject* parent)
24     : QStandardItemModel(parent)
25 {
26     setColumnCount(2);
27     setRowCount(0);
28 }
29 
~AssocLeaderboardModel()30 AssocLeaderboardModel::~AssocLeaderboardModel()
31 {
32 }
33 
removeAllRows()34 void AssocLeaderboardModel::removeAllRows()
35 {
36     QStandardItemModel::clear();
37 
38     QStringList tableHeader;
39     tableHeader
40         << tr("Associations")
41         << tr("%");
42     // IMPROVE set tooltips: items w/ tooltips instead of just strings
43     setHorizontalHeaderLabels(tableHeader);
44 }
45 
addRow(Note * note,float associativity)46 void AssocLeaderboardModel::addRow(Note* note, float associativity)
47 {
48     QStringList tableHeader;
49     tableHeader
50         << (tr("Associations")+(title.size()?tr(" for '")+title+tr("'"):tr("")))
51         << tr("%");
52     // IMPROVE set tooltips: items w/ tooltips instead of just strings
53     setHorizontalHeaderLabels(tableHeader);
54 
55     QList<QStandardItem*> items;
56     QStandardItem* item;
57 
58     QString html;
59     html = QString(note->getName().c_str());
60     html += " (";
61     html += QString::fromStdString(note->getOutline()->getName());
62     html += ")";
63 
64     // item
65     item = new QStandardItem(html);
66     item->setToolTip(html);
67     // TODO under which ROLE this is > I should declare CUSTOM role (user+1 as constant)
68     item->setData(QVariant::fromValue(note));
69     items += item;
70 
71     html.clear();
72     if(associativity>0.29) {
73         html += "<span style='color: #00";
74         if(associativity>0.69) {
75             html += "CC";
76         } else if(associativity>0.49) {
77             html += "AA";
78         } else if(associativity>0.39) {
79             html += "66";
80         } else if(associativity>0.29) {
81             html += "44";
82         }
83         html += "00'>";
84     }
85     html += QString::number(associativity*100.);
86     html += "%";
87     if(associativity>0.29) {
88         html += "</span>";
89     }
90     items += new QStandardItem(html);
91 
92     appendRow(items);
93 }
94 
95 } // m8r namespace
96