aboutsummaryrefslogtreecommitdiffstats
path: root/doc/qtcreatordev/examples/exampleplugin
diff options
context:
space:
mode:
authorLeena Miettinen <riitta-leena.miettinen@qt.io>2020-01-23 11:45:07 +0100
committerLeena Miettinen <riitta-leena.miettinen@qt.io>2020-01-27 09:05:07 +0000
commit5fc456dd2283b2d1e6c4e6d34856052658f34cc4 (patch)
tree7a7cd26a33014e401536a149fa47f6586b68c247 /doc/qtcreatordev/examples/exampleplugin
parentc9f90047ac701416e439f492069c1a0bb364fc08 (diff)
Doc: Rearrange files in the doc folder
Source and configuration files for each manual are now located in a separate subdirectory, with common configuration files in doc/config. doc |_config |_qtcreator |_qtcreatordev |_qtdesignstudio Edit the config files accordingly. Change-Id: Idc747a7c16e84f3e06add91234dc5fc908e64cc5 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'doc/qtcreatordev/examples/exampleplugin')
-rw-r--r--doc/qtcreatordev/examples/exampleplugin/Example.json.in18
-rw-r--r--doc/qtcreatordev/examples/exampleplugin/example.pro59
-rw-r--r--doc/qtcreatordev/examples/exampleplugin/example_global.h9
-rw-r--r--doc/qtcreatordev/examples/exampleplugin/exampleconstants.h10
-rw-r--r--doc/qtcreatordev/examples/exampleplugin/exampleplugin.cpp86
-rw-r--r--doc/qtcreatordev/examples/exampleplugin/exampleplugin.h36
6 files changed, 218 insertions, 0 deletions
diff --git a/doc/qtcreatordev/examples/exampleplugin/Example.json.in b/doc/qtcreatordev/examples/exampleplugin/Example.json.in
new file mode 100644
index 00000000000..12b8bc37a0e
--- /dev/null
+++ b/doc/qtcreatordev/examples/exampleplugin/Example.json.in
@@ -0,0 +1,18 @@
+{
+//! [1]
+ \"Name\" : \"Example\",
+ \"Version\" : \"0.0.1\",
+ \"CompatVersion\" : \"0.0.1\",
+//! [1]
+//! [2]
+ \"Vendor\" : \"My Company\",
+ \"Copyright\" : \"(C) My Company\",
+ \"License\" : \"BSD\",
+ \"Category\" : \"Examples\",
+ \"Description\" : \"Minimal plugin example.\",
+ \"Url\" : \"http://www.mycompany.com\",
+//! [2]
+//! [3]
+ $$dependencyList
+//! [3]
+}
diff --git a/doc/qtcreatordev/examples/exampleplugin/example.pro b/doc/qtcreatordev/examples/exampleplugin/example.pro
new file mode 100644
index 00000000000..c100894b7ba
--- /dev/null
+++ b/doc/qtcreatordev/examples/exampleplugin/example.pro
@@ -0,0 +1,59 @@
+#! [1]
+DEFINES += EXAMPLE_LIBRARY
+#! [1]
+
+# Example files
+
+#! [2]
+SOURCES += exampleplugin.cpp
+
+HEADERS += exampleplugin.h \
+ example_global.h \
+ exampleconstants.h
+#! [2]
+
+# Qt Creator linking
+
+#! [3]
+## set the QTC_SOURCE environment variable to override the setting here
+QTCREATOR_SOURCES = $$(QTC_SOURCE)
+isEmpty(QTCREATOR_SOURCES):QTCREATOR_SOURCES=/Users/example/qtcreator-src
+
+## set the QTC_BUILD environment variable to override the setting here
+IDE_BUILD_TREE = $$(QTC_BUILD)
+isEmpty(IDE_BUILD_TREE):IDE_BUILD_TREE=/Users/example/qtcreator-build
+#! [3]
+
+#! [4]
+## uncomment to build plugin into user config directory
+## <localappdata>/plugins/<ideversion>
+## where <localappdata> is e.g.
+## "%LOCALAPPDATA%\QtProject\qtcreator" on Windows Vista and later
+## "$XDG_DATA_HOME/data/QtProject/qtcreator" or "~/.local/share/data/QtProject/qtcreator" on Linux
+## "~/Library/Application Support/QtProject/Qt Creator" on Mac
+# USE_USER_DESTDIR = yes
+#! [4]
+
+#! [5]
+###### If the plugin can be depended upon by other plugins, this code needs to be outsourced to
+###### <dirname>_dependencies.pri, where <dirname> is the name of the directory containing the
+###### plugin's sources.
+
+QTC_PLUGIN_NAME = Example
+QTC_LIB_DEPENDS += \
+ # nothing here at this time
+
+QTC_PLUGIN_DEPENDS += \
+ coreplugin
+
+QTC_PLUGIN_RECOMMENDS += \
+ # optional plugin dependencies. nothing here at this time
+
+###### End _dependencies.pri contents ######
+#! [5]
+
+#![6]
+include($$QTCREATOR_SOURCES/src/qtcreatorplugin.pri)
+
+#![6]
+
diff --git a/doc/qtcreatordev/examples/exampleplugin/example_global.h b/doc/qtcreatordev/examples/exampleplugin/example_global.h
new file mode 100644
index 00000000000..00c77e6b162
--- /dev/null
+++ b/doc/qtcreatordev/examples/exampleplugin/example_global.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include <QtGlobal>
+
+#if defined(EXAMPLE_LIBRARY)
+# define EXAMPLESHARED_EXPORT Q_DECL_EXPORT
+#else
+# define EXAMPLESHARED_EXPORT Q_DECL_IMPORT
+#endif
diff --git a/doc/qtcreatordev/examples/exampleplugin/exampleconstants.h b/doc/qtcreatordev/examples/exampleplugin/exampleconstants.h
new file mode 100644
index 00000000000..fced2e04295
--- /dev/null
+++ b/doc/qtcreatordev/examples/exampleplugin/exampleconstants.h
@@ -0,0 +1,10 @@
+#pragma once
+
+namespace Example {
+namespace Constants {
+
+const char ACTION_ID[] = "Example.Action";
+const char MENU_ID[] = "Example.Menu";
+
+} // namespace Example
+} // namespace Constants
diff --git a/doc/qtcreatordev/examples/exampleplugin/exampleplugin.cpp b/doc/qtcreatordev/examples/exampleplugin/exampleplugin.cpp
new file mode 100644
index 00000000000..5adc093c46d
--- /dev/null
+++ b/doc/qtcreatordev/examples/exampleplugin/exampleplugin.cpp
@@ -0,0 +1,86 @@
+#include "exampleplugin.h"
+#include "exampleconstants.h"
+
+#include <coreplugin/icore.h>
+#include <coreplugin/icontext.h>
+#include <coreplugin/actionmanager/actionmanager.h>
+#include <coreplugin/actionmanager/command.h>
+#include <coreplugin/actionmanager/actioncontainer.h>
+#include <coreplugin/coreconstants.h>
+
+#include <QAction>
+#include <QMessageBox>
+#include <QMainWindow>
+#include <QMenu>
+
+#include <QtPlugin>
+
+namespace Example {
+namespace Internal {
+
+ExamplePlugin::ExamplePlugin()
+{
+ // Create your members
+}
+
+ExamplePlugin::~ExamplePlugin()
+{
+ // Unregister objects from the plugin manager's object pool
+ // Delete members
+}
+
+bool ExamplePlugin::initialize(const QStringList &arguments, QString *errorString)
+{
+ // Register objects in the plugin manager's object pool
+ // Load settings
+ // Add actions to menus
+ // Connect to other plugins' signals
+ // In the initialize function, a plugin can be sure that the plugins it
+ // depends on have initialized their members.
+
+ Q_UNUSED(arguments)
+ Q_UNUSED(errorString)
+
+//! [add action]
+ QAction *action = new QAction(tr("Example Action"), this);
+ Core::Command *cmd = Core::ActionManager::registerAction(action, Constants::ACTION_ID,
+ Core::Context(Core::Constants::C_GLOBAL));
+ cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Meta+A")));
+ connect(action, &QAction::triggered, this, &ExamplePlugin::triggerAction);
+//! [add action]
+//! [add menu]
+ Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::MENU_ID);
+ menu->menu()->setTitle(tr("Example"));
+ menu->addAction(cmd);
+ Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu);
+//! [add menu]
+
+ return true;
+}
+
+void ExamplePlugin::extensionsInitialized()
+{
+ // Retrieve objects from the plugin manager's object pool
+ // In the extensionsInitialized function, a plugin can be sure that all
+ // plugins that depend on it are completely initialized.
+}
+
+ExtensionSystem::IPlugin::ShutdownFlag ExamplePlugin::aboutToShutdown()
+{
+ // Save settings
+ // Disconnect from signals that are not needed during shutdown
+ // Hide UI (if you add UI that is not in the main window directly)
+ return SynchronousShutdown;
+}
+
+//! [slot implementation]
+void ExamplePlugin::triggerAction()
+{
+ QMessageBox::information(Core::ICore::mainWindow(),
+ tr("Action Triggered"),
+ tr("This is an action from Example."));
+}
+//! [slot implementation]
+
+} // namespace Internal
+} // namespace Example
diff --git a/doc/qtcreatordev/examples/exampleplugin/exampleplugin.h b/doc/qtcreatordev/examples/exampleplugin/exampleplugin.h
new file mode 100644
index 00000000000..e858e92180d
--- /dev/null
+++ b/doc/qtcreatordev/examples/exampleplugin/exampleplugin.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "example_global.h"
+
+#include <extensionsystem/iplugin.h>
+
+//! [namespaces]
+namespace Example {
+namespace Internal {
+//! [namespaces]
+
+//! [base class]
+class ExamplePlugin : public ExtensionSystem::IPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Example.json")
+//! [base class]
+
+public:
+ ExamplePlugin();
+ ~ExamplePlugin();
+
+//! [plugin functions]
+ bool initialize(const QStringList &arguments, QString *errorString);
+ void extensionsInitialized();
+ ShutdownFlag aboutToShutdown();
+//! [plugin functions]
+
+//! [slot]
+private:
+ void triggerAction();
+//! [slot]
+};
+
+} // namespace Internal
+} // namespace Example