dialogs/qsidebar.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7void QSideBarDelegate::initStyleOption(QStyleOptionViewItem *option, -
8 const QModelIndex &index) const -
9{ -
10 QStyledItemDelegate::initStyleOption(option,index); -
11 QVariant value = index.data(QUrlModel::EnabledRole); -
12 if (value.isValid()) {
evaluated: value.isValid()
TRUEFALSE
yes
Evaluation Count:181
yes
Evaluation Count:1696
181-1696
13 -
14 if (!qvariant_cast<bool>(value))
partially evaluated: !qvariant_cast<bool>(value)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:181
0-181
15 option->state &= ~QStyle::State_Enabled;
never executed: option->state &= ~QStyle::State_Enabled;
0
16 }
executed: }
Execution Count:181
181
17}
executed: }
Execution Count:1877
1877
18 -
19 -
20 -
21 -
22 -
23 -
24 -
25QUrlModel::QUrlModel(QObject *parent) : QStandardItemModel(parent), showFullPath(false), fileSystemModel(0) -
26{ -
27}
executed: }
Execution Count:378
378
28 -
29 -
30 -
31 -
32QStringList QUrlModel::mimeTypes() const -
33{ -
34 return QStringList(QLatin1String("text/uri-list"));
never executed: return QStringList(QLatin1String("text/uri-list"));
0
35} -
36 -
37 -
38 -
39 -
40Qt::ItemFlags QUrlModel::flags(const QModelIndex &index) const -
41{ -
42 Qt::ItemFlags flags = QStandardItemModel::flags(index); -
43 if (index.isValid()) {
partially evaluated: index.isValid()
TRUEFALSE
yes
Evaluation Count:386
no
Evaluation Count:0
0-386
44 flags &= ~Qt::ItemIsEditable; -
45 -
46 flags &= ~Qt::ItemIsDropEnabled; -
47 }
executed: }
Execution Count:386
386
48 -
49 if (index.data(Qt::DecorationRole).isNull())
partially evaluated: index.data(Qt::DecorationRole).isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:386
0-386
50 flags &= ~Qt::ItemIsEnabled;
never executed: flags &= ~Qt::ItemIsEnabled;
0
51 -
52 return flags;
executed: return flags;
Execution Count:386
386
53} -
54 -
55 -
56 -
57 -
58QMimeData *QUrlModel::mimeData(const QModelIndexList &indexes) const -
59{ -
60 QList<QUrl> list; -
61 for (int i = 0; i < indexes.count(); ++i) {
never evaluated: i < indexes.count()
0
62 if (indexes.at(i).column() == 0)
never evaluated: indexes.at(i).column() == 0
0
63 list.append(indexes.at(i).data(UrlRole).toUrl());
never executed: list.append(indexes.at(i).data(UrlRole).toUrl());
0
64 }
never executed: }
0
65 QMimeData *data = new QMimeData(); -
66 data->setUrls(list); -
67 return data;
never executed: return data;
0
68} -
69bool QUrlModel::canDrop(QDragEnterEvent *event) -
70{ -
71 if (!event->mimeData()->formats().contains(mimeTypes().first()))
never evaluated: !event->mimeData()->formats().contains(mimeTypes().first())
0
72 return false;
never executed: return false;
0
73 -
74 const QList<QUrl> list = event->mimeData()->urls(); -
75 for (int i = 0; i < list.count(); ++i) {
never evaluated: i < list.count()
0
76 QModelIndex idx = fileSystemModel->index(list.at(0).toLocalFile()); -
77 if (!fileSystemModel->isDir(idx))
never evaluated: !fileSystemModel->isDir(idx)
0
78 return false;
never executed: return false;
0
79 }
never executed: }
0
80 return true;
never executed: return true;
0
81} -
82 -
83 -
84 -
85 -
86bool QUrlModel::dropMimeData(const QMimeData *data, Qt::DropAction action, -
87 int row, int column, const QModelIndex &parent) -
88{ -
89 if (!data->formats().contains(mimeTypes().first()))
never evaluated: !data->formats().contains(mimeTypes().first())
0
90 return false;
never executed: return false;
0
91 (void)action;; -
92 (void)column;; -
93 (void)parent;; -
94 addUrls(data->urls(), row); -
95 return true;
never executed: return true;
0
96} -
97bool QUrlModel::setData(const QModelIndex &index, const QVariant &value, int role) -
98{ -
99 if (value.type() == QVariant::Url) {
evaluated: value.type() == QVariant::Url
TRUEFALSE
yes
Evaluation Count:1459
yes
Evaluation Count:1238
1238-1459
100 QUrl url = value.toUrl(); -
101 QModelIndex dirIndex = fileSystemModel->index(url.toLocalFile()); -
102 -
103 if (showFullPath)
evaluated: showFullPath
TRUEFALSE
yes
Evaluation Count:511
yes
Evaluation Count:948
511-948
104 QStandardItemModel::setData(index, QDir::toNativeSeparators(fileSystemModel->data(dirIndex, QFileSystemModel::FilePathRole).toString()));
executed: QStandardItemModel::setData(index, QDir::toNativeSeparators(fileSystemModel->data(dirIndex, QFileSystemModel::FilePathRole).toString()));
Execution Count:511
511
105 else { -
106 QStandardItemModel::setData(index, QDir::toNativeSeparators(fileSystemModel->data(dirIndex, QFileSystemModel::FilePathRole).toString()), Qt::ToolTipRole); -
107 QStandardItemModel::setData(index, fileSystemModel->data(dirIndex).toString()); -
108 }
executed: }
Execution Count:948
948
109 QStandardItemModel::setData(index, fileSystemModel->data(dirIndex, Qt::DecorationRole), -
110 Qt::DecorationRole); -
111 QStandardItemModel::setData(index, url, UrlRole); -
112 return true;
executed: return true;
Execution Count:1459
1459
113 } -
114 return QStandardItemModel::setData(index, value, role);
executed: return QStandardItemModel::setData(index, value, role);
Execution Count:1238
1238
115} -
116 -
117void QUrlModel::setUrl(const QModelIndex &index, const QUrl &url, const QModelIndex &dirIndex) -
118{ -
119 setData(index, url, UrlRole); -
120 if (url.path().isEmpty()) {
evaluated: url.path().isEmpty()
TRUEFALSE
yes
Evaluation Count:298
yes
Evaluation Count:642
298-642
121 setData(index, fileSystemModel->myComputer()); -
122 setData(index, fileSystemModel->myComputer(Qt::DecorationRole), Qt::DecorationRole); -
123 } else {
executed: }
Execution Count:298
298
124 QString newName; -
125 if (showFullPath) {
evaluated: showFullPath
TRUEFALSE
yes
Evaluation Count:345
yes
Evaluation Count:297
297-345
126 -
127 newName = QDir::toNativeSeparators(dirIndex.data(QFileSystemModel::FilePathRole).toString()); -
128 } else {
executed: }
Execution Count:345
345
129 newName = dirIndex.data().toString(); -
130 }
executed: }
Execution Count:297
297
131 -
132 QIcon newIcon = qvariant_cast<QIcon>(dirIndex.data(Qt::DecorationRole)); -
133 if (!dirIndex.isValid()) {
partially evaluated: !dirIndex.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:642
0-642
134 newIcon = fileSystemModel->iconProvider()->icon(QFileIconProvider::Folder); -
135 newName = QFileInfo(url.toLocalFile()).fileName(); -
136 if (!invalidUrls.contains(url))
never evaluated: !invalidUrls.contains(url)
0
137 invalidUrls.append(url);
never executed: invalidUrls.append(url);
0
138 -
139 setData(index, false, EnabledRole); -
140 } else {
never executed: }
0
141 -
142 setData(index, true, EnabledRole); -
143 }
executed: }
Execution Count:642
642
144 -
145 -
146 const QSize size = newIcon.actualSize(QSize(32,32)); -
147 if (size.width() < 32) {
partially evaluated: size.width() < 32
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:642
0-642
148 QPixmap smallPixmap = newIcon.pixmap(QSize(32, 32)); -
149 newIcon.addPixmap(smallPixmap.scaledToWidth(32, Qt::SmoothTransformation)); -
150 }
never executed: }
0
151 -
152 if (index.data().toString() != newName)
partially evaluated: index.data().toString() != newName
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:642
0-642
153 setData(index, newName);
never executed: setData(index, newName);
0
154 QIcon oldIcon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole)); -
155 if (oldIcon.cacheKey() != newIcon.cacheKey())
partially evaluated: oldIcon.cacheKey() != newIcon.cacheKey()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:642
0-642
156 setData(index, newIcon, Qt::DecorationRole);
never executed: setData(index, newIcon, Qt::DecorationRole);
0
157 }
executed: }
Execution Count:642
642
158} -
159 -
160void QUrlModel::setUrls(const QList<QUrl> &list) -
161{ -
162 removeRows(0, rowCount()); -
163 invalidUrls.clear(); -
164 watching.clear(); -
165 addUrls(list, 0); -
166}
executed: }
Execution Count:643
643
167 -
168 -
169 -
170 -
171 -
172 -
173 -
174void QUrlModel::addUrls(const QList<QUrl> &list, int row, bool move) -
175{ -
176 if (row == -1)
partially evaluated: row == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:643
0-643
177 row = rowCount();
never executed: row = rowCount();
0
178 row = qMin(row, rowCount()); -
179 for (int i = list.count() - 1; i >= 0; --i) {
evaluated: i >= 0
TRUEFALSE
yes
Evaluation Count:940
yes
Evaluation Count:643
643-940
180 QUrl url = list.at(i); -
181 if (!url.isValid() || url.scheme() != QLatin1String("file"))
partially evaluated: !url.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:940
partially evaluated: url.scheme() != QLatin1String("file")
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:940
0-940
182 continue;
never executed: continue;
0
183 -
184 const QString cleanUrl = QDir::cleanPath(url.toLocalFile()); -
185 url = QUrl::fromLocalFile(cleanUrl); -
186 -
187 for (int j = 0; move && j < rowCount(); ++j) {
partially evaluated: move
TRUEFALSE
yes
Evaluation Count:1237
no
Evaluation Count:0
evaluated: j < rowCount()
TRUEFALSE
yes
Evaluation Count:297
yes
Evaluation Count:940
0-1237
188 QString local = index(j, 0).data(UrlRole).toUrl().toLocalFile(); -
189 -
190 -
191 -
192 if (index(j, 0).data(UrlRole).toUrl().toLocalFile() == cleanUrl) {
partially evaluated: index(j, 0).data(UrlRole).toUrl().toLocalFile() == cleanUrl
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:297
0-297
193 -
194 removeRow(j); -
195 if (j <= row)
never evaluated: j <= row
0
196 row--;
never executed: row--;
0
197 break;
never executed: break;
0
198 } -
199 }
executed: }
Execution Count:297
297
200 row = qMax(row, 0); -
201 QModelIndex idx = fileSystemModel->index(cleanUrl); -
202 if (!fileSystemModel->isDir(idx))
partially evaluated: !fileSystemModel->isDir(idx)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:940
0-940
203 continue;
never executed: continue;
0
204 insertRows(row, 1); -
205 setUrl(index(row, 0), url, idx); -
206 watching.append(qMakePair(idx, cleanUrl)); -
207 }
executed: }
Execution Count:940
940
208}
executed: }
Execution Count:643
643
209 -
210 -
211 -
212 -
213QList<QUrl> QUrlModel::urls() const -
214{ -
215 QList<QUrl> list; -
216 for (int i = 0; i < rowCount(); ++i)
evaluated: i < rowCount()
TRUEFALSE
yes
Evaluation Count:384
yes
Evaluation Count:192
192-384
217 list.append(data(index(i, 0), UrlRole).toUrl());
executed: list.append(data(index(i, 0), UrlRole).toUrl());
Execution Count:384
384
218 return list;
executed: return list;
Execution Count:192
192
219} -
220 -
221 -
222 -
223 -
224void QUrlModel::setFileSystemModel(QFileSystemModel *model) -
225{ -
226 if (model == fileSystemModel)
partially evaluated: model == fileSystemModel
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:378
0-378
227 return;
never executed: return;
0
228 if (fileSystemModel != 0) {
partially evaluated: fileSystemModel != 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:378
0-378
229 disconnect(model, "2""dataChanged(QModelIndex,QModelIndex)", -
230 this, "1""dataChanged(QModelIndex,QModelIndex)"); -
231 disconnect(model, "2""layoutChanged()", -
232 this, "1""layoutChanged()"); -
233 disconnect(model, "2""rowsRemoved(QModelIndex,int,int)", -
234 this, "1""layoutChanged()"); -
235 }
never executed: }
0
236 fileSystemModel = model; -
237 if (fileSystemModel != 0) {
partially evaluated: fileSystemModel != 0
TRUEFALSE
yes
Evaluation Count:378
no
Evaluation Count:0
0-378
238 connect(model, "2""dataChanged(QModelIndex,QModelIndex)", -
239 this, "1""dataChanged(QModelIndex,QModelIndex)"); -
240 connect(model, "2""layoutChanged()", -
241 this, "1""layoutChanged()"); -
242 connect(model, "2""rowsRemoved(QModelIndex,int,int)", -
243 this, "1""layoutChanged()"); -
244 }
executed: }
Execution Count:378
378
245 clear(); -
246 insertColumns(0, 1); -
247}
executed: }
Execution Count:378
378
248 -
249 -
250 -
251 -
252void QUrlModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) -
253{ -
254 QModelIndex parent = topLeft.parent(); -
255 for (int i = 0; i < watching.count(); ++i) {
evaluated: i < watching.count()
TRUEFALSE
yes
Evaluation Count:90
yes
Evaluation Count:60
60-90
256 QModelIndex index = watching.at(i).first; -
257 if (index.model() && topLeft.model()) {
evaluated: index.model()
TRUEFALSE
yes
Evaluation Count:59
yes
Evaluation Count:31
partially evaluated: topLeft.model()
TRUEFALSE
yes
Evaluation Count:59
no
Evaluation Count:0
0-59
258 qt_noop(); -
259 }
executed: }
Execution Count:59
59
260 if ( index.row() >= topLeft.row()
evaluated: index.row() >= topLeft.row()
TRUEFALSE
yes
Evaluation Count:55
yes
Evaluation Count:35
35-55
261 && index.row() <= bottomRight.row()
evaluated: index.row() <= bottomRight.row()
TRUEFALSE
yes
Evaluation Count:48
yes
Evaluation Count:7
7-48
262 && index.column() >= topLeft.column()
partially evaluated: index.column() >= topLeft.column()
TRUEFALSE
yes
Evaluation Count:48
no
Evaluation Count:0
0-48
263 && index.column() <= bottomRight.column()
partially evaluated: index.column() <= bottomRight.column()
TRUEFALSE
yes
Evaluation Count:48
no
Evaluation Count:0
0-48
264 && index.parent() == parent) {
partially evaluated: index.parent() == parent
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:48
0-48
265 changed(watching.at(i).second); -
266 }
never executed: }
0
267 }
executed: }
Execution Count:90
90
268}
executed: }
Execution Count:60
60
269 -
270 -
271 -
272 -
273void QUrlModel::layoutChanged() -
274{ -
275 QStringList paths; -
276 for (int i = 0; i < watching.count(); ++i)
evaluated: i < watching.count()
TRUEFALSE
yes
Evaluation Count:873
yes
Evaluation Count:708
708-873
277 paths.append(watching.at(i).second);
executed: paths.append(watching.at(i).second);
Execution Count:873
873
278 watching.clear(); -
279 for (int i = 0; i < paths.count(); ++i) {
evaluated: i < paths.count()
TRUEFALSE
yes
Evaluation Count:873
yes
Evaluation Count:708
708-873
280 QString path = paths.at(i); -
281 QModelIndex newIndex = fileSystemModel->index(path); -
282 watching.append(QPair<QModelIndex, QString>(newIndex, path)); -
283 if (newIndex.isValid())
evaluated: newIndex.isValid()
TRUEFALSE
yes
Evaluation Count:519
yes
Evaluation Count:354
354-519
284 changed(path);
executed: changed(path);
Execution Count:519
519
285 }
executed: }
Execution Count:873
873
286}
executed: }
Execution Count:708
708
287 -
288 -
289 -
290 -
291 -
292 -
293void QUrlModel::changed(const QString &path) -
294{ -
295 for (int i = 0; i < rowCount(); ++i) {
evaluated: i < rowCount()
TRUEFALSE
yes
Evaluation Count:873
yes
Evaluation Count:519
519-873
296 QModelIndex idx = index(i, 0); -
297 if (idx.data(UrlRole).toUrl().toLocalFile() == path) {
evaluated: idx.data(UrlRole).toUrl().toLocalFile() == path
TRUEFALSE
yes
Evaluation Count:519
yes
Evaluation Count:354
354-519
298 setData(idx, idx.data(UrlRole).toUrl()); -
299 }
executed: }
Execution Count:519
519
300 }
executed: }
Execution Count:873
873
301}
executed: }
Execution Count:519
519
302 -
303QSidebar::QSidebar(QWidget *parent) : QListView(parent) -
304{ -
305}
executed: }
Execution Count:189
189
306 -
307void QSidebar::setModelAndUrls(QFileSystemModel *model, const QList<QUrl> &newUrls) -
308{ -
309 -
310 setIconSize(QSize(24,24)); -
311 setUniformItemSizes(true); -
312 urlModel = new QUrlModel(this); -
313 urlModel->setFileSystemModel(model); -
314 setModel(urlModel); -
315 setItemDelegate(new QSideBarDelegate(this)); -
316 -
317 connect(selectionModel(), "2""currentChanged(QModelIndex,QModelIndex)", -
318 this, "1""clicked(QModelIndex)"); -
319 -
320 setDragDropMode(QAbstractItemView::DragDrop); -
321 -
322 setContextMenuPolicy(Qt::CustomContextMenu); -
323 connect(this, "2""customContextMenuRequested(QPoint)", -
324 this, "1""showContextMenu(QPoint)"); -
325 urlModel->setUrls(newUrls); -
326 setCurrentIndex(this->model()->index(0,0)); -
327}
executed: }
Execution Count:189
189
328 -
329QSidebar::~QSidebar() -
330{ -
331} -
332 -
333 -
334void QSidebar::dragEnterEvent(QDragEnterEvent *event) -
335{ -
336 if (urlModel->canDrop(event))
never evaluated: urlModel->canDrop(event)
0
337 QListView::dragEnterEvent(event);
never executed: QListView::dragEnterEvent(event);
0
338}
never executed: }
0
339 -
340 -
341QSize QSidebar::sizeHint() const -
342{ -
343 if (model())
evaluated: model()
TRUEFALSE
yes
Evaluation Count:1612
yes
Evaluation Count:567
567-1612
344 return QListView::sizeHintForIndex(model()->index(0, 0)) + QSize(2 * frameWidth(), 2 * frameWidth());
executed: return QListView::sizeHintForIndex(model()->index(0, 0)) + QSize(2 * frameWidth(), 2 * frameWidth());
Execution Count:1612
1612
345 return QListView::sizeHint();
executed: return QListView::sizeHint();
Execution Count:567
567
346} -
347 -
348void QSidebar::selectUrl(const QUrl &url) -
349{ -
350 disconnect(selectionModel(), "2""currentChanged(QModelIndex,QModelIndex)", -
351 this, "1""clicked(QModelIndex)"); -
352 -
353 selectionModel()->clear(); -
354 for (int i = 0; i < model()->rowCount(); ++i) {
evaluated: i < model()->rowCount()
TRUEFALSE
yes
Evaluation Count:660
yes
Evaluation Count:214
214-660
355 if (model()->index(i, 0).data(QUrlModel::UrlRole).toUrl() == url) {
evaluated: model()->index(i, 0).data(QUrlModel::UrlRole).toUrl() == url
TRUEFALSE
yes
Evaluation Count:211
yes
Evaluation Count:449
211-449
356 selectionModel()->select(model()->index(i, 0), QItemSelectionModel::Select); -
357 break;
executed: break;
Execution Count:211
211
358 } -
359 }
executed: }
Execution Count:449
449
360 -
361 connect(selectionModel(), "2""currentChanged(QModelIndex,QModelIndex)", -
362 this, "1""clicked(QModelIndex)"); -
363}
executed: }
Execution Count:425
425
364 -
365 -
366 -
367 -
368 -
369 -
370 -
371void QSidebar::showContextMenu(const QPoint &position) -
372{ -
373 QList<QAction *> actions; -
374 if (indexAt(position).isValid()) {
never evaluated: indexAt(position).isValid()
0
375 QAction *action = new QAction(QFileDialog::tr("Remove"), this); -
376 if (indexAt(position).data(QUrlModel::UrlRole).toUrl().path().isEmpty())
never evaluated: indexAt(position).data(QUrlModel::UrlRole).toUrl().path().isEmpty()
0
377 action->setEnabled(false);
never executed: action->setEnabled(false);
0
378 connect(action, "2""triggered()", this, "1""removeEntry()"); -
379 actions.append(action); -
380 }
never executed: }
0
381 if (actions.count() > 0)
never evaluated: actions.count() > 0
0
382 QMenu::exec(actions, mapToGlobal(position));
never executed: QMenu::exec(actions, mapToGlobal(position));
0
383}
never executed: }
0
384 -
385 -
386 -
387 -
388 -
389 -
390 -
391void QSidebar::removeEntry() -
392{ -
393 QList<QModelIndex> idxs = selectionModel()->selectedIndexes(); -
394 QList<QPersistentModelIndex> indexes; -
395 for (int i = 0; i < idxs.count(); i++)
never evaluated: i < idxs.count()
0
396 indexes.append(idxs.at(i));
never executed: indexes.append(idxs.at(i));
0
397 -
398 for (int i = 0; i < indexes.count(); ++i)
never evaluated: i < indexes.count()
0
399 if (!indexes.at(i).data(QUrlModel::UrlRole).toUrl().path().isEmpty())
never evaluated: !indexes.at(i).data(QUrlModel::UrlRole).toUrl().path().isEmpty()
0
400 model()->removeRow(indexes.at(i).row());
never executed: model()->removeRow(indexes.at(i).row());
0
401}
never executed: }
0
402 -
403 -
404 -
405 -
406 -
407 -
408void QSidebar::clicked(const QModelIndex &index) -
409{ -
410 QUrl url = model()->index(index.row(), 0).data(QUrlModel::UrlRole).toUrl(); -
411 goToUrl(url); -
412 selectUrl(url); -
413}
executed: }
Execution Count:189
189
414 -
415 -
416 -
417 -
418 -
419void QSidebar::focusInEvent(QFocusEvent *event) -
420{ -
421 QAbstractScrollArea::focusInEvent(event); -
422 viewport()->update(); -
423}
never executed: }
0
424 -
425 -
426 -
427 -
428bool QSidebar::event(QEvent * event) -
429{ -
430 if (event->type() == QEvent::KeyRelease) {
partially evaluated: event->type() == QEvent::KeyRelease
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2093
0-2093
431 QKeyEvent* ke = (QKeyEvent*) event; -
432 if (ke->key() == Qt::Key_Delete) {
never evaluated: ke->key() == Qt::Key_Delete
0
433 removeEntry(); -
434 return true;
never executed: return true;
0
435 } -
436 }
never executed: }
0
437 return QListView::event(event);
executed: return QListView::event(event);
Execution Count:2093
2093
438} -
439 -
440 -
441 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial