mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
streamline the filter combobox code
- int m_filterType -> ProxyModel::FilterType m_filterType - ProxyModel::filterModeFromInt(int) -> static_cast<ProxyModel::FilterType>(int) - int -> QVariant<ProxyModel::FilterType> in the config UI - selectUnselectAll() -> two separate methods; eliminate sender() call This also fixes filterChanged() and configAccepted() wrt this config key. Use the actual filter mode value instead of the combobox index which is error-prone in case the order of the items in the combobox changes. BUG:317323 FIXED_IN:4.10.2
This commit is contained in:
parent
d71127de44
commit
050a8c33aa
5 changed files with 56 additions and 72 deletions
|
@ -87,6 +87,7 @@
|
|||
K_EXPORT_PLASMA_APPLET(folderview, FolderView)
|
||||
|
||||
Q_DECLARE_METATYPE(Qt::SortOrder)
|
||||
Q_DECLARE_METATYPE(ProxyModel::FilterMode)
|
||||
|
||||
MimeModel::MimeModel(QObject *parent)
|
||||
: QStringListModel(parent)
|
||||
|
@ -387,10 +388,9 @@ void FolderView::init()
|
|||
m_sortColumn = cg.readEntry("sortColumn", int(KDirModel::Name));
|
||||
m_sortOrder = sortOrderStringToEnum(cg.readEntry("sortOrder", "ascending"));
|
||||
m_filterFiles = cg.readEntry("filterFiles", "*");
|
||||
m_filterType = cg.readEntry("filter", 0);
|
||||
m_filterType = static_cast<ProxyModel::FilterMode>(cg.readEntry("filter", 0));
|
||||
m_filterFilesMimeList = cg.readEntry("mimeFilter", QStringList());
|
||||
m_blankLabel = cg.readEntry("blankLabel", false);
|
||||
m_userSelectedShowAllFiles = m_filterType;
|
||||
m_showSelectionMarker = KGlobalSettings::singleClick();
|
||||
|
||||
if (isContainment()) {
|
||||
|
@ -400,7 +400,7 @@ void FolderView::init()
|
|||
}
|
||||
m_flow = static_cast<IconView::Flow>(cg.readEntry("flow", static_cast<int>(m_flow)));
|
||||
|
||||
m_model->setFilterMode(ProxyModel::filterModeFromInt(m_filterType));
|
||||
m_model->setFilterMode(m_filterType);
|
||||
m_model->setMimeTypeFilterList(m_filterFilesMimeList);
|
||||
m_model->setFileNameFilter(m_filterFiles);
|
||||
m_model->setSortDirectoriesFirst(m_sortDirsFirst);
|
||||
|
@ -572,15 +572,13 @@ void FolderView::configChanged()
|
|||
m_flow = static_cast<IconView::Flow>(flow);
|
||||
}
|
||||
|
||||
const int filterType = cg.readEntry("filter", m_filterType);
|
||||
const ProxyModel::FilterMode filterType = static_cast<ProxyModel::FilterMode>(cg.readEntry("filter", static_cast<int>(m_filterType)));
|
||||
if (filterType != m_filterType) {
|
||||
m_filterType = filterType;
|
||||
m_model->setFilterMode(ProxyModel::filterModeFromInt(m_filterType));
|
||||
m_model->setFilterMode(m_filterType);
|
||||
needReload = true;
|
||||
}
|
||||
|
||||
m_userSelectedShowAllFiles = m_filterType;
|
||||
|
||||
const QString filterFiles = cg.readEntry("filterFiles", m_filterFiles);
|
||||
if (filterFiles != m_filterFiles) {
|
||||
m_filterFiles = filterFiles;
|
||||
|
@ -756,6 +754,10 @@ void FolderView::createConfigurationInterface(KConfigDialog *parent)
|
|||
uiDisplay.flowCombo->addItem(i18n("Left to Right, Top to Bottom"), IconView::LeftToRight);
|
||||
uiDisplay.flowCombo->addItem(i18n("Right to Left, Top to Bottom"), IconView::RightToLeft);
|
||||
|
||||
uiFilter.filterCombo->addItem(i18n("Show All Files"), QVariant::fromValue(ProxyModel::NoFilter));
|
||||
uiFilter.filterCombo->addItem(i18n("Show Files Matching"), QVariant::fromValue(ProxyModel::FilterShowMatches));
|
||||
uiFilter.filterCombo->addItem(i18n("Hide Files Matching"), QVariant::fromValue(ProxyModel::FilterHideMatches));
|
||||
|
||||
uiDisplay.alignToGrid->setChecked(m_alignToGrid);
|
||||
uiDisplay.clickToView->setChecked(m_clickToView);
|
||||
uiDisplay.lockInPlace->setChecked(m_iconsLocked);
|
||||
|
@ -779,6 +781,15 @@ void FolderView::createConfigurationInterface(KConfigDialog *parent)
|
|||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < uiFilter.filterCombo->maxCount(); i++) {
|
||||
if (m_filterType == uiFilter.filterCombo->itemData(i).value<ProxyModel::FilterMode>()) {
|
||||
uiFilter.filterCombo->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
filterChanged(uiFilter.filterCombo->currentIndex());
|
||||
|
||||
// Hide the icon arrangement controls when we're not acting as a containment,
|
||||
// since this option doesn't make much sense in the applet.
|
||||
if (!isContainment()) {
|
||||
|
@ -796,25 +807,18 @@ void FolderView::createConfigurationInterface(KConfigDialog *parent)
|
|||
connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
|
||||
connect(uiLocation.showPlace, SIGNAL(toggled(bool)), uiLocation.placesCombo, SLOT(setEnabled(bool)));
|
||||
connect(uiLocation.showCustomFolder, SIGNAL(toggled(bool)), uiLocation.lineEdit, SLOT(setEnabled(bool)));
|
||||
connect(uiFilter.filterType, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged(int)));
|
||||
connect(uiFilter.selectAll, SIGNAL(clicked(bool)), this, SLOT(selectUnselectAll()));
|
||||
connect(uiFilter.deselectAll, SIGNAL(clicked(bool)), this, SLOT(selectUnselectAll()));
|
||||
connect(uiFilter.filterCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged(int)));
|
||||
connect(uiFilter.selectAll, SIGNAL(clicked(bool)), this, SLOT(selectAllMimetypes()));
|
||||
connect(uiFilter.deselectAll, SIGNAL(clicked(bool)), this, SLOT(deselectAllMimeTypes()));
|
||||
connect(uiDisplay.previewsAdvanced, SIGNAL(clicked()), this, SLOT(showPreviewConfigDialog()));
|
||||
connect(uiDisplay.showPreviews, SIGNAL(toggled(bool)), uiDisplay.previewsAdvanced, SLOT(setEnabled(bool)));
|
||||
|
||||
KConfigGroup cg = config();
|
||||
const int filter = cg.readEntry("filter", 0);
|
||||
uiFilter.filterType->setCurrentIndex(filter);
|
||||
filterChanged(filter);
|
||||
|
||||
QStringList selectedItems = cg.readEntry("mimeFilter", QStringList());
|
||||
|
||||
if (selectedItems.count()) {
|
||||
if (m_filterFilesMimeList.count()) {
|
||||
for (int i = 0; i < pMimeModel->rowCount(); i++) {
|
||||
const QModelIndex index = pMimeModel->index(i, 0);
|
||||
const KMimeType *mime = static_cast<KMimeType*>(pMimeModel->mapToSource(index).internalPointer());
|
||||
if (mime && selectedItems.contains(mime->name())) {
|
||||
selectedItems.removeAll(mime->name());
|
||||
if (mime && m_filterFilesMimeList.contains(mime->name())) {
|
||||
m_filterFilesMimeList.removeAll(mime->name());
|
||||
uiFilter.filterFilesList->model()->setData(index, Qt::Checked, Qt::CheckStateRole);
|
||||
}
|
||||
}
|
||||
|
@ -832,7 +836,7 @@ void FolderView::createConfigurationInterface(KConfigDialog *parent)
|
|||
connect(uiDisplay.colorButton, SIGNAL(changed(QColor)), parent, SLOT(settingsModified()));
|
||||
connect(uiDisplay.drawShadows, SIGNAL(toggled(bool)), parent, SLOT(settingsModified()));
|
||||
|
||||
connect(uiFilter.filterType, SIGNAL(currentIndexChanged(int)), parent, SLOT(settingsModified()));
|
||||
connect(uiFilter.filterCombo, SIGNAL(currentIndexChanged(int)), parent, SLOT(settingsModified()));
|
||||
connect(uiFilter.filterFilesPattern, SIGNAL(textChanged(QString)), parent, SLOT(settingsModified()));
|
||||
connect(uiFilter.filterFilesList->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), parent, SLOT(settingsModified()));
|
||||
|
||||
|
@ -904,7 +908,10 @@ void FolderView::configAccepted()
|
|||
|
||||
cg.writeEntry("url", url);
|
||||
cg.writeEntry("filterFiles", uiFilter.filterFilesPattern->text());
|
||||
cg.writeEntry("filter", uiFilter.filterType->currentIndex());
|
||||
|
||||
const ProxyModel::FilterMode filterMode =
|
||||
uiFilter.filterCombo->itemData(uiFilter.filterCombo->currentIndex()).value<ProxyModel::FilterMode>();
|
||||
cg.writeEntry("filter", static_cast<int>(filterMode));
|
||||
|
||||
// Now, we have to iterate over all items (not only the filtered ones). For that reason we have
|
||||
// to ask the source model, not the proxy model.
|
||||
|
@ -1849,22 +1856,31 @@ void FolderView::updateSortActionsState()
|
|||
|
||||
void FolderView::filterChanged(int index)
|
||||
{
|
||||
uiFilter.filterFilesPattern->setEnabled(index != 0);
|
||||
uiFilter.searchMimetype->setEnabled(index != 0);
|
||||
uiFilter.filterFilesList->setEnabled(index != 0);
|
||||
uiFilter.selectAll->setEnabled(index != 0);
|
||||
uiFilter.deselectAll->setEnabled(index != 0);
|
||||
if ((index != 0) && (m_userSelectedShowAllFiles == 0)) {
|
||||
for (int i = 0; i < uiFilter.filterFilesList->model()->rowCount(); i++) {
|
||||
const QModelIndex index = uiFilter.filterFilesList->model()->index(i, 0);
|
||||
uiFilter.filterFilesList->model()->setData(index, Qt::Checked, Qt::CheckStateRole);
|
||||
}
|
||||
const ProxyModel::FilterMode filterMode = uiFilter.filterCombo->itemData(index).value<ProxyModel::FilterMode>();
|
||||
const bool filterActive = (filterMode != ProxyModel::NoFilter);
|
||||
|
||||
uiFilter.filterFilesPattern->setEnabled(filterActive);
|
||||
uiFilter.searchMimetype->setEnabled(filterActive);
|
||||
uiFilter.filterFilesList->setEnabled(filterActive);
|
||||
uiFilter.selectAll->setEnabled(filterActive);
|
||||
uiFilter.deselectAll->setEnabled(filterActive);
|
||||
if (filterActive) {
|
||||
selectAllMimetypes();
|
||||
}
|
||||
}
|
||||
|
||||
void FolderView::selectUnselectAll()
|
||||
void FolderView::selectAllMimetypes()
|
||||
{
|
||||
toggleAllMimetypes(Qt::Checked);
|
||||
}
|
||||
|
||||
void FolderView::deselectAllMimeTypes()
|
||||
{
|
||||
toggleAllMimetypes(Qt::Unchecked);
|
||||
}
|
||||
|
||||
void FolderView::toggleAllMimetypes(Qt::CheckState state)
|
||||
{
|
||||
Qt::CheckState state = sender() == uiFilter.selectAll ? Qt::Checked : Qt::Unchecked;
|
||||
for (int i = 0; i < uiFilter.filterFilesList->model()->rowCount(); i++) {
|
||||
const QModelIndex index = uiFilter.filterFilesList->model()->index(i, 0);
|
||||
uiFilter.filterFilesList->model()->setData(index, state, Qt::CheckStateRole);
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include "iconview.h"
|
||||
#include "dirlister.h"
|
||||
#include "proxymodel.h"
|
||||
|
||||
#include "ui_folderviewFilterConfig.h"
|
||||
#include "ui_folderviewDisplayConfig.h"
|
||||
|
@ -140,7 +141,8 @@ protected slots:
|
|||
|
||||
void configAccepted();
|
||||
void filterChanged(int index);
|
||||
void selectUnselectAll();
|
||||
void selectAllMimetypes();
|
||||
void deselectAllMimeTypes();
|
||||
void fontSettingsChanged();
|
||||
void iconSettingsChanged(int group);
|
||||
void clickSettingsChanged(int category);
|
||||
|
@ -170,6 +172,7 @@ private:
|
|||
void timerEvent(QTimerEvent *event);
|
||||
void recreateLayout();
|
||||
void setAppletTitle();
|
||||
void toggleAllMimetypes(Qt::CheckState);
|
||||
|
||||
private:
|
||||
KFileItemDelegate *m_delegate;
|
||||
|
@ -188,7 +191,7 @@ private:
|
|||
KUrl m_url;
|
||||
QColor m_textColor;
|
||||
QString m_titleText;
|
||||
int m_filterType;
|
||||
ProxyModel::FilterMode m_filterType;
|
||||
QString m_filterFiles;
|
||||
QStringList m_filterFilesMimeList;
|
||||
QPointer<KNewFileMenu> m_newMenu;
|
||||
|
@ -208,7 +211,6 @@ private:
|
|||
bool m_alignToGrid;
|
||||
bool m_clickToView;
|
||||
bool m_showSelectionMarker;
|
||||
bool m_userSelectedShowAllFiles;
|
||||
bool m_blankLabel;
|
||||
QString m_customLabel;
|
||||
QStringList m_previewPlugins;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QComboBox" name="filterType">
|
||||
<widget class="QComboBox" name="filterCombo">
|
||||
<property name="toolTip">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
|
@ -36,21 +36,6 @@ p, li { white-space: pre-wrap; }
|
|||
<property name="whatsThis">
|
||||
<string/>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Show All Files</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Show Files Matching</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Hide Files Matching</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -201,11 +186,6 @@ For example, if you have "*" as your pattern, but have nothing selecte
|
|||
<extends>QLineEdit</extends>
|
||||
<header>klineedit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>KComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>kcombobox.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<includes>
|
||||
<include location="global">KDE/KUrlRequester</include>
|
||||
|
|
|
@ -226,18 +226,6 @@ bool ProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) con
|
|||
return QString::compare(leftItem.url().url(), rightItem.url().url(), Qt::CaseSensitive);
|
||||
}
|
||||
|
||||
ProxyModel::FilterMode ProxyModel::filterModeFromInt(int filterMode)
|
||||
{
|
||||
switch (filterMode) {
|
||||
case 0:
|
||||
return ProxyModel::NoFilter;
|
||||
case 1:
|
||||
return ProxyModel::FilterShowMatches;
|
||||
default:
|
||||
return ProxyModel::FilterHideMatches;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool ProxyModel::matchMimeType(const KFileItem &item) const
|
||||
{
|
||||
if (m_mimeSet.isEmpty()) {
|
||||
|
|
|
@ -61,8 +61,6 @@ public:
|
|||
bool isDir(const QModelIndex &index, const KDirModel *dirModel) const;
|
||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||
|
||||
static FilterMode filterModeFromInt(int filterMode);
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||
bool matchMimeType(const KFileItem &item) const;
|
||||
|
|
Loading…
Reference in a new issue