-
Notifications
You must be signed in to change notification settings - Fork 4
/
infowidget.cpp
83 lines (60 loc) · 2.42 KB
/
infowidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
This file is part of CuteVCF.
Foobar is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Foobar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
@author : Sacha Schutz <sacha@labsquare.org>
*/
#include "infowidget.h"
InfoWidget::InfoWidget(VcfModel * vcfModel, QWidget *parent)
: QWidget(parent)
{
mModel = new QStandardItemModel;
mView = new QTableView;
mVcfModel = vcfModel;
mModel->setColumnCount(2);
mView->horizontalHeader()->hide();
mView->setSelectionBehavior(QAbstractItemView::SelectRows);
mView->setModel(mModel);
mView->verticalHeader()->setVisible(false);
mView->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch);
mView->setAlternatingRowColors(true);
mView->horizontalHeader()->setHighlightSections(false);
QVBoxLayout * cLayout = new QVBoxLayout;
cLayout->addWidget(mView);
cLayout->setContentsMargins(0,0,0,0);
setLayout(cLayout);
}
void InfoWidget::setLine(const QModelIndex &index)
{
// avoid cliping with clear... Will probably change this with custom model
int count = mModel->rowCount();
mModel->removeRows(0, count);
mModel->setHorizontalHeaderLabels(QStringList()<<tr("Key")<<tr("Value"));
mView->horizontalHeader()->show();
VcfLine line = mVcfModel->line(index);
QHash<QByteArray, QVariant> infos = line.infos();
for (QByteArray key : infos.keys()){
QStandardItem * keyItem = new QStandardItem(QString::fromUtf8(key));
QStandardItem * valItem = new QStandardItem(infos.value(key).toString());
keyItem->setEditable(false);
valItem->setEditable(false);
keyItem->setToolTip(mVcfModel->header().info(key).value("Description").toString());
QList<QStandardItem*> row ;
row.append(keyItem);
row.append(valItem);
mModel->appendRow(row);
}
mView->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch);
}
void InfoWidget::clear()
{
mModel->clear();
}