-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtbuttonssheetview.cpp
More file actions
84 lines (68 loc) · 2.03 KB
/
Copy pathtbuttonssheetview.cpp
File metadata and controls
84 lines (68 loc) · 2.03 KB
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
84
#include "tbuttonssheetview.h"
TKeywordsModel::TKeywordsModel(QObject* parent) : QAbstractListModel(parent) {}
int TKeywordsModel::rowCount(const QModelIndex& parent) const {
Q_UNUSED(parent);
return List.count();
}
int TKeywordsModel::columnCount(const QModelIndex& parent) const {
Q_UNUSED(parent);
return 1;
}
QVariant TKeywordsModel::data(const QModelIndex& index, int role) const {
Q_UNUSED(index);
if (role == Qt::DisplayRole) {
if (index.row() < List.count())
return List[index.row()];
}
return QVariant();
}
void TKeywordsModel::AddString(QString Str) {
beginResetModel();
List.push_back(Str);
endResetModel();
}
void TKeywordsModel::clear() {
beginResetModel();
List.clear();
endResetModel();
}
QVariant TKeywordsModel::headerData(int section, Qt::Orientation o, int role) const {
Q_UNUSED(section);
Q_UNUSED(o);
if (role == Qt::DisplayRole) {
return "a";
}
return QVariant();
}
const QStringList* TKeywordsModel::StringList() const {
return &List;
}
//************************************************************************************
TButtonsSheetView::TButtonsSheetView(QWidget* parent) : QWidget(parent) {
Layout = new QVBoxLayout(this);
// Layout->setMargin(0);
Model = new TKeywordsModel(this);
ListView = new QListView(this);
Layout->addWidget(ListView);
ListView->setModel(Model);
setLayout(Layout);
connect(ListView, SIGNAL(clicked(QModelIndex)), SLOT(OnKeywordPressed(QModelIndex)));
// QString Style;
// ListView->setStyleSheet(Style);
}
TButtonsSheetView::~TButtonsSheetView() {
ClearStrings();
}
void TButtonsSheetView::ClearStrings() {
Model->clear();
}
void TButtonsSheetView::AddString(QString Word) {
if (Model->StringList()->contains(Word) == false) {
Model->AddString(Word);
};
}
void TButtonsSheetView::OnKeywordPressed(const QModelIndex& Index) {
QVariant Data = Model->data(Index);
if (Data.isValid())
emit Picked(Data.toString());
}