Workspace 6.21.5
Including plugin-specific licenses

Introduction

In this tutorial we will show you how to add a plugin license or a license for an external library so that it will be displayed in Workspace.

By the end of the tutorial we will:

  • Understand how to add a plugin license or a license for an external library to your Workspace plugin code

Prerequisites


Contents


Sample files used and modified in this tutorial

Adding a plugin license

Create the Licenses subdirectory

  • Create a subdirectory in your plugin directory called Licenses
    Licenses subdirectory in your plugin directory

Create and edit license file

  • Add a text file to the Licenses directory. Call it license.txt.
    Create license file
  • Open license.txt in your favourite text editor and copy the appropriate license text to it.
  • In this example, we will place some dummy text in the license file. Copy the following to license.txt and save the file.
    -- This is a dummy license file
    -- Please replace the text with the appropriate license text you want to display
    

Create and edit resource file

  • Create a Qt resource file called license_resources.qrc in the Licenses directory
    Create Qt resource file
  • Add the following text to license_resources.qrc:
    <RCC>
        <qresource prefix="/SimplePluginLicense/Licenses">
            <file>license.txt</file>
        </qresource>
    </RCC>
    
Note
Your plugin folder may have a different name. The format is:
<qresource prefix="/<your plugin directory name>/Licenses">

Create and edit CMakeLists.txt file

  • In the Licenses directory, add a CMakeLists.txt file
    Create CMakeLists.txt file
  • Add the following text to CMakeLists.txt:
    list(APPEND RESOURCES ${SIMPLEPLUGIN_SOURCE_DIR}/Licenses/license_resources.qrc)
    

Modify the top-level CMakeLists.txt file

  • In the top-level plugin directory, there is another CMakeLists.txt file. Add the following lines to that CMakeLists.txt:
    set(RESOURCES "")
    include(${SIMPLEPLUGIN_SOURCE_DIR}/Licenses/CMakeLists.txt)
    
  • Add ${RESOURCES} to the target library in add_library:
    add_library(simplepluginlicenseplugin ${SOURCES} ${HEADERS} ${MOC_SOURCES} ${UIC_SOURCES} ${RES_SOURCES} ${RESOURCES})
    
  • After the additions, the top-level CMakeLists.txt should look something like:
    set(UI_SOURCES
    )
    set(RESOURCES "")
    include(${SIMPLEPLUGINLICENSEPLUGIN_SOURCE_DIR}/Licenses/CMakeLists.txt)
    add_definitions(-DSIMPLEPLUGINLICENSEPLUGIN_VERSION=${SIMPLEPLUGINLICENSEPLUGIN_VERSION})
    # The next line is used by the simple application generator wizard
    # add_subdirectory(${SIMPLEPLUGINLICENSEPLUGIN_SOURCE_DIR}/Application)
    # The below line can be used to import sub-directories
    include( ${SIMPLEPLUGINLICENSEPLUGIN_SOURCE_DIR}/Collection/CMakeLists.txt )
    # qtx macros are defined in the ${WORKSPACE_CMAKE_ROOT}/CMakeLists.txt included at the top of this file
    # to support both Qt4 and Qt5 builds.
    qtx_wrap_ui(UIC_SOURCES ${UI_SOURCES})
    qtx_add_resources(RES_SOURCES ${RESOURCES})
    add_library(simplepluginlicenseplugin ${SOURCES} ${HEADERS} ${MOC_SOURCES} ${UIC_SOURCES} ${RES_SOURCES} ${RESOURCES})

Modify the plugin header file

  • In the plugin header file, add the following in the public section:
    QStringList getLicensePaths() const;
    QStringList
    Definition: vectornumbertostringlistadaptor.cpp:133

Modify the plugin .CPP file

  • In the plugin CPP file, add:
    QStringList SimplePluginLicensePlugin::getLicensePaths() const
    {
    return { ":/SimplePluginLicense/Licenses/license.txt" };
    }

Rebuild the code


View the added plugin license in %Workspace

  • To view the plugin license, launch Workspace Editor.
  • Navigate to Help --> About Workspace...
  • In the "About Workspace" dialog box, click on "Show licenses"
  • Select your newly added plugin license in the "View license for:" drop-down list. In this example that is "license (Used in SimplePluginLicense plugin)"
View plugin license