diff --git a/debug/akonadisearchdebugwidget.cpp b/debug/akonadisearchdebugwidget.cpp index f9d960b..7dc2844 100644 --- a/debug/akonadisearchdebugwidget.cpp +++ b/debug/akonadisearchdebugwidget.cpp @@ -1,120 +1,120 @@ /* Copyright (c) 2014-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "akonadisearchdebugwidget.h" #include "job/akonadisearchdebugsearchjob.h" #include "akonadisearchdebugsearchpathcombobox.h" #include "akonadisearchsyntaxhighlighter.h" #include #include #include #include #include using namespace Akonadi::Search; AkonadiSearchDebugWidget::AkonadiSearchDebugWidget(QWidget *parent) : QWidget(parent) { QVBoxLayout *mainLayout = new QVBoxLayout(this); QHBoxLayout *hbox = new QHBoxLayout; mainLayout->addLayout(hbox); QLabel *lab = new QLabel(QStringLiteral("Item identifier:"), this); hbox->addWidget(lab); mLineEdit = new KLineEdit(this); mLineEdit->setTrapReturnKey(true); - mLineEdit->setClearButtonShown(true); + mLineEdit->setClearButtonEnabled(true); mLineEdit->setObjectName(QStringLiteral("lineedit")); connect(mLineEdit, &KLineEdit::textChanged, this, &AkonadiSearchDebugWidget::slotSearchLineTextChanged); hbox->addWidget(mLineEdit); mSearchPathComboBox = new Akonadi::Search::AkonadiSearchDebugSearchPathComboBox(this); hbox->addWidget(mSearchPathComboBox); mSearchPathComboBox->setObjectName(QStringLiteral("searchpathcombo")); mSearchButton = new QPushButton(QStringLiteral("Search"), this); mSearchButton->setObjectName(QStringLiteral("searchbutton")); connect(mSearchButton, &QPushButton::clicked, this, &AkonadiSearchDebugWidget::slotSearch); hbox->addWidget(mSearchButton); mSearchButton->setEnabled(false); mPlainTextEditor = new QPlainTextEdit(this); new AkonadiSearchSyntaxHighlighter(mPlainTextEditor->document()); mPlainTextEditor->setReadOnly(true); mainLayout->addWidget(mPlainTextEditor); mPlainTextEditor->setObjectName(QStringLiteral("plaintexteditor")); connect(mLineEdit, &KLineEdit::returnPressed, this, &AkonadiSearchDebugWidget::slotSearch); } AkonadiSearchDebugWidget::~AkonadiSearchDebugWidget() { } void AkonadiSearchDebugWidget::slotSearchLineTextChanged(const QString &text) { mSearchButton->setEnabled(!text.trimmed().isEmpty()); } void AkonadiSearchDebugWidget::setAkonadiId(Akonadi::Item::Id akonadiId) { mLineEdit->setText(QString::number(akonadiId)); } void AkonadiSearchDebugWidget::setSearchType(AkonadiSearchDebugSearchPathComboBox::SearchType type) { mSearchPathComboBox->setSearchType(type); } void AkonadiSearchDebugWidget::doSearch() { slotSearch(); } QString AkonadiSearchDebugWidget::plainText() const { return QStringLiteral("Item: %1\n").arg(mLineEdit->text()) + mPlainTextEditor->toPlainText(); } void AkonadiSearchDebugWidget::slotSearch() { const QString searchId = mLineEdit->text(); if (searchId.isEmpty()) { return; } Akonadi::Search::AkonadiSearchDebugSearchJob *job = new Akonadi::Search::AkonadiSearchDebugSearchJob(this); job->setAkonadiId(searchId); job->setSearchPath(mSearchPathComboBox->searchPath()); connect(job, &Akonadi::Search::AkonadiSearchDebugSearchJob::result, this, &AkonadiSearchDebugWidget::slotResult); connect(job, &Akonadi::Search::AkonadiSearchDebugSearchJob::error, this, &AkonadiSearchDebugWidget::slotError); job->start(); } void AkonadiSearchDebugWidget::slotResult(const QString &result) { mPlainTextEditor->setPlainText(result); } void AkonadiSearchDebugWidget::slotError(const QString &errorStr) { mPlainTextEditor->setPlainText(QStringLiteral("Error found:\n") + errorStr); } diff --git a/debug/autotests/akonadisearchdebugwidgettest.cpp b/debug/autotests/akonadisearchdebugwidgettest.cpp index 364d4e2..82c8a48 100644 --- a/debug/autotests/akonadisearchdebugwidgettest.cpp +++ b/debug/autotests/akonadisearchdebugwidgettest.cpp @@ -1,95 +1,95 @@ /* Copyright (c) 2014-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "akonadisearchdebugwidgettest.h" #include #include "../akonadisearchdebugwidget.h" #include #include "../akonadisearchdebugsearchpathcombobox.h" #include #include AkonadiSearchDebugWidgetTest::AkonadiSearchDebugWidgetTest(QObject *parent) : QObject(parent) { } AkonadiSearchDebugWidgetTest::~AkonadiSearchDebugWidgetTest() { } void AkonadiSearchDebugWidgetTest::shouldHaveDefaultValue() { Akonadi::Search::AkonadiSearchDebugWidget widget; QPushButton *button = widget.findChild(QStringLiteral("searchbutton")); QVERIFY(button); QVERIFY(!button->isEnabled()); KLineEdit *lineEdit = widget.findChild(QStringLiteral("lineedit")); QVERIFY(lineEdit); QVERIFY(lineEdit->text().isEmpty()); QVERIFY(lineEdit->trapReturnKey()); - QVERIFY(lineEdit->isClearButtonShown()); + QVERIFY(lineEdit->isClearButtonEnabled()); QPlainTextEdit *editorWidget = widget.findChild(QStringLiteral("plaintexteditor")); QVERIFY(editorWidget->isReadOnly()); QVERIFY(editorWidget); QVERIFY(editorWidget->toPlainText().isEmpty()); Akonadi::Search::AkonadiSearchDebugSearchPathComboBox *searchCombo = widget.findChild(QStringLiteral("searchpathcombo")); QVERIFY(searchCombo); } void AkonadiSearchDebugWidgetTest::shouldFillLineEditWhenWeWantToSearchItem() { Akonadi::Search::AkonadiSearchDebugWidget widget; KLineEdit *lineEdit = widget.findChild(QStringLiteral("lineedit")); const int value = 42; const QString akonadiItem = QString::number(value); widget.setAkonadiId(value); QCOMPARE(lineEdit->text(), akonadiItem); } void AkonadiSearchDebugWidgetTest::shouldEnabledPushButtonWhenLineEditIsNotEmpty() { Akonadi::Search::AkonadiSearchDebugWidget widget; const int value = 42; widget.setAkonadiId(value); QPushButton *button = widget.findChild(QStringLiteral("searchbutton")); QVERIFY(button->isEnabled()); KLineEdit *lineEdit = widget.findChild(QStringLiteral("lineedit")); lineEdit->setText(QStringLiteral("")); QVERIFY(!button->isEnabled()); //trimmed string lineEdit->setText(QStringLiteral(" ")); QVERIFY(!button->isEnabled()); } void AkonadiSearchDebugWidgetTest::shouldChangeSearchType() { Akonadi::Search::AkonadiSearchDebugWidget widget; Akonadi::Search::AkonadiSearchDebugSearchPathComboBox::SearchType type = Akonadi::Search::AkonadiSearchDebugSearchPathComboBox::Emails; widget.setSearchType(type); Akonadi::Search::AkonadiSearchDebugSearchPathComboBox *searchCombo = widget.findChild(QStringLiteral("searchpathcombo")); const QString path = searchCombo->pathFromEnum(type); QCOMPARE(searchCombo->searchPath(), path); } QTEST_MAIN(AkonadiSearchDebugWidgetTest)