|
|
To add a module the following steps are required
|
|
|
|
|
|
##### 1. Create the module folder
|
|
|
|
|
|
Create a folder inside the Module directory. The name of the folder is arbitrary but it is a good practice to name it with the module name.
|
|
|
|
|
|
##### 2. Create the module class
|
|
|
|
|
|
Create a class that will inherit from the abstract Module class and creates a UI class that will inherit from the QWidget class. These two classes can coincide, in this case, you can directly inherit from the DefaultModule class.
|
|
|
|
|
|
##### 3. Insert the ModuleId
|
|
|
|
|
|
Go to the ModuleInfo class and add a unique ID inside the ModuleId enum.
|
|
|
|
|
|
##### 4. Add the module to the module factory
|
|
|
|
|
|
Go to the ModulesList class and in the createModuleList() method append the following code
|
|
|
|
|
|
```plaintext
|
|
|
1. #ifdef <YOURMODULE_H>
|
|
|
2. ModuleInfo yourmodule(ModuleId::<module id>, "<modulename>", ModuleCategory::<chosen category>);
|
|
|
3. yourmodule.setFactory([](){return new MyModuleConstructure();});
|
|
|
4. yourmodule.addModuleSourceFiles("Modules/<your module folder>/");
|
|
|
5. addModuleInfo(yourmodule);
|
|
|
6. #endif
|
|
|
```
|
|
|
|
|
|
You can check the <YOURMODULE_H> variable in the top part of the .h file of your module.
|
|
|
|
|
|
With the line 2. you are creating a ModuleInfo variable that associate the module id with its name. The name will be the same displayed in the PickModulePanel and saved inside the XML configuration file. The Category will determine in which area of the module picker panel will be the button to instantiate the module.
|
|
|
|
|
|
With line 3. you are specifying the factory method to instantiate your module class. It can be a lambda that calls the class constructor.
|
|
|
|
|
|
With line 4. the module folder created at the first step is specified. This information will be used from the SkywardHub compiler for the auto-deployment feature.
|
|
|
|
|
|
##### 5. Overrides the module abstract methods
|
|
|
|
|
|
In order to implement the module class, you have to override the following three public abstract methods:
|
|
|
|
|
|
```plaintext
|
|
|
QWidget *toWidget() override;
|
|
|
XmlObject toXmlObject() override;
|
|
|
void fromXmlObject(const XmlObject &xmlObject) override;
|
|
|
```
|
|
|
|
|
|
The method toWidget() allows you to specify which View will be displayed as a panel inside the MainWindow. It is a good practice to create a view class and a model class that implements the logic. However, if the view and the model coincide, you can simply return this.
|
|
|
|
|
|
The toXmlObject and fromXmlObject specify methods to serialize the current model into an XML file to save and restore the configuration. If you do not have any data to save in the xml file, in the toXmlObject() method you can simply return the name of the current model.
|
|
|
|
|
|
Take as example the following code. Please remind that you should use the ModuleId you created in the previous step.
|
|
|
|
|
|
```plaintext
|
|
|
XmlObject<your module class>::toXmlObject(){
|
|
|
return XmlObject(getName(ModuleId::<your module id>));
|
|
|
}
|
|
|
```
|
|
|
|
|
|
While the fromXmlObject() can be left empty if you do not need to store any data in the xml.
|
|
|
|
|
|
##### Using the default context menu
|
|
|
|
|
|
At this point the module is created and insert inside the SkywardHub.
|
|
|
|
|
|
If you inherited from DefaultModule and you want to use the default options for the context menu add in the constructor the following line of code: defaultContextMenuSetup(); as in the following example.
|
|
|
|
|
|
```plaintext
|
|
|
EmptyModule::EmptyModule() : DefaultModule(), ui(new Ui::EmptyModule)
|
|
|
{
|
|
|
ui->setupUi(this);
|
|
|
defaultContextMenuSetup();
|
|
|
}
|
|
|
```
|
|
|
|
|
|
After this, to add QActions at the context menu override the method void addCustomActionsToMenu() override; as in the following example
|
|
|
|
|
|
```plaintext
|
|
|
void TableModule::addCustomActionsToMenu()
|
|
|
{
|
|
|
QAction* action= new QAction("<Action Name>");
|
|
|
connect(action, &QAction::triggered, this, &TableModule::onActionClicked);
|
|
|
|
|
|
addActionToMenu(action);
|
|
|
}
|
|
|
``` |
|
|
\ No newline at end of file |