summaryrefslogtreecommitdiffstats
path: root/src/gui/dialogs/qsidebar.cpp
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2009-04-21 08:17:56 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2009-04-21 08:21:23 (GMT)
commitb108e0479c6ec872ab767b8b81420b28ca1886cf (patch)
treef61d0d4b9147d87debd8685a4b76ea7674493e57 /src/gui/dialogs/qsidebar.cpp
parent292a37301950a64f211e3a2909ff64884b73e1cc (diff)
downloadQt-b108e0479c6ec872ab767b8b81420b28ca1886cf.zip
Qt-b108e0479c6ec872ab767b8b81420b28ca1886cf.tar.gz
Qt-b108e0479c6ec872ab767b8b81420b28ca1886cf.tar.bz2
There is no way to delete a invalid entry in the sidebar of QFileDialog.
We can't remove an item in the sidebar if the bookmark is not valid (i.e. link to a non existing directory). ItemViews doesn't allow you to have disabled items and to select them at the same time, so i have implemented a delegate that paint in gray if the bookmark is invalid. So you can click on it and delete it. Task-number: 251341 Reviewed-by: jasplin
Diffstat (limited to 'src/gui/dialogs/qsidebar.cpp')
-rw-r--r--src/gui/dialogs/qsidebar.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/gui/dialogs/qsidebar.cpp b/src/gui/dialogs/qsidebar.cpp
index 1bd2b7d..bfdb37e 100644
--- a/src/gui/dialogs/qsidebar.cpp
+++ b/src/gui/dialogs/qsidebar.cpp
@@ -55,6 +55,18 @@
QT_BEGIN_NAMESPACE
+void QSideBarDelegate::initStyleOption(QStyleOptionViewItem *option,
+ const QModelIndex &index) const
+{
+ QStyledItemDelegate::initStyleOption(option,index);
+ QVariant value = index.data(QUrlModel::EnabledRole);
+ if (value.isValid()) {
+ //If the bookmark/entry is not enabled then we paint it in gray
+ if (!qvariant_cast<bool>(value))
+ option->state &= ~QStyle::State_Enabled;
+ }
+}
+
/*!
QUrlModel lets you have indexes from a QFileSystemModel to a list. When QFileSystemModel
changes them QUrlModel will automatically update.
@@ -88,9 +100,6 @@ Qt::ItemFlags QUrlModel::flags(const QModelIndex &index) const
if (index.data(Qt::DecorationRole).isNull())
flags &= ~Qt::ItemIsEnabled;
- if (invalidUrls.contains(index.data(UrlRole).toUrl()))
- flags &= ~Qt::ItemIsEnabled;
-
return flags;
}
@@ -193,6 +202,11 @@ void QUrlModel::setUrl(const QModelIndex &index, const QUrl &url, const QModelIn
newName = QFileInfo(url.toLocalFile()).fileName();
if (!invalidUrls.contains(url))
invalidUrls.append(url);
+ //The bookmark is invalid then we set to false the EnabledRole
+ setData(index, false, EnabledRole);
+ } else {
+ //The bookmark is valid then we set to true the EnabledRole
+ setData(index, true, EnabledRole);
}
// Make sure that we have at least 32x32 images
@@ -356,6 +370,7 @@ void QSidebar::init(QFileSystemModel *model, const QList<QUrl> &newUrls)
urlModel = new QUrlModel(this);
urlModel->setFileSystemModel(model);
setModel(urlModel);
+ setItemDelegate(new QSideBarDelegate(this));
connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(clicked(const QModelIndex &)));