Commit 17de924a authored by Laurent Montel's avatar Laurent Montel 😁

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
parent 30b7df1e
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "../src/core/widgets/searchlinestatus.h" #include "../src/core/widgets/searchlinestatus.h"
#include <QMenu> #include <QMenu>
#include <QTest> #include <QTest>
#include <QCompleter>
SearchLineStatusTest::SearchLineStatusTest(QObject *parent) SearchLineStatusTest::SearchLineStatusTest(QObject *parent)
: QObject(parent) : QObject(parent)
...@@ -40,6 +41,38 @@ void SearchLineStatusTest::shouldHaveDefaultValue() ...@@ -40,6 +41,38 @@ void SearchLineStatusTest::shouldHaveDefaultValue()
QVERIFY(filterMenu); QVERIFY(filterMenu);
QVERIFY(!filterMenu->actions().isEmpty()); 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) QTEST_MAIN(SearchLineStatusTest)
...@@ -29,6 +29,8 @@ public: ...@@ -29,6 +29,8 @@ public:
private Q_SLOTS: private Q_SLOTS:
void shouldHaveDefaultValue(); void shouldHaveDefaultValue();
void shouldAddCompletionItem();
void shouldClearCompleter();
}; };
#endif // SEARCHLINESTATUSTEST_H #endif // SEARCHLINESTATUSTEST_H
...@@ -178,7 +178,7 @@ Widget::~Widget() ...@@ -178,7 +178,7 @@ Widget::~Widget()
void Widget::changeQuicksearchVisibility(bool show) void Widget::changeQuicksearchVisibility(bool show)
{ {
KLineEdit *const lineEdit = d->quickSearchLine->searchEdit(); QLineEdit *const lineEdit = d->quickSearchLine->searchEdit();
if (!show) { if (!show) {
//if we hide it we do not want to apply the filter, //if we hide it we do not want to apply the filter,
//otherwise someone is maybe stuck with x new emails //otherwise someone is maybe stuck with x new emails
...@@ -369,7 +369,7 @@ StorageModel *Widget::storageModel() const ...@@ -369,7 +369,7 @@ StorageModel *Widget::storageModel() const
return d->mStorageModel; return d->mStorageModel;
} }
KLineEdit *Widget::quickSearch() const QLineEdit *Widget::quickSearch() const
{ {
return d->quickSearchLine->searchEdit(); return d->quickSearchLine->searchEdit();
} }
...@@ -1010,8 +1010,7 @@ void Widget::searchTimerFired() ...@@ -1010,8 +1010,7 @@ void Widget::searchTimerFired()
const QString text = d->quickSearchLine->searchEdit()->text(); const QString text = d->quickSearchLine->searchEdit()->text();
if (!text.isEmpty()) { if (!text.isEmpty()) {
KCompletion *comp = d->quickSearchLine->searchEdit()->completionObject(); d->quickSearchLine->addCompletionItem(text);
comp->addItem(text);
} }
d->mFilter->setCurrentFolder(d->mCurrentFolder); d->mFilter->setCurrentFolder(d->mCurrentFolder);
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <core/sortorder.h> #include <core/sortorder.h>
#include <core/widgets/quicksearchline.h> #include <core/widgets/quicksearchline.h>
class KLineEdit; class QLineEdit;
class QActionGroup; class QActionGroup;
class KComboBox; class KComboBox;
class QMenu; class QMenu;
...@@ -81,7 +81,7 @@ public: ...@@ -81,7 +81,7 @@ public:
* Returns the search line of this widget. Can be 0 if the quick search * Returns the search line of this widget. Can be 0 if the quick search
* is disabled in the global configuration. * is disabled in the global configuration.
*/ */
KLineEdit *quickSearch() const; QLineEdit *quickSearch() const;
/** /**
* Returns the View attached to this Widget. Never 0. * Returns the View attached to this Widget. Never 0.
......
...@@ -53,10 +53,10 @@ QuickSearchLine::QuickSearchLine(QWidget *parent) ...@@ -53,10 +53,10 @@ QuickSearchLine::QuickSearchLine(QWidget *parent)
connect(mSearchEdit, &SearchLineStatus::searchOptionChanged, this, &QuickSearchLine::searchOptionChanged); connect(mSearchEdit, &SearchLineStatus::searchOptionChanged, this, &QuickSearchLine::searchOptionChanged);
mSearchEdit->setPlaceholderText(i18nc("Search for messages.", "Search")); mSearchEdit->setPlaceholderText(i18nc("Search for messages.", "Search"));
mSearchEdit->setObjectName(QStringLiteral("quicksearch")); mSearchEdit->setObjectName(QStringLiteral("quicksearch"));
mSearchEdit->setClearButtonShown(true); mSearchEdit->setClearButtonEnabled(true);
connect(mSearchEdit, &KLineEdit::textChanged, this, &QuickSearchLine::slotSearchEditTextEdited); connect(mSearchEdit, &QLineEdit::textChanged, this, &QuickSearchLine::slotSearchEditTextEdited);
connect(mSearchEdit, &KLineEdit::clearButtonClicked, this, &QuickSearchLine::slotClearButtonClicked); //connect(mSearchEdit, &QLineEdit::clearButtonClicked, this, &QuickSearchLine::slotClearButtonClicked);
hbox->addWidget(mSearchEdit); hbox->addWidget(mSearchEdit);
...@@ -177,3 +177,8 @@ void QuickSearchLine::changeQuicksearchVisibility(bool show) ...@@ -177,3 +177,8 @@ void QuickSearchLine::changeQuicksearchVisibility(bool show)
mSearchEdit->setVisible(show); mSearchEdit->setVisible(show);
mTagFilterCombo->setVisible(show && mTagFilterCombo->count()); mTagFilterCombo->setVisible(show && mTagFilterCombo->count());
} }
void QuickSearchLine::addCompletionItem(const QString &str)
{
mSearchEdit->addCompletionItem(str);
}
...@@ -67,6 +67,7 @@ public: ...@@ -67,6 +67,7 @@ public:
void setContainsOutboundMessages(bool containsOutboundMessages); void setContainsOutboundMessages(bool containsOutboundMessages);
void changeQuicksearchVisibility(bool show); void changeQuicksearchVisibility(bool show);
void addCompletionItem(const QString &str);
Q_SIGNALS: Q_SIGNALS:
void clearButtonClicked(); void clearButtonClicked();
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
*/ */
#include "searchlinestatus.h" #include "searchlinestatus.h"
#include "messagelist_debug.h"
#include <KLocalizedString> #include <KLocalizedString>
#include <QAction> #include <QAction>
...@@ -25,10 +26,14 @@ ...@@ -25,10 +26,14 @@
#include <KIconLoader> #include <KIconLoader>
#include <QWidgetAction> #include <QWidgetAction>
#include <QPushButton> #include <QPushButton>
#include <QCompleter>
#include <QContextMenuEvent>
#include <QStringListModel>
static const char qLineEditclearButtonActionNameC[] = "_q_qlineeditclearaction";
using namespace MessageList::Core; using namespace MessageList::Core;
SearchLineStatus::SearchLineStatus(QWidget *parent) SearchLineStatus::SearchLineStatus(QWidget *parent)
: PimCommon::LineEditWithCompleter(parent), : QLineEdit(parent),
mLocked(false), mLocked(false),
mHasFilter(false), mHasFilter(false),
mLockAction(nullptr), mLockAction(nullptr),
...@@ -36,10 +41,20 @@ SearchLineStatus::SearchLineStatus(QWidget *parent) ...@@ -36,10 +41,20 @@ SearchLineStatus::SearchLineStatus(QWidget *parent)
mFilterMenu(nullptr), mFilterMenu(nullptr),
mContainsOutboundMessages(false) mContainsOutboundMessages(false)
{ {
mCompleter = new QCompleter(this);
mCompleterListModel = new QStringListModel(this);
mCompleter->setModel(mCompleterListModel);
setCompleter(mCompleter);
setClearButtonEnabled(true); setClearButtonEnabled(true);
setClearButtonShown(false);
initializeActions(); initializeActions();
createMenuSearch(); 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() SearchLineStatus::~SearchLineStatus()
...@@ -304,3 +319,30 @@ void SearchLineStatus::slotFilterActionClicked(QAction *act) ...@@ -304,3 +319,30 @@ void SearchLineStatus::slotFilterActionClicked(QAction *act)
Q_UNUSED(act); Q_UNUSED(act);
slotSearchOptionChanged(); 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);
}
...@@ -18,17 +18,18 @@ ...@@ -18,17 +18,18 @@
#ifndef SEARCHLINESTATUS_H #ifndef SEARCHLINESTATUS_H
#define SEARCHLINESTATUS_H #define SEARCHLINESTATUS_H
#include <PimCommon/LineEditWithCompleter> #include <QLineEdit>
#include <Akonadi/KMime/MessageStatus> #include <Akonadi/KMime/MessageStatus>
#include "messagelist_private_export.h" #include "messagelist_private_export.h"
#include "quicksearchline.h" #include "quicksearchline.h"
#include <QIcon> #include <QIcon>
class QStringListModel;
class QAction; class QAction;
namespace MessageList namespace MessageList
{ {
namespace Core namespace Core
{ {
class MESSAGELIST_TESTS_EXPORT SearchLineStatus : public PimCommon::LineEditWithCompleter class MESSAGELIST_TESTS_EXPORT SearchLineStatus : public QLineEdit
{ {
Q_OBJECT Q_OBJECT
public: public:
...@@ -43,9 +44,15 @@ public: ...@@ -43,9 +44,15 @@ public:
void setContainsOutboundMessages(bool containsOutboundMessages); void setContainsOutboundMessages(bool containsOutboundMessages);
bool containsOutboundMessages() const; bool containsOutboundMessages() const;
QuickSearchLine::SearchOptions searchOptions() const; QuickSearchLine::SearchOptions searchOptions() const;
void addCompletionItem(const QString &str);
void slotClearHistory();
Q_SIGNALS: Q_SIGNALS:
void filterActionChanged(const QList<Akonadi::MessageStatus> &lst); void filterActionChanged(const QList<Akonadi::MessageStatus> &lst);
void searchOptionChanged(); void searchOptionChanged();
void clearButtonClicked();
protected:
void contextMenuEvent(QContextMenuEvent *e) override;
private Q_SLOTS: private Q_SLOTS:
void slotToggledLockAction(); void slotToggledLockAction();
...@@ -77,6 +84,9 @@ private: ...@@ -77,6 +84,9 @@ private:
QAction *mSearchAgainstSubjectAction; QAction *mSearchAgainstSubjectAction;
QAction *mSearchAgainstFromOrToAction; QAction *mSearchAgainstFromOrToAction;
QAction *mSearchAgainstBccAction; QAction *mSearchAgainstBccAction;
QCompleter *mCompleter;
QStringListModel *mCompleterListModel;
QStringList mListCompetion;
bool mContainsOutboundMessages; bool mContainsOutboundMessages;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment