summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2017-08-02 13:26:36 +0200
committerMontel Laurent <[email protected]>2017-08-02 13:26:36 +0200
commit17de924ad746f75ebd47c85dc7ddcc5d19de8827 (patch)
treec0c805b6c5c836010cbb368c9364bb53a784304d
parent30b7df1eacb2b054664fe5ee569294bb1b3ffb3e (diff)
Fix Bug 381424 - When there's text in the search, the lock button is not accessible
FIXED-IN: 5.6.0 BUG: 381424 Convert it to QLineEdit as it's a bug in klineedit + new qt I don't know where is the bug and I don't have time to investigate it. And this lineedit doesn't need to have klineedit feature
-rw-r--r--messagelist/autotests/searchlinestatustest.cpp33
-rw-r--r--messagelist/autotests/searchlinestatustest.h2
-rw-r--r--messagelist/src/core/widgetbase.cpp7
-rw-r--r--messagelist/src/core/widgetbase.h4
-rw-r--r--messagelist/src/core/widgets/quicksearchline.cpp11
-rw-r--r--messagelist/src/core/widgets/quicksearchline.h1
-rw-r--r--messagelist/src/core/widgets/searchlinestatus.cpp46
-rw-r--r--messagelist/src/core/widgets/searchlinestatus.h14
8 files changed, 105 insertions, 13 deletions
diff --git a/messagelist/autotests/searchlinestatustest.cpp b/messagelist/autotests/searchlinestatustest.cpp
index 09600d5..95f2bdc 100644
--- a/messagelist/autotests/searchlinestatustest.cpp
+++ b/messagelist/autotests/searchlinestatustest.cpp
@@ -19,6 +19,7 @@
#include "../src/core/widgets/searchlinestatus.h"
#include <QMenu>
#include <QTest>
+#include <QCompleter>
SearchLineStatusTest::SearchLineStatusTest(QObject *parent)
: QObject(parent)
@@ -40,6 +41,38 @@ void SearchLineStatusTest::shouldHaveDefaultValue()
QVERIFY(filterMenu);
QVERIFY(!filterMenu->actions().isEmpty());
+ QVERIFY(w.completer());
+ QVERIFY(w.completer()->model());
+ QCOMPARE(w.completer()->model()->rowCount(), 0);
+
+ //Verify if qt qlineedit name changed
+ QAction *act = w.findChild<QAction *>(QLatin1String("_q_qlineeditclearaction"));
+ QVERIFY(act);
+}
+
+void SearchLineStatusTest::shouldAddCompletionItem()
+{
+ MessageList::Core::SearchLineStatus w;
+ w.addCompletionItem(QStringLiteral("ff"));
+ QCOMPARE(w.completer()->model()->rowCount(), 1);
+
+ //Don't add same element
+ w.addCompletionItem(QStringLiteral("ff"));
+ QCOMPARE(w.completer()->model()->rowCount(), 1);
+
+ w.addCompletionItem(QStringLiteral("ffss"));
+ QCOMPARE(w.completer()->model()->rowCount(), 2);
+}
+
+void SearchLineStatusTest::shouldClearCompleter()
+{
+ MessageList::Core::SearchLineStatus w;
+ for (int i = 0; i < 10 ;++i) {
+ w.addCompletionItem(QStringLiteral("ff%1").arg(i));
+ }
+ QCOMPARE(w.completer()->model()->rowCount(), 10);
+ w.slotClearHistory();
+ QCOMPARE(w.completer()->model()->rowCount(), 0);
}
QTEST_MAIN(SearchLineStatusTest)
diff --git a/messagelist/autotests/searchlinestatustest.h b/messagelist/autotests/searchlinestatustest.h
index fca5d0a..bbe39fb 100644
--- a/messagelist/autotests/searchlinestatustest.h
+++ b/messagelist/autotests/searchlinestatustest.h
@@ -29,6 +29,8 @@ public:
private Q_SLOTS:
void shouldHaveDefaultValue();
+ void shouldAddCompletionItem();
+ void shouldClearCompleter();
};
#endif // SEARCHLINESTATUSTEST_H
diff --git a/messagelist/src/core/widgetbase.cpp b/messagelist/src/core/widgetbase.cpp
index f84a828..8378194 100644
--- a/messagelist/src/core/widgetbase.cpp
+++ b/messagelist/src/core/widgetbase.cpp
@@ -178,7 +178,7 @@ Widget::~Widget()
void Widget::changeQuicksearchVisibility(bool show)
{
- KLineEdit *const lineEdit = d->quickSearchLine->searchEdit();
+ QLineEdit *const lineEdit = d->quickSearchLine->searchEdit();
if (!show) {
//if we hide it we do not want to apply the filter,
//otherwise someone is maybe stuck with x new emails
@@ -369,7 +369,7 @@ StorageModel *Widget::storageModel() const
return d->mStorageModel;
}
-KLineEdit *Widget::quickSearch() const
+QLineEdit *Widget::quickSearch() const
{
return d->quickSearchLine->searchEdit();
}
@@ -1010,8 +1010,7 @@ void Widget::searchTimerFired()
const QString text = d->quickSearchLine->searchEdit()->text();
if (!text.isEmpty()) {
- KCompletion *comp = d->quickSearchLine->searchEdit()->completionObject();
- comp->addItem(text);
+ d->quickSearchLine->addCompletionItem(text);
}
d->mFilter->setCurrentFolder(d->mCurrentFolder);
diff --git a/messagelist/src/core/widgetbase.h b/messagelist/src/core/widgetbase.h
index 16bc2ad..16aae0d 100644
--- a/messagelist/src/core/widgetbase.h
+++ b/messagelist/src/core/widgetbase.h
@@ -29,7 +29,7 @@
#include <core/sortorder.h>
#include <core/widgets/quicksearchline.h>
-class KLineEdit;
+class QLineEdit;
class QActionGroup;
class KComboBox;
class QMenu;
@@ -81,7 +81,7 @@ public:
* Returns the search line of this widget. Can be 0 if the quick search
* is disabled in the global configuration.
*/
- KLineEdit *quickSearch() const;
+ QLineEdit *quickSearch() const;
/**
* Returns the View attached to this Widget. Never 0.
diff --git a/messagelist/src/core/widgets/quicksearchline.cpp b/messagelist/src/core/widgets/quicksearchline.cpp
index 0b838d4..23df64a 100644
--- a/messagelist/src/core/widgets/quicksearchline.cpp
+++ b/messagelist/src/core/widgets/quicksearchline.cpp
@@ -53,10 +53,10 @@ QuickSearchLine::QuickSearchLine(QWidget *parent)
connect(mSearchEdit, &SearchLineStatus::searchOptionChanged, this, &QuickSearchLine::searchOptionChanged);
mSearchEdit->setPlaceholderText(i18nc("Search for messages.", "Search"));
mSearchEdit->setObjectName(QStringLiteral("quicksearch"));
- mSearchEdit->setClearButtonShown(true);
+ mSearchEdit->setClearButtonEnabled(true);
- connect(mSearchEdit, &KLineEdit::textChanged, this, &QuickSearchLine::slotSearchEditTextEdited);
- connect(mSearchEdit, &KLineEdit::clearButtonClicked, this, &QuickSearchLine::slotClearButtonClicked);
+ connect(mSearchEdit, &QLineEdit::textChanged, this, &QuickSearchLine::slotSearchEditTextEdited);
+ //connect(mSearchEdit, &QLineEdit::clearButtonClicked, this, &QuickSearchLine::slotClearButtonClicked);
hbox->addWidget(mSearchEdit);
@@ -177,3 +177,8 @@ void QuickSearchLine::changeQuicksearchVisibility(bool show)
mSearchEdit->setVisible(show);
mTagFilterCombo->setVisible(show && mTagFilterCombo->count());
}
+
+void QuickSearchLine::addCompletionItem(const QString &str)
+{
+ mSearchEdit->addCompletionItem(str);
+}
diff --git a/messagelist/src/core/widgets/quicksearchline.h b/messagelist/src/core/widgets/quicksearchline.h
index c211f41..1a460f1 100644
--- a/messagelist/src/core/widgets/quicksearchline.h
+++ b/messagelist/src/core/widgets/quicksearchline.h
@@ -67,6 +67,7 @@ public:
void setContainsOutboundMessages(bool containsOutboundMessages);
void changeQuicksearchVisibility(bool show);
+ void addCompletionItem(const QString &str);
Q_SIGNALS:
void clearButtonClicked();
diff --git a/messagelist/src/core/widgets/searchlinestatus.cpp b/messagelist/src/core/widgets/searchlinestatus.cpp
index cbf26bf..570f73d 100644
--- a/messagelist/src/core/widgets/searchlinestatus.cpp
+++ b/messagelist/src/core/widgets/searchlinestatus.cpp
@@ -16,6 +16,7 @@
*/
#include "searchlinestatus.h"
+#include "messagelist_debug.h"
#include <KLocalizedString>
#include <QAction>
@@ -25,10 +26,14 @@
#include <KIconLoader>
#include <QWidgetAction>
#include <QPushButton>
+#include <QCompleter>
+#include <QContextMenuEvent>
+#include <QStringListModel>
+static const char qLineEditclearButtonActionNameC[] = "_q_qlineeditclearaction";
using namespace MessageList::Core;
SearchLineStatus::SearchLineStatus(QWidget *parent)
- : PimCommon::LineEditWithCompleter(parent),
+ : QLineEdit(parent),
mLocked(false),
mHasFilter(false),
mLockAction(nullptr),
@@ -36,10 +41,20 @@ SearchLineStatus::SearchLineStatus(QWidget *parent)
mFilterMenu(nullptr),
mContainsOutboundMessages(false)
{
+ mCompleter = new QCompleter(this);
+ mCompleterListModel = new QStringListModel(this);
+ mCompleter->setModel(mCompleterListModel);
+ setCompleter(mCompleter);
+
setClearButtonEnabled(true);
- setClearButtonShown(false);
initializeActions();
createMenuSearch();
+ QAction *act = findChild<QAction *>(QLatin1String(qLineEditclearButtonActionNameC));
+ if (act) {
+ connect(act, &QAction::triggered, this, &SearchLineStatus::clearButtonClicked);
+ } else {
+ qCWarning(MESSAGELIST_LOG) << "Clear button name was changed ! Please verify qt code";
+ }
}
SearchLineStatus::~SearchLineStatus()
@@ -304,3 +319,30 @@ void SearchLineStatus::slotFilterActionClicked(QAction *act)
Q_UNUSED(act);
slotSearchOptionChanged();
}
+
+void SearchLineStatus::addCompletionItem(const QString &str)
+{
+ mListCompetion.removeAll(str);
+ mListCompetion.prepend(str);
+ while (mListCompetion.size() > 20) {
+ mListCompetion.removeLast();
+ }
+ mCompleterListModel->setStringList(mListCompetion);
+}
+
+void SearchLineStatus::contextMenuEvent(QContextMenuEvent *e)
+{
+ QMenu *popup = QLineEdit::createStandardContextMenu();
+ if (popup) {
+ popup->addSeparator();
+ popup->addAction(QIcon::fromTheme(QStringLiteral("edit-clear-locationbar-rtl")), i18n("Clear History"), this, &SearchLineStatus::slotClearHistory);
+ popup->exec(e->globalPos());
+ delete popup;
+ }
+}
+
+void SearchLineStatus::slotClearHistory()
+{
+ mListCompetion.clear();
+ mCompleterListModel->setStringList(mListCompetion);
+}
diff --git a/messagelist/src/core/widgets/searchlinestatus.h b/messagelist/src/core/widgets/searchlinestatus.h
index 2f56f14..94b9186 100644
--- a/messagelist/src/core/widgets/searchlinestatus.h
+++ b/messagelist/src/core/widgets/searchlinestatus.h
@@ -18,17 +18,18 @@
#ifndef SEARCHLINESTATUS_H
#define SEARCHLINESTATUS_H
-#include <PimCommon/LineEditWithCompleter>
+#include <QLineEdit>
#include <Akonadi/KMime/MessageStatus>
#include "messagelist_private_export.h"
#include "quicksearchline.h"
#include <QIcon>
+class QStringListModel;
class QAction;
namespace MessageList
{
namespace Core
{
-class MESSAGELIST_TESTS_EXPORT SearchLineStatus : public PimCommon::LineEditWithCompleter
+class MESSAGELIST_TESTS_EXPORT SearchLineStatus : public QLineEdit
{
Q_OBJECT
public:
@@ -43,9 +44,15 @@ public:
void setContainsOutboundMessages(bool containsOutboundMessages);
bool containsOutboundMessages() const;
QuickSearchLine::SearchOptions searchOptions() const;
+ void addCompletionItem(const QString &str);
+ void slotClearHistory();
Q_SIGNALS:
void filterActionChanged(const QList<Akonadi::MessageStatus> &lst);
void searchOptionChanged();
+ void clearButtonClicked();
+
+protected:
+ void contextMenuEvent(QContextMenuEvent *e) override;
private Q_SLOTS:
void slotToggledLockAction();
@@ -77,6 +84,9 @@ private:
QAction *mSearchAgainstSubjectAction;
QAction *mSearchAgainstFromOrToAction;
QAction *mSearchAgainstBccAction;
+ QCompleter *mCompleter;
+ QStringListModel *mCompleterListModel;
+ QStringList mListCompetion;
bool mContainsOutboundMessages;
};