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 @@
#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)
......@@ -29,6 +29,8 @@ public:
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAddCompletionItem();
void shouldClearCompleter();
};
#endif // SEARCHLINESTATUSTEST_H
......@@ -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);
......
......@@ -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.
......
......@@ -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);
}
......@@ -67,6 +67,7 @@ public:
void setContainsOutboundMessages(bool containsOutboundMessages);
void changeQuicksearchVisibility(bool show);
void addCompletionItem(const QString &str);
Q_SIGNALS:
void clearButtonClicked();
......
......@@ -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);
}
......@@ -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;
};
......
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