/
currentrecord.cpp
74 lines (65 loc) · 2.23 KB
/
currentrecord.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
#include "currentrecord.h"
#include "ui_currentrecord.h"
CurrentRecord::CurrentRecord(QWidget *parent) : QWidget(parent), ui(new Ui::CurrentRecord), selectedItem(0){
ui->setupUi(this);
setWindowFlags(Qt::WindowStaysOnTopHint);
this->move(0,0);
}
CurrentRecord::~CurrentRecord(){
delete ui;
}
void CurrentRecord::setRecord(QStringList header, QStringList record){
clearList();
// Make listView generic control function.
QStandardItemModel *headModel = new QStandardItemModel(0);
for (int i = 0; i < header.size(); ++i) {
QStandardItem *item;
item = new QStandardItem(header.at(i));
headModel->appendRow(item);
}
ui->headerView->setModel(headModel);
ui->listWidget->insertItems(0,record);
ui->hbox->setAlignment(Qt::AlignLeft);
ui->vbox->setAlignment(Qt::AlignLeft);
setWidth(header,record);
setHeight(header.size(),record.size());
this->layout()->setAlignment(this,Qt::AlignLeft);
this->adjustSize();
}
void CurrentRecord::clearList(){
selectedItem = 0;
ui->headerView->clearFocus();
ui->listWidget->clear();
}
void CurrentRecord::setSelection(int column){
ui->listWidget->itemSelectionChanged();
ui->listWidget->item(column)->setSelected(true);
selectedItem = column;
setClipBoard();
}
void CurrentRecord::setWidth(QStringList header, QStringList record){
int headerWidth = 0;
for (int i = 0; i < header.size(); ++i) {
if (headerWidth < header.at(i).length()) {
headerWidth = header.at(i).length();
}
}
int recordWidth = 15;
for (int i = 0; i < record.size(); ++i) {
if (recordWidth < record.at(i).length()) {
recordWidth = record.at(i).length();
}
}
ui->headerView->setMaximumWidth((headerWidth*8));
ui->listWidget->setMaximumWidth((recordWidth*8));
ui->headerView->setMinimumWidth((headerWidth*8));
ui->listWidget->setMinimumWidth((recordWidth*8));
}
void CurrentRecord::setHeight(int header, int record){
ui->headerView->setMinimumHeight(header*3);
ui->listWidget->setMinimumHeight(record*3);
}
void CurrentRecord::setClipBoard(){
clipboard = QApplication::clipboard();
clipboard->setText(ui->listWidget->item(selectedItem)->text());
}