| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - |
| 7 | ** | - |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
| 9 | ** Commercial License Usage | - |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
| 11 | ** accordance with the commercial license agreement provided with the | - |
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - |
| 13 | ** a written agreement between you and Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
| 16 | ** | - |
| 17 | ** GNU Lesser General Public License Usage | - |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
| 19 | ** General Public License version 2.1 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include "qsidebar_p.h" | - |
| 43 | #include "qfilesystemmodel.h" | - |
| 44 | | - |
| 45 | #ifndef QT_NO_FILEDIALOG | - |
| 46 | | - |
| 47 | #include <qaction.h> | - |
| 48 | #include <qurl.h> | - |
| 49 | #include <qmenu.h> | - |
| 50 | #include <qmimedata.h> | - |
| 51 | #include <qevent.h> | - |
| 52 | #include <qdebug.h> | - |
| 53 | #include <qfileiconprovider.h> | - |
| 54 | #include <qfiledialog.h> | - |
| 55 | | - |
| 56 | QT_BEGIN_NAMESPACE | - |
| 57 | | - |
| 58 | void QSideBarDelegate::initStyleOption(QStyleOptionViewItem *option, | - |
| 59 | const QModelIndex &index) const | - |
| 60 | { | - |
| 61 | QStyledItemDelegate::initStyleOption(option,index); executed (the execution status of this line is deduced): QStyledItemDelegate::initStyleOption(option,index); | - |
| 62 | QVariant value = index.data(QUrlModel::EnabledRole); executed (the execution status of this line is deduced): QVariant value = index.data(QUrlModel::EnabledRole); | - |
| 63 | if (value.isValid()) { evaluated: value.isValid()| yes Evaluation Count:181 | yes Evaluation Count:1696 |
| 181-1696 |
| 64 | //If the bookmark/entry is not enabled then we paint it in gray | - |
| 65 | if (!qvariant_cast<bool>(value)) partially evaluated: !qvariant_cast<bool>(value)| no Evaluation Count:0 | yes Evaluation Count:181 |
| 0-181 |
| 66 | option->state &= ~QStyle::State_Enabled; never executed: option->state &= ~QStyle::State_Enabled; | 0 |
| 67 | } executed: }Execution Count:181 | 181 |
| 68 | } executed: }Execution Count:1877 | 1877 |
| 69 | | - |
| 70 | /*! | - |
| 71 | QUrlModel lets you have indexes from a QFileSystemModel to a list. When QFileSystemModel | - |
| 72 | changes them QUrlModel will automatically update. | - |
| 73 | | - |
| 74 | Example usage: File dialog sidebar and combo box | - |
| 75 | */ | - |
| 76 | QUrlModel::QUrlModel(QObject *parent) : QStandardItemModel(parent), showFullPath(false), fileSystemModel(0) | - |
| 77 | { | - |
| 78 | } executed: }Execution Count:378 | 378 |
| 79 | | - |
| 80 | /*! | - |
| 81 | \reimp | - |
| 82 | */ | - |
| 83 | QStringList QUrlModel::mimeTypes() const | - |
| 84 | { | - |
| 85 | return QStringList(QLatin1String("text/uri-list")); never executed: return QStringList(QLatin1String("text/uri-list")); | 0 |
| 86 | } | - |
| 87 | | - |
| 88 | /*! | - |
| 89 | \reimp | - |
| 90 | */ | - |
| 91 | Qt::ItemFlags QUrlModel::flags(const QModelIndex &index) const | - |
| 92 | { | - |
| 93 | Qt::ItemFlags flags = QStandardItemModel::flags(index); executed (the execution status of this line is deduced): Qt::ItemFlags flags = QStandardItemModel::flags(index); | - |
| 94 | if (index.isValid()) { partially evaluated: index.isValid()| yes Evaluation Count:386 | no Evaluation Count:0 |
| 0-386 |
| 95 | flags &= ~Qt::ItemIsEditable; executed (the execution status of this line is deduced): flags &= ~Qt::ItemIsEditable; | - |
| 96 | // ### some future version could support "moving" urls onto a folder | - |
| 97 | flags &= ~Qt::ItemIsDropEnabled; executed (the execution status of this line is deduced): flags &= ~Qt::ItemIsDropEnabled; | - |
| 98 | } executed: }Execution Count:386 | 386 |
| 99 | | - |
| 100 | if (index.data(Qt::DecorationRole).isNull()) partially evaluated: index.data(Qt::DecorationRole).isNull()| no Evaluation Count:0 | yes Evaluation Count:386 |
| 0-386 |
| 101 | flags &= ~Qt::ItemIsEnabled; never executed: flags &= ~Qt::ItemIsEnabled; | 0 |
| 102 | | - |
| 103 | return flags; executed: return flags;Execution Count:386 | 386 |
| 104 | } | - |
| 105 | | - |
| 106 | /*! | - |
| 107 | \reimp | - |
| 108 | */ | - |
| 109 | QMimeData *QUrlModel::mimeData(const QModelIndexList &indexes) const | - |
| 110 | { | - |
| 111 | QList<QUrl> list; never executed (the execution status of this line is deduced): QList<QUrl> list; | - |
| 112 | for (int i = 0; i < indexes.count(); ++i) { never evaluated: i < indexes.count() | 0 |
| 113 | if (indexes.at(i).column() == 0) never evaluated: indexes.at(i).column() == 0 | 0 |
| 114 | list.append(indexes.at(i).data(UrlRole).toUrl()); never executed: list.append(indexes.at(i).data(UrlRole).toUrl()); | 0 |
| 115 | } | 0 |
| 116 | QMimeData *data = new QMimeData(); never executed (the execution status of this line is deduced): QMimeData *data = new QMimeData(); | - |
| 117 | data->setUrls(list); never executed (the execution status of this line is deduced): data->setUrls(list); | - |
| 118 | return data; never executed: return data; | 0 |
| 119 | } | - |
| 120 | | - |
| 121 | #ifndef QT_NO_DRAGANDDROP | - |
| 122 | | - |
| 123 | /*! | - |
| 124 | Decide based upon the data if it should be accepted or not | - |
| 125 | | - |
| 126 | We only accept dirs and not files | - |
| 127 | */ | - |
| 128 | bool QUrlModel::canDrop(QDragEnterEvent *event) | - |
| 129 | { | - |
| 130 | if (!event->mimeData()->formats().contains(mimeTypes().first())) never evaluated: !event->mimeData()->formats().contains(mimeTypes().first()) | 0 |
| 131 | return false; never executed: return false; | 0 |
| 132 | | - |
| 133 | const QList<QUrl> list = event->mimeData()->urls(); never executed (the execution status of this line is deduced): const QList<QUrl> list = event->mimeData()->urls(); | - |
| 134 | for (int i = 0; i < list.count(); ++i) { never evaluated: i < list.count() | 0 |
| 135 | QModelIndex idx = fileSystemModel->index(list.at(0).toLocalFile()); never executed (the execution status of this line is deduced): QModelIndex idx = fileSystemModel->index(list.at(0).toLocalFile()); | - |
| 136 | if (!fileSystemModel->isDir(idx)) never evaluated: !fileSystemModel->isDir(idx) | 0 |
| 137 | return false; never executed: return false; | 0 |
| 138 | } | 0 |
| 139 | return true; never executed: return true; | 0 |
| 140 | } | - |
| 141 | | - |
| 142 | /*! | - |
| 143 | \reimp | - |
| 144 | */ | - |
| 145 | bool QUrlModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - |
| 146 | int row, int column, const QModelIndex &parent) | - |
| 147 | { | - |
| 148 | if (!data->formats().contains(mimeTypes().first())) never evaluated: !data->formats().contains(mimeTypes().first()) | 0 |
| 149 | return false; never executed: return false; | 0 |
| 150 | Q_UNUSED(action); never executed (the execution status of this line is deduced): (void)action;; | - |
| 151 | Q_UNUSED(column); never executed (the execution status of this line is deduced): (void)column;; | - |
| 152 | Q_UNUSED(parent); never executed (the execution status of this line is deduced): (void)parent;; | - |
| 153 | addUrls(data->urls(), row); never executed (the execution status of this line is deduced): addUrls(data->urls(), row); | - |
| 154 | return true; never executed: return true; | 0 |
| 155 | } | - |
| 156 | | - |
| 157 | #endif // QT_NO_DRAGANDDROP | - |
| 158 | | - |
| 159 | /*! | - |
| 160 | \reimp | - |
| 161 | | - |
| 162 | If the role is the UrlRole then handle otherwise just pass to QStandardItemModel | - |
| 163 | */ | - |
| 164 | bool QUrlModel::setData(const QModelIndex &index, const QVariant &value, int role) | - |
| 165 | { | - |
| 166 | if (value.type() == QVariant::Url) { evaluated: value.type() == QVariant::Url| yes Evaluation Count:1459 | yes Evaluation Count:1238 |
| 1238-1459 |
| 167 | QUrl url = value.toUrl(); executed (the execution status of this line is deduced): QUrl url = value.toUrl(); | - |
| 168 | QModelIndex dirIndex = fileSystemModel->index(url.toLocalFile()); executed (the execution status of this line is deduced): QModelIndex dirIndex = fileSystemModel->index(url.toLocalFile()); | - |
| 169 | //On windows the popup display the "C:\", convert to nativeSeparators | - |
| 170 | if (showFullPath) evaluated: showFullPath| yes Evaluation Count:511 | yes Evaluation Count:948 |
| 511-948 |
| 171 | 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 |
| 172 | else { | - |
| 173 | QStandardItemModel::setData(index, QDir::toNativeSeparators(fileSystemModel->data(dirIndex, QFileSystemModel::FilePathRole).toString()), Qt::ToolTipRole); executed (the execution status of this line is deduced): QStandardItemModel::setData(index, QDir::toNativeSeparators(fileSystemModel->data(dirIndex, QFileSystemModel::FilePathRole).toString()), Qt::ToolTipRole); | - |
| 174 | QStandardItemModel::setData(index, fileSystemModel->data(dirIndex).toString()); executed (the execution status of this line is deduced): QStandardItemModel::setData(index, fileSystemModel->data(dirIndex).toString()); | - |
| 175 | } executed: }Execution Count:948 | 948 |
| 176 | QStandardItemModel::setData(index, fileSystemModel->data(dirIndex, Qt::DecorationRole), executed (the execution status of this line is deduced): QStandardItemModel::setData(index, fileSystemModel->data(dirIndex, Qt::DecorationRole), | - |
| 177 | Qt::DecorationRole); executed (the execution status of this line is deduced): Qt::DecorationRole); | - |
| 178 | QStandardItemModel::setData(index, url, UrlRole); executed (the execution status of this line is deduced): QStandardItemModel::setData(index, url, UrlRole); | - |
| 179 | return true; executed: return true;Execution Count:1459 | 1459 |
| 180 | } | - |
| 181 | return QStandardItemModel::setData(index, value, role); executed: return QStandardItemModel::setData(index, value, role);Execution Count:1238 | 1238 |
| 182 | } | - |
| 183 | | - |
| 184 | void QUrlModel::setUrl(const QModelIndex &index, const QUrl &url, const QModelIndex &dirIndex) | - |
| 185 | { | - |
| 186 | setData(index, url, UrlRole); executed (the execution status of this line is deduced): setData(index, url, UrlRole); | - |
| 187 | if (url.path().isEmpty()) { evaluated: url.path().isEmpty()| yes Evaluation Count:298 | yes Evaluation Count:642 |
| 298-642 |
| 188 | setData(index, fileSystemModel->myComputer()); executed (the execution status of this line is deduced): setData(index, fileSystemModel->myComputer()); | - |
| 189 | setData(index, fileSystemModel->myComputer(Qt::DecorationRole), Qt::DecorationRole); executed (the execution status of this line is deduced): setData(index, fileSystemModel->myComputer(Qt::DecorationRole), Qt::DecorationRole); | - |
| 190 | } else { executed: }Execution Count:298 | 298 |
| 191 | QString newName; executed (the execution status of this line is deduced): QString newName; | - |
| 192 | if (showFullPath) { evaluated: showFullPath| yes Evaluation Count:345 | yes Evaluation Count:297 |
| 297-345 |
| 193 | //On windows the popup display the "C:\", convert to nativeSeparators | - |
| 194 | newName = QDir::toNativeSeparators(dirIndex.data(QFileSystemModel::FilePathRole).toString()); executed (the execution status of this line is deduced): newName = QDir::toNativeSeparators(dirIndex.data(QFileSystemModel::FilePathRole).toString()); | - |
| 195 | } else { executed: }Execution Count:345 | 345 |
| 196 | newName = dirIndex.data().toString(); executed (the execution status of this line is deduced): newName = dirIndex.data().toString(); | - |
| 197 | } executed: }Execution Count:297 | 297 |
| 198 | | - |
| 199 | QIcon newIcon = qvariant_cast<QIcon>(dirIndex.data(Qt::DecorationRole)); executed (the execution status of this line is deduced): QIcon newIcon = qvariant_cast<QIcon>(dirIndex.data(Qt::DecorationRole)); | - |
| 200 | if (!dirIndex.isValid()) { partially evaluated: !dirIndex.isValid()| no Evaluation Count:0 | yes Evaluation Count:642 |
| 0-642 |
| 201 | newIcon = fileSystemModel->iconProvider()->icon(QFileIconProvider::Folder); never executed (the execution status of this line is deduced): newIcon = fileSystemModel->iconProvider()->icon(QFileIconProvider::Folder); | - |
| 202 | newName = QFileInfo(url.toLocalFile()).fileName(); never executed (the execution status of this line is deduced): newName = QFileInfo(url.toLocalFile()).fileName(); | - |
| 203 | if (!invalidUrls.contains(url)) never evaluated: !invalidUrls.contains(url) | 0 |
| 204 | invalidUrls.append(url); never executed: invalidUrls.append(url); | 0 |
| 205 | //The bookmark is invalid then we set to false the EnabledRole | - |
| 206 | setData(index, false, EnabledRole); never executed (the execution status of this line is deduced): setData(index, false, EnabledRole); | - |
| 207 | } else { | 0 |
| 208 | //The bookmark is valid then we set to true the EnabledRole | - |
| 209 | setData(index, true, EnabledRole); executed (the execution status of this line is deduced): setData(index, true, EnabledRole); | - |
| 210 | } executed: }Execution Count:642 | 642 |
| 211 | | - |
| 212 | // Make sure that we have at least 32x32 images | - |
| 213 | const QSize size = newIcon.actualSize(QSize(32,32)); executed (the execution status of this line is deduced): const QSize size = newIcon.actualSize(QSize(32,32)); | - |
| 214 | if (size.width() < 32) { partially evaluated: size.width() < 32| no Evaluation Count:0 | yes Evaluation Count:642 |
| 0-642 |
| 215 | QPixmap smallPixmap = newIcon.pixmap(QSize(32, 32)); never executed (the execution status of this line is deduced): QPixmap smallPixmap = newIcon.pixmap(QSize(32, 32)); | - |
| 216 | newIcon.addPixmap(smallPixmap.scaledToWidth(32, Qt::SmoothTransformation)); never executed (the execution status of this line is deduced): newIcon.addPixmap(smallPixmap.scaledToWidth(32, Qt::SmoothTransformation)); | - |
| 217 | } | 0 |
| 218 | | - |
| 219 | if (index.data().toString() != newName) partially evaluated: index.data().toString() != newName| no Evaluation Count:0 | yes Evaluation Count:642 |
| 0-642 |
| 220 | setData(index, newName); never executed: setData(index, newName); | 0 |
| 221 | QIcon oldIcon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole)); executed (the execution status of this line is deduced): QIcon oldIcon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole)); | - |
| 222 | if (oldIcon.cacheKey() != newIcon.cacheKey()) partially evaluated: oldIcon.cacheKey() != newIcon.cacheKey()| no Evaluation Count:0 | yes Evaluation Count:642 |
| 0-642 |
| 223 | setData(index, newIcon, Qt::DecorationRole); never executed: setData(index, newIcon, Qt::DecorationRole); | 0 |
| 224 | } executed: }Execution Count:642 | 642 |
| 225 | } | - |
| 226 | | - |
| 227 | void QUrlModel::setUrls(const QList<QUrl> &list) | - |
| 228 | { | - |
| 229 | removeRows(0, rowCount()); executed (the execution status of this line is deduced): removeRows(0, rowCount()); | - |
| 230 | invalidUrls.clear(); executed (the execution status of this line is deduced): invalidUrls.clear(); | - |
| 231 | watching.clear(); executed (the execution status of this line is deduced): watching.clear(); | - |
| 232 | addUrls(list, 0); executed (the execution status of this line is deduced): addUrls(list, 0); | - |
| 233 | } executed: }Execution Count:643 | 643 |
| 234 | | - |
| 235 | /*! | - |
| 236 | Add urls \a list into the list at \a row. If move then movie | - |
| 237 | existing ones to row. | - |
| 238 | | - |
| 239 | \sa dropMimeData() | - |
| 240 | */ | - |
| 241 | void QUrlModel::addUrls(const QList<QUrl> &list, int row, bool move) | - |
| 242 | { | - |
| 243 | if (row == -1) partially evaluated: row == -1| no Evaluation Count:0 | yes Evaluation Count:643 |
| 0-643 |
| 244 | row = rowCount(); never executed: row = rowCount(); | 0 |
| 245 | row = qMin(row, rowCount()); executed (the execution status of this line is deduced): row = qMin(row, rowCount()); | - |
| 246 | for (int i = list.count() - 1; i >= 0; --i) { evaluated: i >= 0| yes Evaluation Count:940 | yes Evaluation Count:643 |
| 643-940 |
| 247 | QUrl url = list.at(i); executed (the execution status of this line is deduced): QUrl url = list.at(i); | - |
| 248 | if (!url.isValid() || url.scheme() != QLatin1String("file")) partially evaluated: !url.isValid()| no Evaluation Count:0 | yes Evaluation Count:940 |
partially evaluated: url.scheme() != QLatin1String("file")| no Evaluation Count:0 | yes Evaluation Count:940 |
| 0-940 |
| 249 | continue; never executed: continue; | 0 |
| 250 | //this makes sure the url is clean | - |
| 251 | const QString cleanUrl = QDir::cleanPath(url.toLocalFile()); executed (the execution status of this line is deduced): const QString cleanUrl = QDir::cleanPath(url.toLocalFile()); | - |
| 252 | url = QUrl::fromLocalFile(cleanUrl); executed (the execution status of this line is deduced): url = QUrl::fromLocalFile(cleanUrl); | - |
| 253 | | - |
| 254 | for (int j = 0; move && j < rowCount(); ++j) { partially evaluated: move| yes Evaluation Count:1237 | no Evaluation Count:0 |
evaluated: j < rowCount()| yes Evaluation Count:297 | yes Evaluation Count:940 |
| 0-1237 |
| 255 | QString local = index(j, 0).data(UrlRole).toUrl().toLocalFile(); executed (the execution status of this line is deduced): QString local = index(j, 0).data(UrlRole).toUrl().toLocalFile(); | - |
| 256 | #if defined(Q_OS_WIN) | - |
| 257 | if (index(j, 0).data(UrlRole).toUrl().toLocalFile().toLower() == cleanUrl.toLower()) { | - |
| 258 | #else | - |
| 259 | if (index(j, 0).data(UrlRole).toUrl().toLocalFile() == cleanUrl) { partially evaluated: index(j, 0).data(UrlRole).toUrl().toLocalFile() == cleanUrl| no Evaluation Count:0 | yes Evaluation Count:297 |
| 0-297 |
| 260 | #endif | - |
| 261 | removeRow(j); never executed (the execution status of this line is deduced): removeRow(j); | - |
| 262 | if (j <= row) never evaluated: j <= row | 0 |
| 263 | row--; | 0 |
| 264 | break; | 0 |
| 265 | } | - |
| 266 | } executed: }Execution Count:297 | 297 |
| 267 | row = qMax(row, 0); executed (the execution status of this line is deduced): row = qMax(row, 0); | - |
| 268 | QModelIndex idx = fileSystemModel->index(cleanUrl); executed (the execution status of this line is deduced): QModelIndex idx = fileSystemModel->index(cleanUrl); | - |
| 269 | if (!fileSystemModel->isDir(idx)) partially evaluated: !fileSystemModel->isDir(idx)| no Evaluation Count:0 | yes Evaluation Count:940 |
| 0-940 |
| 270 | continue; never executed: continue; | 0 |
| 271 | insertRows(row, 1); executed (the execution status of this line is deduced): insertRows(row, 1); | - |
| 272 | setUrl(index(row, 0), url, idx); executed (the execution status of this line is deduced): setUrl(index(row, 0), url, idx); | - |
| 273 | watching.append(qMakePair(idx, cleanUrl)); executed (the execution status of this line is deduced): watching.append(qMakePair(idx, cleanUrl)); | - |
| 274 | } executed: }Execution Count:940 | 940 |
| 275 | } executed: }Execution Count:643 | 643 |
| 276 | | - |
| 277 | /*! | - |
| 278 | Return the complete list of urls in a QList. | - |
| 279 | */ | - |
| 280 | QList<QUrl> QUrlModel::urls() const | - |
| 281 | { | - |
| 282 | QList<QUrl> list; executed (the execution status of this line is deduced): QList<QUrl> list; | - |
| 283 | for (int i = 0; i < rowCount(); ++i) evaluated: i < rowCount()| yes Evaluation Count:384 | yes Evaluation Count:192 |
| 192-384 |
| 284 | list.append(data(index(i, 0), UrlRole).toUrl()); executed: list.append(data(index(i, 0), UrlRole).toUrl());Execution Count:384 | 384 |
| 285 | return list; executed: return list;Execution Count:192 | 192 |
| 286 | } | - |
| 287 | | - |
| 288 | /*! | - |
| 289 | QFileSystemModel to get index's from, clears existing rows | - |
| 290 | */ | - |
| 291 | void QUrlModel::setFileSystemModel(QFileSystemModel *model) | - |
| 292 | { | - |
| 293 | if (model == fileSystemModel) partially evaluated: model == fileSystemModel| no Evaluation Count:0 | yes Evaluation Count:378 |
| 0-378 |
| 294 | return; | 0 |
| 295 | if (fileSystemModel != 0) { partially evaluated: fileSystemModel != 0| no Evaluation Count:0 | yes Evaluation Count:378 |
| 0-378 |
| 296 | disconnect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), never executed (the execution status of this line is deduced): disconnect(model, "2""dataChanged(QModelIndex,QModelIndex)", | - |
| 297 | this, SLOT(dataChanged(QModelIndex,QModelIndex))); never executed (the execution status of this line is deduced): this, "1""dataChanged(QModelIndex,QModelIndex)"); | - |
| 298 | disconnect(model, SIGNAL(layoutChanged()), never executed (the execution status of this line is deduced): disconnect(model, "2""layoutChanged()", | - |
| 299 | this, SLOT(layoutChanged())); never executed (the execution status of this line is deduced): this, "1""layoutChanged()"); | - |
| 300 | disconnect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), never executed (the execution status of this line is deduced): disconnect(model, "2""rowsRemoved(QModelIndex,int,int)", | - |
| 301 | this, SLOT(layoutChanged())); never executed (the execution status of this line is deduced): this, "1""layoutChanged()"); | - |
| 302 | } | 0 |
| 303 | fileSystemModel = model; executed (the execution status of this line is deduced): fileSystemModel = model; | - |
| 304 | if (fileSystemModel != 0) { partially evaluated: fileSystemModel != 0| yes Evaluation Count:378 | no Evaluation Count:0 |
| 0-378 |
| 305 | connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), executed (the execution status of this line is deduced): connect(model, "2""dataChanged(QModelIndex,QModelIndex)", | - |
| 306 | this, SLOT(dataChanged(QModelIndex,QModelIndex))); executed (the execution status of this line is deduced): this, "1""dataChanged(QModelIndex,QModelIndex)"); | - |
| 307 | connect(model, SIGNAL(layoutChanged()), executed (the execution status of this line is deduced): connect(model, "2""layoutChanged()", | - |
| 308 | this, SLOT(layoutChanged())); executed (the execution status of this line is deduced): this, "1""layoutChanged()"); | - |
| 309 | connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), executed (the execution status of this line is deduced): connect(model, "2""rowsRemoved(QModelIndex,int,int)", | - |
| 310 | this, SLOT(layoutChanged())); executed (the execution status of this line is deduced): this, "1""layoutChanged()"); | - |
| 311 | } executed: }Execution Count:378 | 378 |
| 312 | clear(); executed (the execution status of this line is deduced): clear(); | - |
| 313 | insertColumns(0, 1); executed (the execution status of this line is deduced): insertColumns(0, 1); | - |
| 314 | } executed: }Execution Count:378 | 378 |
| 315 | | - |
| 316 | /* | - |
| 317 | If one of the index's we are watching has changed update our internal data | - |
| 318 | */ | - |
| 319 | void QUrlModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) | - |
| 320 | { | - |
| 321 | QModelIndex parent = topLeft.parent(); executed (the execution status of this line is deduced): QModelIndex parent = topLeft.parent(); | - |
| 322 | for (int i = 0; i < watching.count(); ++i) { evaluated: i < watching.count()| yes Evaluation Count:90 | yes Evaluation Count:60 |
| 60-90 |
| 323 | QModelIndex index = watching.at(i).first; executed (the execution status of this line is deduced): QModelIndex index = watching.at(i).first; | - |
| 324 | if (index.model() && topLeft.model()) { evaluated: index.model()| yes Evaluation Count:59 | yes Evaluation Count:31 |
partially evaluated: topLeft.model()| yes Evaluation Count:59 | no Evaluation Count:0 |
| 0-59 |
| 325 | Q_ASSERT(index.model() == topLeft.model()); executed (the execution status of this line is deduced): qt_noop(); | - |
| 326 | } executed: }Execution Count:59 | 59 |
| 327 | if ( index.row() >= topLeft.row() evaluated: index.row() >= topLeft.row()| yes Evaluation Count:55 | yes Evaluation Count:35 |
| 35-55 |
| 328 | && index.row() <= bottomRight.row() evaluated: index.row() <= bottomRight.row()| yes Evaluation Count:48 | yes Evaluation Count:7 |
| 7-48 |
| 329 | && index.column() >= topLeft.column() partially evaluated: index.column() >= topLeft.column()| yes Evaluation Count:48 | no Evaluation Count:0 |
| 0-48 |
| 330 | && index.column() <= bottomRight.column() partially evaluated: index.column() <= bottomRight.column()| yes Evaluation Count:48 | no Evaluation Count:0 |
| 0-48 |
| 331 | && index.parent() == parent) { partially evaluated: index.parent() == parent| no Evaluation Count:0 | yes Evaluation Count:48 |
| 0-48 |
| 332 | changed(watching.at(i).second); never executed (the execution status of this line is deduced): changed(watching.at(i).second); | - |
| 333 | } | 0 |
| 334 | } executed: }Execution Count:90 | 90 |
| 335 | } executed: }Execution Count:60 | 60 |
| 336 | | - |
| 337 | /*! | - |
| 338 | Re-get all of our data, anything could have changed! | - |
| 339 | */ | - |
| 340 | void QUrlModel::layoutChanged() | - |
| 341 | { | - |
| 342 | QStringList paths; executed (the execution status of this line is deduced): QStringList paths; | - |
| 343 | for (int i = 0; i < watching.count(); ++i) evaluated: i < watching.count()| yes Evaluation Count:873 | yes Evaluation Count:708 |
| 708-873 |
| 344 | paths.append(watching.at(i).second); executed: paths.append(watching.at(i).second);Execution Count:873 | 873 |
| 345 | watching.clear(); executed (the execution status of this line is deduced): watching.clear(); | - |
| 346 | for (int i = 0; i < paths.count(); ++i) { evaluated: i < paths.count()| yes Evaluation Count:873 | yes Evaluation Count:708 |
| 708-873 |
| 347 | QString path = paths.at(i); executed (the execution status of this line is deduced): QString path = paths.at(i); | - |
| 348 | QModelIndex newIndex = fileSystemModel->index(path); executed (the execution status of this line is deduced): QModelIndex newIndex = fileSystemModel->index(path); | - |
| 349 | watching.append(QPair<QModelIndex, QString>(newIndex, path)); executed (the execution status of this line is deduced): watching.append(QPair<QModelIndex, QString>(newIndex, path)); | - |
| 350 | if (newIndex.isValid()) evaluated: newIndex.isValid()| yes Evaluation Count:519 | yes Evaluation Count:354 |
| 354-519 |
| 351 | changed(path); executed: changed(path);Execution Count:519 | 519 |
| 352 | } executed: }Execution Count:873 | 873 |
| 353 | } executed: }Execution Count:708 | 708 |
| 354 | | - |
| 355 | /*! | - |
| 356 | The following path changed data update our copy of that data | - |
| 357 | | - |
| 358 | \sa layoutChanged(), dataChanged() | - |
| 359 | */ | - |
| 360 | void QUrlModel::changed(const QString &path) | - |
| 361 | { | - |
| 362 | for (int i = 0; i < rowCount(); ++i) { evaluated: i < rowCount()| yes Evaluation Count:873 | yes Evaluation Count:519 |
| 519-873 |
| 363 | QModelIndex idx = index(i, 0); executed (the execution status of this line is deduced): QModelIndex idx = index(i, 0); | - |
| 364 | if (idx.data(UrlRole).toUrl().toLocalFile() == path) { evaluated: idx.data(UrlRole).toUrl().toLocalFile() == path| yes Evaluation Count:519 | yes Evaluation Count:354 |
| 354-519 |
| 365 | setData(idx, idx.data(UrlRole).toUrl()); executed (the execution status of this line is deduced): setData(idx, idx.data(UrlRole).toUrl()); | - |
| 366 | } executed: }Execution Count:519 | 519 |
| 367 | } executed: }Execution Count:873 | 873 |
| 368 | } executed: }Execution Count:519 | 519 |
| 369 | | - |
| 370 | QSidebar::QSidebar(QWidget *parent) : QListView(parent) | - |
| 371 | { | - |
| 372 | } executed: }Execution Count:189 | 189 |
| 373 | | - |
| 374 | void QSidebar::setModelAndUrls(QFileSystemModel *model, const QList<QUrl> &newUrls) | - |
| 375 | { | - |
| 376 | // ### TODO make icon size dynamic | - |
| 377 | setIconSize(QSize(24,24)); executed (the execution status of this line is deduced): setIconSize(QSize(24,24)); | - |
| 378 | setUniformItemSizes(true); executed (the execution status of this line is deduced): setUniformItemSizes(true); | - |
| 379 | urlModel = new QUrlModel(this); executed (the execution status of this line is deduced): urlModel = new QUrlModel(this); | - |
| 380 | urlModel->setFileSystemModel(model); executed (the execution status of this line is deduced): urlModel->setFileSystemModel(model); | - |
| 381 | setModel(urlModel); executed (the execution status of this line is deduced): setModel(urlModel); | - |
| 382 | setItemDelegate(new QSideBarDelegate(this)); executed (the execution status of this line is deduced): setItemDelegate(new QSideBarDelegate(this)); | - |
| 383 | | - |
| 384 | connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), executed (the execution status of this line is deduced): connect(selectionModel(), "2""currentChanged(QModelIndex,QModelIndex)", | - |
| 385 | this, SLOT(clicked(QModelIndex))); executed (the execution status of this line is deduced): this, "1""clicked(QModelIndex)"); | - |
| 386 | #ifndef QT_NO_DRAGANDDROP | - |
| 387 | setDragDropMode(QAbstractItemView::DragDrop); executed (the execution status of this line is deduced): setDragDropMode(QAbstractItemView::DragDrop); | - |
| 388 | #endif | - |
| 389 | setContextMenuPolicy(Qt::CustomContextMenu); executed (the execution status of this line is deduced): setContextMenuPolicy(Qt::CustomContextMenu); | - |
| 390 | connect(this, SIGNAL(customContextMenuRequested(QPoint)), executed (the execution status of this line is deduced): connect(this, "2""customContextMenuRequested(QPoint)", | - |
| 391 | this, SLOT(showContextMenu(QPoint))); executed (the execution status of this line is deduced): this, "1""showContextMenu(QPoint)"); | - |
| 392 | urlModel->setUrls(newUrls); executed (the execution status of this line is deduced): urlModel->setUrls(newUrls); | - |
| 393 | setCurrentIndex(this->model()->index(0,0)); executed (the execution status of this line is deduced): setCurrentIndex(this->model()->index(0,0)); | - |
| 394 | } executed: }Execution Count:189 | 189 |
| 395 | | - |
| 396 | QSidebar::~QSidebar() | - |
| 397 | { | - |
| 398 | } | - |
| 399 | | - |
| 400 | #ifndef QT_NO_DRAGANDDROP | - |
| 401 | void QSidebar::dragEnterEvent(QDragEnterEvent *event) | - |
| 402 | { | - |
| 403 | if (urlModel->canDrop(event)) never evaluated: urlModel->canDrop(event) | 0 |
| 404 | QListView::dragEnterEvent(event); never executed: QListView::dragEnterEvent(event); | 0 |
| 405 | } | 0 |
| 406 | #endif // QT_NO_DRAGANDDROP | - |
| 407 | | - |
| 408 | QSize QSidebar::sizeHint() const | - |
| 409 | { | - |
| 410 | if (model()) evaluated: model()| yes Evaluation Count:1612 | yes Evaluation Count:567 |
| 567-1612 |
| 411 | 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 |
| 412 | return QListView::sizeHint(); executed: return QListView::sizeHint();Execution Count:567 | 567 |
| 413 | } | - |
| 414 | | - |
| 415 | void QSidebar::selectUrl(const QUrl &url) | - |
| 416 | { | - |
| 417 | disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), executed (the execution status of this line is deduced): disconnect(selectionModel(), "2""currentChanged(QModelIndex,QModelIndex)", | - |
| 418 | this, SLOT(clicked(QModelIndex))); executed (the execution status of this line is deduced): this, "1""clicked(QModelIndex)"); | - |
| 419 | | - |
| 420 | selectionModel()->clear(); executed (the execution status of this line is deduced): selectionModel()->clear(); | - |
| 421 | for (int i = 0; i < model()->rowCount(); ++i) { evaluated: i < model()->rowCount()| yes Evaluation Count:660 | yes Evaluation Count:214 |
| 214-660 |
| 422 | if (model()->index(i, 0).data(QUrlModel::UrlRole).toUrl() == url) { evaluated: model()->index(i, 0).data(QUrlModel::UrlRole).toUrl() == url| yes Evaluation Count:211 | yes Evaluation Count:449 |
| 211-449 |
| 423 | selectionModel()->select(model()->index(i, 0), QItemSelectionModel::Select); executed (the execution status of this line is deduced): selectionModel()->select(model()->index(i, 0), QItemSelectionModel::Select); | - |
| 424 | break; executed: break;Execution Count:211 | 211 |
| 425 | } | - |
| 426 | } executed: }Execution Count:449 | 449 |
| 427 | | - |
| 428 | connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), executed (the execution status of this line is deduced): connect(selectionModel(), "2""currentChanged(QModelIndex,QModelIndex)", | - |
| 429 | this, SLOT(clicked(QModelIndex))); executed (the execution status of this line is deduced): this, "1""clicked(QModelIndex)"); | - |
| 430 | } executed: }Execution Count:425 | 425 |
| 431 | | - |
| 432 | #ifndef QT_NO_MENU | - |
| 433 | /*! | - |
| 434 | \internal | - |
| 435 | | - |
| 436 | \sa removeEntry() | - |
| 437 | */ | - |
| 438 | void QSidebar::showContextMenu(const QPoint &position) | - |
| 439 | { | - |
| 440 | QList<QAction *> actions; never executed (the execution status of this line is deduced): QList<QAction *> actions; | - |
| 441 | if (indexAt(position).isValid()) { never evaluated: indexAt(position).isValid() | 0 |
| 442 | QAction *action = new QAction(QFileDialog::tr("Remove"), this); never executed (the execution status of this line is deduced): QAction *action = new QAction(QFileDialog::tr("Remove"), this); | - |
| 443 | if (indexAt(position).data(QUrlModel::UrlRole).toUrl().path().isEmpty()) never evaluated: indexAt(position).data(QUrlModel::UrlRole).toUrl().path().isEmpty() | 0 |
| 444 | action->setEnabled(false); never executed: action->setEnabled(false); | 0 |
| 445 | connect(action, SIGNAL(triggered()), this, SLOT(removeEntry())); never executed (the execution status of this line is deduced): connect(action, "2""triggered()", this, "1""removeEntry()"); | - |
| 446 | actions.append(action); never executed (the execution status of this line is deduced): actions.append(action); | - |
| 447 | } | 0 |
| 448 | if (actions.count() > 0) never evaluated: actions.count() > 0 | 0 |
| 449 | QMenu::exec(actions, mapToGlobal(position)); never executed: QMenu::exec(actions, mapToGlobal(position)); | 0 |
| 450 | } | 0 |
| 451 | #endif // QT_NO_MENU | - |
| 452 | | - |
| 453 | /*! | - |
| 454 | \internal | - |
| 455 | | - |
| 456 | \sa showContextMenu() | - |
| 457 | */ | - |
| 458 | void QSidebar::removeEntry() | - |
| 459 | { | - |
| 460 | QList<QModelIndex> idxs = selectionModel()->selectedIndexes(); never executed (the execution status of this line is deduced): QList<QModelIndex> idxs = selectionModel()->selectedIndexes(); | - |
| 461 | QList<QPersistentModelIndex> indexes; never executed (the execution status of this line is deduced): QList<QPersistentModelIndex> indexes; | - |
| 462 | for (int i = 0; i < idxs.count(); i++) never evaluated: i < idxs.count() | 0 |
| 463 | indexes.append(idxs.at(i)); never executed: indexes.append(idxs.at(i)); | 0 |
| 464 | | - |
| 465 | for (int i = 0; i < indexes.count(); ++i) never evaluated: i < indexes.count() | 0 |
| 466 | if (!indexes.at(i).data(QUrlModel::UrlRole).toUrl().path().isEmpty()) never evaluated: !indexes.at(i).data(QUrlModel::UrlRole).toUrl().path().isEmpty() | 0 |
| 467 | model()->removeRow(indexes.at(i).row()); never executed: model()->removeRow(indexes.at(i).row()); | 0 |
| 468 | } | 0 |
| 469 | | - |
| 470 | /*! | - |
| 471 | \internal | - |
| 472 | | - |
| 473 | \sa goToUrl() | - |
| 474 | */ | - |
| 475 | void QSidebar::clicked(const QModelIndex &index) | - |
| 476 | { | - |
| 477 | QUrl url = model()->index(index.row(), 0).data(QUrlModel::UrlRole).toUrl(); executed (the execution status of this line is deduced): QUrl url = model()->index(index.row(), 0).data(QUrlModel::UrlRole).toUrl(); | - |
| 478 | emit goToUrl(url); executed (the execution status of this line is deduced): goToUrl(url); | - |
| 479 | selectUrl(url); executed (the execution status of this line is deduced): selectUrl(url); | - |
| 480 | } executed: }Execution Count:189 | 189 |
| 481 | | - |
| 482 | /*! | - |
| 483 | \reimp | - |
| 484 | Don't automatically select something | - |
| 485 | */ | - |
| 486 | void QSidebar::focusInEvent(QFocusEvent *event) | - |
| 487 | { | - |
| 488 | QAbstractScrollArea::focusInEvent(event); never executed (the execution status of this line is deduced): QAbstractScrollArea::focusInEvent(event); | - |
| 489 | viewport()->update(); never executed (the execution status of this line is deduced): viewport()->update(); | - |
| 490 | } | 0 |
| 491 | | - |
| 492 | /*! | - |
| 493 | \reimp | - |
| 494 | */ | - |
| 495 | bool QSidebar::event(QEvent * event) | - |
| 496 | { | - |
| 497 | if (event->type() == QEvent::KeyRelease) { partially evaluated: event->type() == QEvent::KeyRelease| no Evaluation Count:0 | yes Evaluation Count:2093 |
| 0-2093 |
| 498 | QKeyEvent* ke = (QKeyEvent*) event; never executed (the execution status of this line is deduced): QKeyEvent* ke = (QKeyEvent*) event; | - |
| 499 | if (ke->key() == Qt::Key_Delete) { never evaluated: ke->key() == Qt::Key_Delete | 0 |
| 500 | removeEntry(); never executed (the execution status of this line is deduced): removeEntry(); | - |
| 501 | return true; never executed: return true; | 0 |
| 502 | } | - |
| 503 | } | 0 |
| 504 | return QListView::event(event); executed: return QListView::event(event);Execution Count:2093 | 2093 |
| 505 | } | - |
| 506 | | - |
| 507 | QT_END_NAMESPACE | - |
| 508 | | - |
| 509 | #endif | - |
| 510 | | - |
| | |