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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <QtInstanceIconView.hxx>
#include <QtInstanceIconView.moc>
#include <vcl/qt/QtUtils.hxx>
// role used for the ID in the QStandardItem
constexpr int ROLE_ID = Qt::UserRole + 1000;
QtInstanceIconView::QtInstanceIconView(QListView* pListView)
: QtInstanceWidget(pListView)
, m_pListView(pListView)
{
assert(m_pListView);
m_pModel = qobject_cast<QStandardItemModel*>(m_pListView->model());
assert(m_pModel && "list view doesn't have expected item model set");
m_pSelectionModel = m_pListView->selectionModel();
assert(m_pSelectionModel);
connect(m_pListView, &QListView::activated, this, &QtInstanceIconView::handleActivated);
connect(m_pSelectionModel, &QItemSelectionModel::selectionChanged, this,
&QtInstanceIconView::handleSelectionChanged);
}
int QtInstanceIconView::get_item_width() const
{
assert(false && "Not implemented yet");
return 0;
}
void QtInstanceIconView::set_item_width(int) { assert(false && "Not implemented yet"); }
void QtInstanceIconView::insert(int, const OUString*, const OUString*, const OUString*,
weld::TreeIter*)
{
assert(false && "Not implemented yet");
}
void QtInstanceIconView::insert(int nPos, const OUString* pStr, const OUString* pId,
const VirtualDevice* pIcon, weld::TreeIter* pRet)
{
assert(!pRet && "Support for pRet param not implemented yet");
(void)pRet;
SolarMutexGuard g;
GetQtInstance().RunInMainThread([&] {
if (nPos == -1)
nPos = m_pModel->rowCount();
QStandardItem* pItem = new QStandardItem;
if (pStr)
pItem->setText(toQString(*pStr));
if (pId)
pItem->setData(toQString(*pId), ROLE_ID);
if (pIcon)
pItem->setIcon(QIcon(toQPixmap(*pIcon)));
m_pModel->insertRow(nPos, pItem);
});
}
void QtInstanceIconView::insert_separator(int, const OUString*)
{
assert(false && "Not implemented yet");
}
OUString QtInstanceIconView::get_selected_id() const
{
SolarMutexGuard g;
OUString sId;
GetQtInstance().RunInMainThread([&] {
const QModelIndexList aSelectedIndexes = m_pSelectionModel->selectedIndexes();
if (aSelectedIndexes.empty())
return;
QVariant aIdData = aSelectedIndexes.first().data(ROLE_ID);
if (aIdData.canConvert<QString>())
sId = toOUString(aIdData.toString());
});
return sId;
}
void QtInstanceIconView::clear()
{
SolarMutexGuard g;
GetQtInstance().RunInMainThread([&] { m_pModel->clear(); });
}
int QtInstanceIconView::count_selected_items() const
{
assert(false && "Not implemented yet");
return 0;
}
OUString QtInstanceIconView::get_selected_text() const
{
assert(false && "Not implemented yet");
return OUString();
}
OUString QtInstanceIconView::get_id(int) const
{
assert(false && "Not implemented yet");
return OUString();
}
void QtInstanceIconView::select(int nPos)
{
SolarMutexGuard g;
GetQtInstance().RunInMainThread(
[&] { m_pSelectionModel->select(m_pModel->index(nPos, 0), QItemSelectionModel::Select); });
}
void QtInstanceIconView::unselect(int) { assert(false && "Not implemented yet"); }
void QtInstanceIconView::set_image(int, VirtualDevice*) { assert(false && "Not implemented yet"); }
void QtInstanceIconView::set_text(int, const OUString&) { assert(false && "Not implemented yet"); }
void QtInstanceIconView::set_id(int, const OUString&) { assert(false && "Not implemented yet"); }
void QtInstanceIconView::remove(int) { assert(false && "Not implemented yet"); }
tools::Rectangle QtInstanceIconView::get_rect(int) const
{
assert(false && "Not implemented yet");
return tools::Rectangle();
}
std::unique_ptr<weld::TreeIter> QtInstanceIconView::make_iterator(const weld::TreeIter*) const
{
assert(false && "Not implemented yet");
return nullptr;
}
bool QtInstanceIconView::get_selected(weld::TreeIter*) const
{
assert(false && "Not implemented yet");
return false;
}
bool QtInstanceIconView::get_cursor(weld::TreeIter*) const
{
assert(false && "Not implemented yet");
return false;
}
void QtInstanceIconView::set_cursor(const weld::TreeIter&)
{
assert(false && "Not implemented yet");
}
bool QtInstanceIconView::get_iter_first(weld::TreeIter&) const
{
assert(false && "Not implemented yet");
return false;
}
OUString QtInstanceIconView::get_id(const weld::TreeIter&) const
{
assert(false && "Not implemented yet");
return OUString();
}
OUString QtInstanceIconView::get_text(const weld::TreeIter&) const
{
assert(false && "Not implemented yet");
return OUString();
}
bool QtInstanceIconView::iter_next_sibling(weld::TreeIter&) const
{
assert(false && "Not implemented yet");
return false;
}
void QtInstanceIconView::scroll_to_item(const weld::TreeIter&)
{
assert(false && "Not implemented yet");
}
void QtInstanceIconView::selected_foreach(const std::function<bool(weld::TreeIter&)>&)
{
assert(false && "Not implemented yet");
}
int QtInstanceIconView::n_children() const
{
SolarMutexGuard g;
int nChildren = 0;
GetQtInstance().RunInMainThread([&] { nChildren = m_pModel->rowCount(); });
return nChildren;
}
void QtInstanceIconView::handleActivated()
{
SolarMutexGuard g;
signal_item_activated();
}
void QtInstanceIconView::handleSelectionChanged()
{
SolarMutexGuard g;
signal_selection_changed();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|