Series Article Directory
提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加
For example: CC For Windows source code compilation
提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档
plug-in development
foreword
CC
The development of the software framework and plug-in functions is relatively flexible. This blog post records the development of plug-ins. Plug-ins are divided into three types, IO
, GL
and Standard
, and the differences between each type are not studied in detail. Today we mainly introduce Standard
the development of the following types of plug-ins.
1. Basics
CC
It is QT
developed based on . Therefore, before developing plug-ins, you need to have a proper understanding of the QT
relevant foundations. In fact, you don't need too much, as long as you can control the logical order and slot functions.
2. Example introduction
Inferring the operating mechanism from , there are four files in Example
the official website , which are:ExamplePlugin
ActionA.h
ActionA.cpp
ExamplePlugin.h
ExamplePlugin.cpp
Among them, ExamplePlugin.*
it is CC
coupled with the plug-in mechanism of . Generally, it does not need to be changed, because the purpose of making a plug-in is to expand the function. If the function to be extended is independent, then there is no need to change these two files. It is specific ActionA.*
. The implementation file can be simply understood as that CC
the plug-in mechanism will be called ExamplePlugin
, and then the functions implemented in it ExamplePlugin
will be triggered . The trigger command is:ActionA.*
// EaxmplePlugin.cpp
// This method returns all the 'actions' your plugin can perform.
// getActions() will be called only once, when plugin is loaded.
QList<QAction*> ExamplePlugin::getActions()
{
// default action (if it has not been already created, this is the moment to do it)
if (!m_action)
{
// Here we use the default plugin name, description, and icon,
// but each action should have its own.
m_action = new QAction(getName(), this);
m_action->setToolTip(getDescription());
m_action->setIcon(getIcon());
// Connect appropriate signal
connect(m_action, &QAction::triggered, this, [this]()
{
Example::performActionA(m_app); // 触发 ActionA的功能函数
});
}
return { m_action };
}
Statements that perform functionsExample::performActionA(m_app);
3. Realization
As of now, CC
the development of plug-ins can be reduced to QT
component development. Here, a simple pop-up window is introduced (it CC
may not be applicable to the standard plug-in process, but it can realize the function. It is not yet known what the bug is What).
First, ActionA.h
create a new class in , here, a SegDialog
class called is defined:
class SegDialog : public QDialog {
Q_OBJECT
public:
explicit SegDialog(ccMainAppInterface* appInterface = nullptr, QWidget* parent = nullptr);
~SegDialog() {};
private:
ccMainAppInterface* appInterface_;
}
Pay attention to the constructor and private variables. There is a ccMainAppInterfac
variable, which must not be omitted. This class includes some operations displayed on the interface, such as addDB, addPoint, etc., which can display your display results on the interface UI
.
Next, let's look at the implementation:
// ActionA.cpp
SegDialog::SegDialog(ccMainAppInterface* appInterface, QWidget* parent)
: appInterface_(appInterface), QDialog(parent) {
}
Just post the implementation of the constructor. As for how to design it, you can do whatever you want. When you get here, do you find it very familiar, usually when QT
designing independent pop-up windows, you can also use Dialog
this class.
After introducing the definition and implementation of the function, let's see how to trigger it:
void performActionA(ccMainAppInterface* appInterface)
{
SegDialog* pDlg = new SegDialog(appInterface);
pDlg->setMinimumSize(480, 640);
pDlg->setWindowTitle("Test Example");
pDlg->show();
}
Look, this function is the entry point of the call, and it is enough to performActionA
directly call the previously created class in it .SegDialog
4. Introduction of Attached Documents
ExamplePlugin
There is a info.json
file in , which stores some information of the plug-in, as follows:
{
"type": "Standard", # 说明插件类型,不用管
"name": "Segmentation Example (Standard Plugin)", # 插件的名字,即在CC中的显示名字
"icon": ":/CC/plugin/ExamplePlugin/images/icon.png", # logo,在CC中该插件的log
"description": "This is a description of the marvelous Example plugin. It does nothing.",
"authors": [
{
"name": "Daniel Girardeau-Montaut",
"email": "[email protected]"
}
],
"maintainers": [
{
"name": "Andy Maloney",
"email": "[email protected]"
},
{
"name": "Example NoEmail"
}
],
"references": [
{
"text": "The unsuccessful self-treatment of a case of “writer's block”",
"url": "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1311997/"
},
{
"text": "Sword swallowing and its side effects",
"url": "http://www.bmj.com/content/333/7582/1285"
},
{
"text": "I thought of creating this wonderful plugin while I was hiking up ⛰ Mont Blanc"
}
]
}
V. Summary
After reading the introduction, did you find that CC
the development of plug-ins is actually a process problem, and the real design and core is still in the QT
application.