summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Faure <[email protected]>2016-07-14 15:20:12 +0200
committerDavid Faure <[email protected]>2016-07-14 15:20:12 +0200
commitd4d9fe536cb5cff58730f9ff14be451b28926103 (patch)
tree457e07f9b49693f0701bf15088c2f377655c6765
parentd0bdbeb640c6149d3ececd619290890e9a735beb (diff)
MessageViewer plugin: create NoteEdit widget on demand.
-rw-r--r--plugins/messageviewerplugins/autotests/viewerplugincreatenotetest.cpp17
-rw-r--r--plugins/messageviewerplugins/autotests/viewerplugincreatenotetest.h2
-rw-r--r--plugins/messageviewerplugins/createnoteplugin/viewerplugincreatenoteinterface.cpp29
-rw-r--r--plugins/messageviewerplugins/createnoteplugin/viewerplugincreatenoteinterface.h2
4 files changed, 31 insertions, 19 deletions
diff --git a/plugins/messageviewerplugins/autotests/viewerplugincreatenotetest.cpp b/plugins/messageviewerplugins/autotests/viewerplugincreatenotetest.cpp
index 5b19981..c2739b1 100644
--- a/plugins/messageviewerplugins/autotests/viewerplugincreatenotetest.cpp
+++ b/plugins/messageviewerplugins/autotests/viewerplugincreatenotetest.cpp
@@ -42,26 +42,27 @@ ViewerPluginCreateNoteTest::~ViewerPluginCreateNoteTest()
}
-void ViewerPluginCreateNoteTest::shouldHaveDefaultValue()
+void ViewerPluginCreateNoteTest::shouldCreateAction()
{
MessageViewer::ViewerPluginCreatenote *note = new MessageViewer::ViewerPluginCreatenote(this);
QVERIFY(!note->viewerPluginName().isEmpty());
QWidget *parent = new QWidget(0);
parent->setLayout(new QHBoxLayout);
-
- QVERIFY(note->createView(parent, new KActionCollection(this)));
+ MessageViewer::ViewerPluginInterface *interface = note->createView(parent, new KActionCollection(this));
+ QVERIFY(interface);
+ QVERIFY(!interface->actions().isEmpty());
}
-void ViewerPluginCreateNoteTest::shouldCreateAction()
+void ViewerPluginCreateNoteTest::shouldShowWidget()
{
- MessageViewer::ViewerPluginCreatenote *event = new MessageViewer::ViewerPluginCreatenote(this);
+ MessageViewer::ViewerPluginCreatenote *note = new MessageViewer::ViewerPluginCreatenote(this);
QWidget *parent = new QWidget(0);
parent->setLayout(new QHBoxLayout);
- MessageViewer::ViewerPluginInterface *interface = event->createView(parent, new KActionCollection(this));
- QVERIFY(!interface->actions().isEmpty());
+ MessageViewer::ViewerPluginInterface *interface = note->createView(parent, new KActionCollection(this));
+ interface->execute();
QWidget *createnotewidget = parent->findChild<QWidget *>(QStringLiteral("noteedit"));
QVERIFY(createnotewidget);
- QCOMPARE(createnotewidget->isVisible(), false);
+ QCOMPARE(createnotewidget->isHidden(), false);
}
QTEST_MAIN(ViewerPluginCreateNoteTest)
diff --git a/plugins/messageviewerplugins/autotests/viewerplugincreatenotetest.h b/plugins/messageviewerplugins/autotests/viewerplugincreatenotetest.h
index d98f394..a19b07a 100644
--- a/plugins/messageviewerplugins/autotests/viewerplugincreatenotetest.h
+++ b/plugins/messageviewerplugins/autotests/viewerplugincreatenotetest.h
@@ -30,8 +30,8 @@ public:
~ViewerPluginCreateNoteTest();
private Q_SLOTS:
- void shouldHaveDefaultValue();
void shouldCreateAction();
+ void shouldShowWidget();
};
#endif // VIEWERPLUGINCREATENOTETEST_H
diff --git a/plugins/messageviewerplugins/createnoteplugin/viewerplugincreatenoteinterface.cpp b/plugins/messageviewerplugins/createnoteplugin/viewerplugincreatenoteinterface.cpp
index 4ad596a..f785475 100644
--- a/plugins/messageviewerplugins/createnoteplugin/viewerplugincreatenoteinterface.cpp
+++ b/plugins/messageviewerplugins/createnoteplugin/viewerplugincreatenoteinterface.cpp
@@ -33,14 +33,10 @@
using namespace MessageViewer;
ViewerPluginCreatenoteInterface::ViewerPluginCreatenoteInterface(KActionCollection *ac, QWidget *parent)
- : ViewerPluginInterface(parent)
+ : ViewerPluginInterface(parent),
+ mNoteEdit(Q_NULLPTR)
{
createAction(ac);
- mNoteEdit = new NoteEdit(parent);
- mNoteEdit->setObjectName(QStringLiteral("noteedit"));
- mNoteEdit->hide();
- connect(mNoteEdit, &NoteEdit::createNote, this, &ViewerPluginCreatenoteInterface::slotCreateNote);
- parent->layout()->addWidget(mNoteEdit);
}
ViewerPluginCreatenoteInterface::~ViewerPluginCreatenoteInterface()
@@ -61,12 +57,12 @@ QList<QAction *> ViewerPluginCreatenoteInterface::actions() const
void ViewerPluginCreatenoteInterface::setMessage(const KMime::Message::Ptr &value)
{
- mNoteEdit->setMessage(value);
+ widget()->setMessage(value);
}
void ViewerPluginCreatenoteInterface::closePlugin()
{
- mNoteEdit->slotCloseWidget();
+ widget()->slotCloseWidget();
}
Akonadi::Relation ViewerPluginCreatenoteInterface::relatedNoteRelation() const
@@ -98,7 +94,7 @@ void ViewerPluginCreatenoteInterface::showWidget()
void ViewerPluginCreatenoteInterface::showCreateNewNoteWidget()
{
- mNoteEdit->showNoteEdit();
+ widget()->showNoteEdit();
}
void ViewerPluginCreatenoteInterface::slotNoteItemFetched(KJob *job)
@@ -113,7 +109,7 @@ void ViewerPluginCreatenoteInterface::slotNoteItemFetched(KJob *job)
showCreateNewNoteWidget();
} else {
Akonadi::NoteUtils::NoteMessageWrapper note(fetch->items().first().payload<KMime::Message::Ptr>());
- mNoteEdit->setMessage(note.message());
+ widget()->setMessage(note.message());
showCreateNewNoteWidget();
}
}
@@ -163,3 +159,16 @@ void ViewerPluginCreatenoteInterface::slotCreateNote(const KMime::Message::Ptr &
CreateNoteJob *createJob = new CreateNoteJob(notePtr, collection, mMessageItem, this);
createJob->start();
}
+
+NoteEdit *ViewerPluginCreatenoteInterface::widget()
+{
+ if (!mNoteEdit) {
+ QWidget *parentWidget = static_cast<QWidget *>(parent());
+ mNoteEdit = new NoteEdit(parentWidget);
+ connect(mNoteEdit, &NoteEdit::createNote, this, &ViewerPluginCreatenoteInterface::slotCreateNote);
+ mNoteEdit->setObjectName(QStringLiteral("noteedit"));
+ parentWidget->layout()->addWidget(mNoteEdit);
+ mNoteEdit->hide();
+ }
+ return mNoteEdit;
+}
diff --git a/plugins/messageviewerplugins/createnoteplugin/viewerplugincreatenoteinterface.h b/plugins/messageviewerplugins/createnoteplugin/viewerplugincreatenoteinterface.h
index 9fd1e79..613fe0d 100644
--- a/plugins/messageviewerplugins/createnoteplugin/viewerplugincreatenoteinterface.h
+++ b/plugins/messageviewerplugins/createnoteplugin/viewerplugincreatenoteinterface.h
@@ -49,6 +49,8 @@ private:
Akonadi::Relation relatedNoteRelation() const;
void showCreateNewNoteWidget();
void createAction(KActionCollection *ac);
+ NoteEdit *widget();
+
Akonadi::Item mMessageItem;
NoteEdit *mNoteEdit;
QList<QAction *> mAction;