summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederik Gladhorn <gladhorn@kde.org>2016-10-08 12:33:57 (GMT)
committerFrederik Gladhorn <gladhorn@kde.org>2016-10-08 12:33:57 (GMT)
commitad3b07f3c88e6fa964bee08731e166e68cd295d9 (patch)
treea9c7f491eee20eb60878cc4c0f2e1ea6f934054e
parent617e443254faec59a6433fd07a34e120fd4680e2 (diff)
Remove another round of pimpls
-rw-r--r--app/filtercontroller.cpp466
-rw-r--r--app/filtercontroller.h256
2 files changed, 350 insertions, 372 deletions
diff --git a/app/filtercontroller.cpp b/app/filtercontroller.cpp
index 8a3df47..93cfb6d 100644
--- a/app/filtercontroller.cpp
+++ b/app/filtercontroller.cpp
@@ -26,7 +26,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
// Qt
#include <QAction>
#include <QCompleter>
-#include <QDate>
#include <QLineEdit>
#include <QPainter>
#include <QPainterPath>
@@ -37,7 +36,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
// KDE
#include <KComboBox>
-#include <KFileItem>
#include <KIconLoader>
#include <QLineEdit>
#include <KLocalizedString>
@@ -46,8 +44,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
#include <lib/datewidget.h>
#include <lib/flowlayout.h>
#include <lib/paintutils.h>
-#include <lib/semanticinfo/sorteddirmodel.h>
-#include <lib/timeutils.h>
#ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE
// KDE
@@ -61,190 +57,67 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
namespace Gwenview
{
-/**
- * An AbstractSortedDirModelFilter which filters on the file names
- */
-class NameFilter : public AbstractSortedDirModelFilter
-{
-public:
- enum Mode {
- Contains,
- DoesNotContain
- };
- NameFilter(SortedDirModel* model)
- : AbstractSortedDirModelFilter(model)
- , mText()
- , mMode(Contains)
- {}
-
- virtual bool needsSemanticInfo() const
- {
- return false;
- }
-
- virtual bool acceptsIndex(const QModelIndex& index) const
- {
- if (mText.isEmpty()) {
- return true;
- }
- switch (mMode) {
- case Contains:
- return index.data().toString().contains(mText, Qt::CaseInsensitive);
- default: /*DoesNotContain:*/
- return !index.data().toString().contains(mText, Qt::CaseInsensitive);
- }
- }
-
- void setText(const QString& text)
- {
- mText = text;
- model()->applyFilters();
- }
-
- void setMode(Mode mode)
- {
- mMode = mode;
- model()->applyFilters();
- }
-
-private:
- QString mText;
- Mode mMode;
-};
-
-struct NameFilterWidgetPrivate
-{
- QPointer<NameFilter> mFilter;
- KComboBox* mModeComboBox;
- QLineEdit* mLineEdit;
-};
-
NameFilterWidget::NameFilterWidget(SortedDirModel* model)
-: d(new NameFilterWidgetPrivate)
{
- d->mFilter = new NameFilter(model);
+ mFilter = new NameFilter(model);
- d->mModeComboBox = new KComboBox;
- d->mModeComboBox->addItem(i18n("Name contains"), QVariant(NameFilter::Contains));
- d->mModeComboBox->addItem(i18n("Name does not contain"), QVariant(NameFilter::DoesNotContain));
+ mModeComboBox = new KComboBox;
+ mModeComboBox->addItem(i18n("Name contains"), QVariant(NameFilter::Contains));
+ mModeComboBox->addItem(i18n("Name does not contain"), QVariant(NameFilter::DoesNotContain));
- d->mLineEdit = new QLineEdit;
+ mLineEdit = new QLineEdit;
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(2);
- layout->addWidget(d->mModeComboBox);
- layout->addWidget(d->mLineEdit);
+ layout->addWidget(mModeComboBox);
+ layout->addWidget(mLineEdit);
QTimer* timer = new QTimer(this);
timer->setInterval(350);
timer->setSingleShot(true);
connect(timer, SIGNAL(timeout()), SLOT(applyNameFilter()));
- connect(d->mLineEdit, SIGNAL(textChanged(QString)),
+ connect(mLineEdit, SIGNAL(textChanged(QString)),
timer, SLOT(start()));
- connect(d->mModeComboBox, SIGNAL(currentIndexChanged(int)),
+ connect(mModeComboBox, SIGNAL(currentIndexChanged(int)),
SLOT(applyNameFilter()));
- QTimer::singleShot(0, d->mLineEdit, SLOT(setFocus()));
+ QTimer::singleShot(0, mLineEdit, SLOT(setFocus()));
}
NameFilterWidget::~NameFilterWidget()
{
- delete d->mFilter;
- delete d;
+ delete mFilter;
}
void NameFilterWidget::applyNameFilter()
{
- QVariant data = d->mModeComboBox->itemData(d->mModeComboBox->currentIndex());
- d->mFilter->setMode(NameFilter::Mode(data.toInt()));
- d->mFilter->setText(d->mLineEdit->text());
+ QVariant data = mModeComboBox->itemData(mModeComboBox->currentIndex());
+ mFilter->setMode(NameFilter::Mode(data.toInt()));
+ mFilter->setText(mLineEdit->text());
}
-/**
- * An AbstractSortedDirModelFilter which filters on the file dates
- */
-class DateFilter : public AbstractSortedDirModelFilter
-{
-public:
- enum Mode {
- GreaterOrEqual,
- Equal,
- LessOrEqual
- };
- DateFilter(SortedDirModel* model)
- : AbstractSortedDirModelFilter(model)
- , mMode(GreaterOrEqual)
- {}
-
- virtual bool needsSemanticInfo() const
- {
- return false;
- }
-
- virtual bool acceptsIndex(const QModelIndex& index) const
- {
- if (!mDate.isValid()) {
- return true;
- }
- KFileItem fileItem = model()->itemForSourceIndex(index);
- QDate date = TimeUtils::dateTimeForFileItem(fileItem).date();
- switch (mMode) {
- case GreaterOrEqual:
- return date >= mDate;
- case Equal:
- return date == mDate;
- default: /* LessOrEqual */
- return date <= mDate;
- }
- }
-
- void setDate(const QDate& date)
- {
- mDate = date;
- model()->applyFilters();
- }
-
- void setMode(Mode mode)
- {
- mMode = mode;
- model()->applyFilters();
- }
-
-private:
- QDate mDate;
- Mode mMode;
-};
-
-struct DateFilterWidgetPrivate
-{
- QPointer<DateFilter> mFilter;
- KComboBox* mModeComboBox;
- DateWidget* mDateWidget;
-};
-
DateFilterWidget::DateFilterWidget(SortedDirModel* model)
-: d(new DateFilterWidgetPrivate)
{
- d->mFilter = new DateFilter(model);
+ mFilter = new DateFilter(model);
- d->mModeComboBox = new KComboBox;
- d->mModeComboBox->addItem(i18n("Date >="), DateFilter::GreaterOrEqual);
- d->mModeComboBox->addItem(i18n("Date ="), DateFilter::Equal);
- d->mModeComboBox->addItem(i18n("Date <="), DateFilter::LessOrEqual);
+ mModeComboBox = new KComboBox;
+ mModeComboBox->addItem(i18n("Date >="), DateFilter::GreaterOrEqual);
+ mModeComboBox->addItem(i18n("Date ="), DateFilter::Equal);
+ mModeComboBox->addItem(i18n("Date <="), DateFilter::LessOrEqual);
- d->mDateWidget = new DateWidget;
+ mDateWidget = new DateWidget;
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(0);
- layout->addWidget(d->mModeComboBox);
- layout->addWidget(d->mDateWidget);
+ layout->addWidget(mModeComboBox);
+ layout->addWidget(mDateWidget);
- connect(d->mDateWidget, SIGNAL(dateChanged(QDate)),
+ connect(mDateWidget, SIGNAL(dateChanged(QDate)),
SLOT(applyDateFilter()));
- connect(d->mModeComboBox, SIGNAL(currentIndexChanged(int)),
+ connect(mModeComboBox, SIGNAL(currentIndexChanged(int)),
SLOT(applyDateFilter()));
applyDateFilter();
@@ -252,100 +125,39 @@ DateFilterWidget::DateFilterWidget(SortedDirModel* model)
DateFilterWidget::~DateFilterWidget()
{
- delete d->mFilter;
- delete d;
+ delete mFilter;
}
void DateFilterWidget::applyDateFilter()
{
- QVariant data = d->mModeComboBox->itemData(d->mModeComboBox->currentIndex());
- d->mFilter->setMode(DateFilter::Mode(data.toInt()));
- d->mFilter->setDate(d->mDateWidget->date());
+ QVariant data = mModeComboBox->itemData(mModeComboBox->currentIndex());
+ mFilter->setMode(DateFilter::Mode(data.toInt()));
+ mFilter->setDate(mDateWidget->date());
}
#ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE
-/**
- * An AbstractSortedDirModelFilter which filters on file ratings
- */
-class RatingFilter : public AbstractSortedDirModelFilter
-{
-public:
- enum Mode {
- GreaterOrEqual,
- Equal,
- LessOrEqual
- };
-
- RatingFilter(SortedDirModel* model)
- : AbstractSortedDirModelFilter(model)
- , mRating(0)
- , mMode(GreaterOrEqual) {}
-
- virtual bool needsSemanticInfo() const
- {
- return true;
- }
-
- virtual bool acceptsIndex(const QModelIndex& index) const
- {
- SemanticInfo info = model()->semanticInfoForSourceIndex(index);
- switch (mMode) {
- case GreaterOrEqual:
- return info.mRating >= mRating;
- case Equal:
- return info.mRating == mRating;
- default: /* LessOrEqual */
- return info.mRating <= mRating;
- }
- }
-
- void setRating(int value)
- {
- mRating = value;
- model()->applyFilters();
- }
-
- void setMode(Mode mode)
- {
- mMode = mode;
- model()->applyFilters();
- }
-
-private:
- int mRating;
- Mode mMode;
-};
-
-struct RatingWidgetPrivate
-{
- KComboBox* mModeComboBox;
- KRatingWidget* mRatingWidget;
- QPointer<RatingFilter> mFilter;
-};
-
RatingFilterWidget::RatingFilterWidget(SortedDirModel* model)
-: d(new RatingWidgetPrivate)
{
- d->mModeComboBox = new KComboBox;
- d->mModeComboBox->addItem(i18n("Rating >="), RatingFilter::GreaterOrEqual);
- d->mModeComboBox->addItem(i18n("Rating =") , RatingFilter::Equal);
- d->mModeComboBox->addItem(i18n("Rating <="), RatingFilter::LessOrEqual);
+ mModeComboBox = new KComboBox;
+ mModeComboBox->addItem(i18n("Rating >="), RatingFilter::GreaterOrEqual);
+ mModeComboBox->addItem(i18n("Rating =") , RatingFilter::Equal);
+ mModeComboBox->addItem(i18n("Rating <="), RatingFilter::LessOrEqual);
- d->mRatingWidget = new KRatingWidget;
- d->mRatingWidget->setHalfStepsEnabled(true);
- d->mRatingWidget->setMaxRating(10);
+ mRatingWidget = new KRatingWidget;
+ mRatingWidget->setHalfStepsEnabled(true);
+ mRatingWidget->setMaxRating(10);
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(0);
- layout->addWidget(d->mModeComboBox);
- layout->addWidget(d->mRatingWidget);
+ layout->addWidget(mModeComboBox);
+ layout->addWidget(mRatingWidget);
- d->mFilter = new RatingFilter(model);
+ mFilter = new RatingFilter(model);
- QObject::connect(d->mModeComboBox, SIGNAL(currentIndexChanged(int)),
+ QObject::connect(mModeComboBox, SIGNAL(currentIndexChanged(int)),
SLOT(updateFilterMode()));
- QObject::connect(d->mRatingWidget, SIGNAL(ratingChanged(int)),
+ QObject::connect(mRatingWidget, SIGNAL(ratingChanged(int)),
SLOT(slotRatingChanged(int)));
updateFilterMode();
@@ -353,128 +165,73 @@ RatingFilterWidget::RatingFilterWidget(SortedDirModel* model)
RatingFilterWidget::~RatingFilterWidget()
{
- delete d->mFilter;
- delete d;
+ delete mFilter;
}
void RatingFilterWidget::slotRatingChanged(int value)
{
- d->mFilter->setRating(value);
+ mFilter->setRating(value);
}
void RatingFilterWidget::updateFilterMode()
{
- QVariant data = d->mModeComboBox->itemData(d->mModeComboBox->currentIndex());
- d->mFilter->setMode(RatingFilter::Mode(data.toInt()));
+ QVariant data = mModeComboBox->itemData(mModeComboBox->currentIndex());
+ mFilter->setMode(RatingFilter::Mode(data.toInt()));
}
-/**
- * An AbstractSortedDirModelFilter which filters on associated tags
- */
-class TagFilter : public AbstractSortedDirModelFilter
-{
-public:
- TagFilter(SortedDirModel* model)
- : AbstractSortedDirModelFilter(model)
- , mWantMatchingTag(true)
- {}
-
- virtual bool needsSemanticInfo() const
- {
- return true;
- }
-
- virtual bool acceptsIndex(const QModelIndex& index) const
- {
- if (mTag.isEmpty()) {
- return true;
- }
- SemanticInfo info = model()->semanticInfoForSourceIndex(index);
- if (mWantMatchingTag) {
- return info.mTags.contains(mTag);
- } else {
- return !info.mTags.contains(mTag);
- }
- }
-
- void setTag(const SemanticInfoTag& tag)
- {
- mTag = tag;
- model()->applyFilters();
- }
-
- void setWantMatchingTag(bool value)
- {
- mWantMatchingTag = value;
- model()->applyFilters();
- }
-
-private:
- SemanticInfoTag mTag;
- bool mWantMatchingTag;
-};
-
-struct TagFilterWidgetPrivate
-{
- KComboBox* mModeComboBox;
- QComboBox* mTagComboBox;
- QPointer<TagFilter> mFilter;
-};
TagFilterWidget::TagFilterWidget(SortedDirModel* model)
-: d(new TagFilterWidgetPrivate)
{
- d->mFilter = new TagFilter(model);
+ mFilter = new TagFilter(model);
- d->mModeComboBox = new KComboBox;
- d->mModeComboBox->addItem(i18n("Tagged"), QVariant(true));
- d->mModeComboBox->addItem(i18n("Not Tagged"), QVariant(false));
+ mModeComboBox = new KComboBox;
+ mModeComboBox->addItem(i18n("Tagged"), QVariant(true));
+ mModeComboBox->addItem(i18n("Not Tagged"), QVariant(false));
- d->mTagComboBox = new QComboBox;
+ mTagComboBox = new QComboBox;
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(0);
- layout->addWidget(d->mModeComboBox);
- layout->addWidget(d->mTagComboBox);
+ layout->addWidget(mModeComboBox);
+ layout->addWidget(mTagComboBox);
AbstractSemanticInfoBackEnd* backEnd = model->semanticInfoBackEnd();
backEnd->refreshAllTags();
TagModel* tagModel = TagModel::createAllTagsModel(this, backEnd);
- QCompleter* completer = new QCompleter(d->mTagComboBox);
+ QCompleter* completer = new QCompleter(mTagComboBox);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completer->setModel(tagModel);
- d->mTagComboBox->setCompleter(completer);
- d->mTagComboBox->setInsertPolicy(QComboBox::NoInsert);
- d->mTagComboBox->setEditable(true);
- d->mTagComboBox->setModel(tagModel);
- d->mTagComboBox->setCurrentIndex(-1);
+ mTagComboBox->setCompleter(completer);
+ mTagComboBox->setInsertPolicy(QComboBox::NoInsert);
+ mTagComboBox->setEditable(true);
+ mTagComboBox->setModel(tagModel);
+ mTagComboBox->setCurrentIndex(-1);
- connect(d->mTagComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateTagSetFilter()));
+ connect(mTagComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateTagSetFilter()));
- connect(d->mModeComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateTagSetFilter()));
+ connect(mModeComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateTagSetFilter()));
- QTimer::singleShot(0, d->mTagComboBox, SLOT(setFocus()));
+ QTimer::singleShot(0, mTagComboBox, SLOT(setFocus()));
}
TagFilterWidget::~TagFilterWidget()
{
- delete d->mFilter;
- delete d;
+ delete mFilter;
}
void TagFilterWidget::updateTagSetFilter()
{
- QModelIndex index = d->mTagComboBox->model()->index(d->mTagComboBox->currentIndex(), 0);
+ QModelIndex index = mTagComboBox->model()->index(mTagComboBox->currentIndex(), 0);
if (!index.isValid()) {
qWarning() << "Invalid index";
return;
}
SemanticInfoTag tag = index.data(TagModel::TagRole).toString();
- d->mFilter->setTag(tag);
+ mFilter->setTag(tag);
- bool wantMatchingTag = d->mModeComboBox->itemData(d->mModeComboBox->currentIndex()).toBool();
- d->mFilter->setWantMatchingTag(wantMatchingTag);
+ bool wantMatchingTag = mModeComboBox->itemData(mModeComboBox->currentIndex()).toBool();
+ mFilter->setWantMatchingTag(wantMatchingTag);
}
#endif
@@ -521,95 +278,82 @@ protected:
}
};
-struct FilterControllerPrivate
-{
- FilterController* q;
- QFrame* mFrame;
- SortedDirModel* mDirModel;
- QList<QAction*> mActionList;
-
- int mFilterWidgetCount; /**< How many filter widgets are in mFrame */
-
- void addAction(const QString& text, const char* slot)
- {
- QAction* action = new QAction(text, q);
- QObject::connect(action, SIGNAL(triggered()), q, slot);
- mActionList << action;
- }
-
- void addFilter(QWidget* widget)
- {
- if (mFrame->isHidden()) {
- mFrame->show();
- }
- FilterWidgetContainer* container = new FilterWidgetContainer;
- container->setFilterWidget(widget);
- mFrame->layout()->addWidget(container);
-
- mFilterWidgetCount++;
- QObject::connect(container, SIGNAL(destroyed()), q, SLOT(slotFilterWidgetClosed()));
- }
-};
FilterController::FilterController(QFrame* frame, SortedDirModel* dirModel)
: QObject(frame)
-, d(new FilterControllerPrivate)
{
- d->q = this;
- d->mFrame = frame;
- d->mDirModel = dirModel;
- d->mFilterWidgetCount = 0;
+ q = this;
+ mFrame = frame;
+ mDirModel = dirModel;
+ mFilterWidgetCount = 0;
- d->mFrame->hide();
- FlowLayout* layout = new FlowLayout(d->mFrame);
+ mFrame->hide();
+ FlowLayout* layout = new FlowLayout(mFrame);
layout->setSpacing(2);
- d->addAction(i18nc("@action:inmenu", "Filter by Name"), SLOT(addFilterByName()));
- d->addAction(i18nc("@action:inmenu", "Filter by Date"), SLOT(addFilterByDate()));
+ addAction(i18nc("@action:inmenu", "Filter by Name"), SLOT(addFilterByName()));
+ addAction(i18nc("@action:inmenu", "Filter by Date"), SLOT(addFilterByDate()));
#ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE
- d->addAction(i18nc("@action:inmenu", "Filter by Rating"), SLOT(addFilterByRating()));
- d->addAction(i18nc("@action:inmenu", "Filter by Tag"), SLOT(addFilterByTag()));
+ addAction(i18nc("@action:inmenu", "Filter by Rating"), SLOT(addFilterByRating()));
+ addAction(i18nc("@action:inmenu", "Filter by Tag"), SLOT(addFilterByTag()));
#endif
}
-FilterController::~FilterController()
-{
- delete d;
-}
-
QList<QAction*> FilterController::actionList() const
{
- return d->mActionList;
+ return mActionList;
}
void FilterController::addFilterByName()
{
- d->addFilter(new NameFilterWidget(d->mDirModel));
+ addFilter(new NameFilterWidget(mDirModel));
}
void FilterController::addFilterByDate()
{
- d->addFilter(new DateFilterWidget(d->mDirModel));
+ addFilter(new DateFilterWidget(mDirModel));
}
#ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE
void FilterController::addFilterByRating()
{
- d->addFilter(new RatingFilterWidget(d->mDirModel));
+ addFilter(new RatingFilterWidget(mDirModel));
}
void FilterController::addFilterByTag()
{
- d->addFilter(new TagFilterWidget(d->mDirModel));
+ addFilter(new TagFilterWidget(mDirModel));
}
#endif
void FilterController::slotFilterWidgetClosed()
{
- d->mFilterWidgetCount--;
- if (d->mFilterWidgetCount == 0) {
- d->mFrame->hide();
+ mFilterWidgetCount--;
+ if (mFilterWidgetCount == 0) {
+ mFrame->hide();
}
}
+
+void FilterController::addAction(const QString& text, const char* slot)
+{
+ QAction* action = new QAction(text, q);
+ QObject::connect(action, SIGNAL(triggered()), q, slot);
+ mActionList << action;
+}
+
+
+void FilterController::addFilter(QWidget* widget)
+{
+ if (mFrame->isHidden()) {
+ mFrame->show();
+ }
+ FilterWidgetContainer* container = new FilterWidgetContainer;
+ container->setFilterWidget(widget);
+ mFrame->layout()->addWidget(container);
+
+ mFilterWidgetCount++;
+ QObject::connect(container, SIGNAL(destroyed()), q, SLOT(slotFilterWidgetClosed()));
+}
+
} // namespace
diff --git a/app/filtercontroller.h b/app/filtercontroller.h
index 2f6ef7b..44697f3 100644
--- a/app/filtercontroller.h
+++ b/app/filtercontroller.h
@@ -24,23 +24,90 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
#include <config-gwenview.h>
// Qt
+#include <QDate>
#include <QList>
#include <QObject>
#include <QWidget>
// KDE
+#include <KFileItem>
// Local
+#include <lib/datewidget.h>
+#include <lib/semanticinfo/sorteddirmodel.h>
+#include <lib/timeutils.h>
+
+#ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE
+// KDE
+#include <kratingwidget.h>
+
+// Local
+#include <lib/semanticinfo/abstractsemanticinfobackend.h>
+#include <lib/semanticinfo/tagmodel.h>
+#endif
class QAction;
class QFrame;
+class QLineEdit;
+class QComboBox;
+class KComboBox;
namespace Gwenview
{
class SortedDirModel;
-struct NameFilterWidgetPrivate;
+/**
+ * An AbstractSortedDirModelFilter which filters on the file names
+ */
+class NameFilter : public AbstractSortedDirModelFilter
+{
+public:
+ enum Mode {
+ Contains,
+ DoesNotContain
+ };
+ NameFilter(SortedDirModel* model)
+ : AbstractSortedDirModelFilter(model)
+ , mText()
+ , mMode(Contains)
+ {}
+
+ virtual bool needsSemanticInfo() const
+ {
+ return false;
+ }
+
+ virtual bool acceptsIndex(const QModelIndex& index) const
+ {
+ if (mText.isEmpty()) {
+ return true;
+ }
+ switch (mMode) {
+ case Contains:
+ return index.data().toString().contains(mText, Qt::CaseInsensitive);
+ default: /*DoesNotContain:*/
+ return !index.data().toString().contains(mText, Qt::CaseInsensitive);
+ }
+ }
+
+ void setText(const QString& text)
+ {
+ mText = text;
+ model()->applyFilters();
+ }
+
+ void setMode(Mode mode)
+ {
+ mMode = mode;
+ model()->applyFilters();
+ }
+
+private:
+ QString mText;
+ Mode mMode;
+};
+
class NameFilterWidget : public QWidget
{
Q_OBJECT
@@ -52,10 +119,67 @@ private Q_SLOTS:
void applyNameFilter();
private:
- NameFilterWidgetPrivate* const d;
+ QPointer<NameFilter> mFilter;
+ KComboBox* mModeComboBox;
+ QLineEdit* mLineEdit;
+};
+
+
+/**
+ * An AbstractSortedDirModelFilter which filters on the file dates
+ */
+class DateFilter : public AbstractSortedDirModelFilter
+{
+public:
+ enum Mode {
+ GreaterOrEqual,
+ Equal,
+ LessOrEqual
+ };
+ DateFilter(SortedDirModel* model)
+ : AbstractSortedDirModelFilter(model)
+ , mMode(GreaterOrEqual)
+ {}
+
+ virtual bool needsSemanticInfo() const
+ {
+ return false;
+ }
+
+ virtual bool acceptsIndex(const QModelIndex& index) const
+ {
+ if (!mDate.isValid()) {
+ return true;
+ }
+ KFileItem fileItem = model()->itemForSourceIndex(index);
+ QDate date = TimeUtils::dateTimeForFileItem(fileItem).date();
+ switch (mMode) {
+ case GreaterOrEqual:
+ return date >= mDate;
+ case Equal:
+ return date == mDate;
+ default: /* LessOrEqual */
+ return date <= mDate;
+ }
+ }
+
+ void setDate(const QDate& date)
+ {
+ mDate = date;
+ model()->applyFilters();
+ }
+
+ void setMode(Mode mode)
+ {
+ mMode = mode;
+ model()->applyFilters();
+ }
+
+private:
+ QDate mDate;
+ Mode mMode;
};
-struct DateFilterWidgetPrivate;
class DateFilterWidget : public QWidget
{
Q_OBJECT
@@ -67,11 +191,65 @@ private Q_SLOTS:
void applyDateFilter();
private:
- DateFilterWidgetPrivate* const d;
+ QPointer<DateFilter> mFilter;
+ KComboBox* mModeComboBox;
+ DateWidget* mDateWidget;
};
+
#ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE
-struct RatingWidgetPrivate;
+/**
+ * An AbstractSortedDirModelFilter which filters on file ratings
+ */
+class RatingFilter : public AbstractSortedDirModelFilter
+{
+public:
+ enum Mode {
+ GreaterOrEqual,
+ Equal,
+ LessOrEqual
+ };
+
+ RatingFilter(SortedDirModel* model)
+ : AbstractSortedDirModelFilter(model)
+ , mRating(0)
+ , mMode(GreaterOrEqual) {}
+
+ virtual bool needsSemanticInfo() const
+ {
+ return true;
+ }
+
+ virtual bool acceptsIndex(const QModelIndex& index) const
+ {
+ SemanticInfo info = model()->semanticInfoForSourceIndex(index);
+ switch (mMode) {
+ case GreaterOrEqual:
+ return info.mRating >= mRating;
+ case Equal:
+ return info.mRating == mRating;
+ default: /* LessOrEqual */
+ return info.mRating <= mRating;
+ }
+ }
+
+ void setRating(int value)
+ {
+ mRating = value;
+ model()->applyFilters();
+ }
+
+ void setMode(Mode mode)
+ {
+ mMode = mode;
+ model()->applyFilters();
+ }
+
+private:
+ int mRating;
+ Mode mMode;
+};
+
class RatingFilterWidget : public QWidget
{
Q_OBJECT
@@ -84,10 +262,57 @@ private Q_SLOTS:
void updateFilterMode();
private:
- RatingWidgetPrivate* const d;
+ KComboBox* mModeComboBox;
+ KRatingWidget* mRatingWidget;
+ QPointer<RatingFilter> mFilter;
+};
+
+/**
+ * An AbstractSortedDirModelFilter which filters on associated tags
+ */
+class TagFilter : public AbstractSortedDirModelFilter
+{
+public:
+ TagFilter(SortedDirModel* model)
+ : AbstractSortedDirModelFilter(model)
+ , mWantMatchingTag(true)
+ {}
+
+ virtual bool needsSemanticInfo() const
+ {
+ return true;
+ }
+
+ virtual bool acceptsIndex(const QModelIndex& index) const
+ {
+ if (mTag.isEmpty()) {
+ return true;
+ }
+ SemanticInfo info = model()->semanticInfoForSourceIndex(index);
+ if (mWantMatchingTag) {
+ return info.mTags.contains(mTag);
+ } else {
+ return !info.mTags.contains(mTag);
+ }
+ }
+
+ void setTag(const SemanticInfoTag& tag)
+ {
+ mTag = tag;
+ model()->applyFilters();
+ }
+
+ void setWantMatchingTag(bool value)
+ {
+ mWantMatchingTag = value;
+ model()->applyFilters();
+ }
+
+private:
+ SemanticInfoTag mTag;
+ bool mWantMatchingTag;
};
-struct TagFilterWidgetPrivate;
class TagFilterWidget : public QWidget
{
Q_OBJECT
@@ -99,11 +324,13 @@ private Q_SLOTS:
void updateTagSetFilter();
private:
- TagFilterWidgetPrivate* const d;
+ KComboBox* mModeComboBox;
+ QComboBox* mTagComboBox;
+ QPointer<TagFilter> mFilter;
};
#endif
-struct FilterControllerPrivate;
+
/**
* This class manages the filter widgets in the filter frame and assign the
* corresponding filters to the SortedDirModel
@@ -113,7 +340,6 @@ class FilterController : public QObject
Q_OBJECT
public:
FilterController(QFrame* filterFrame, SortedDirModel* model);
- ~FilterController();
QList<QAction*> actionList() const;
@@ -127,7 +353,15 @@ private Q_SLOTS:
void slotFilterWidgetClosed();
private:
- FilterControllerPrivate* const d;
+ void addAction(const QString& text, const char* slot);
+ void addFilter(QWidget* widget);
+
+ FilterController* q;
+ QFrame* mFrame;
+ SortedDirModel* mDirModel;
+ QList<QAction*> mActionList;
+
+ int mFilterWidgetCount; /**< How many filter widgets are in mFrame */
};
} // namespace