• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Product
    • Design UI
    • Develop
    • Analyze and test
    • Deploy
    • Framework and toolbox
    • Compatibility
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • GUI - CDP Widgets
  • CDPBaseUiLoaderWidget

CDPBaseUiLoaderWidget Class

The UI Loader Widget class loads form (.ui) files dynamically and includes functionality to replace routings in real time. More...

Header: #include <CDPBaseWidgets/CDPBaseUiLoaderWidget.h>
Inherits: DialogLoader and
  • List of all members, including inherited members

Public Types

typedef ComRoutingsMap
typedef ICDPRoutingsMap

Properties

  • cdpSelectReplacementRouting : QString
  • uiFileName : QString

Public Functions

CDPBaseUiLoaderWidget(QWidget *parent = 0)
QString replacementIndexRouting()
void setReplacementIndexRouting(const QString &routing)
void setUiFileName(const QString &filename)
  • 11 public functions inherited from DialogLoader

Public Slots

void setRoutingReplacement(const QString &replaceable)
void setRoutingReplacement(int dynamicRouting)
void setRoutingReplacement(double dynamicRouting)

Signals

void clicked()

Protected Functions

void mapRoutedObjectsThatContainString(const QString &replaceable, QObject *mainObject)
void replaceRoutingsInMappedObjects()

Protected Slots

virtual void showDialog(bool show = true)

Detailed Description

The UI Loader Widget class loads form (.ui) files dynamically and includes functionality to replace routings in real time.

The routing replacement functionality allows one form file to show data from different systems by the click of a button. Routings can be changed either by providing replacement strings to the slot named setRoutingReplacement(QString) or by configuring replacement strings as dynamic properties on the following format:

stringReplacement1="$(REPLACE1)=Replacement1;$(REPLACE2)=OtherReplacement1"
stringReplacement2="$(REPLACE1)=Replacement2;$(REPLACE2)=OtherReplacement2"

You can provide any number of replacements separated by ";". The replacements are added by first specifying the string that are to be replaced in the routings, followed by an equal sign and then the string that we want to replace it with (e.g. $(COMPONENT)=Pump1).

The dynamic properties must be named stringReplacement followed by a number. After configuring the properties, providing the numbers to the slot named setRoutingReplacement(int) or setRoutingReplacement(double) will select the routing replacements. It is also possible to control this using a cdp object by adding routing to the property named cdpSelectReplacementRouting.

The replacements strings are executed on the routings from left to right. The order of the first replacements will be used in all consecutive replacements. Meaning, that if stringReplacement2 in the above example had $(REPLACE2) as its first replacement, it would still be executed after $(REPLACE1) as this is the order used in stringReplacement1. The same goes if the replacements are added using setRoutingReplacement(QString).

To avoid broken routings in the application, the template variables need to be wrapped in $(). The alternative is to ensure that the initial routings are valid (e.g. use MyComp1 instead of $(REPLACE1) in the above example and then use MyComp1=MyComp2 in stringReplacement2 etc.).

Note: Make sure that all objects that are connected using signals and slots have unique names across .ui files. Failing to do so might cause source objects to connect wrong targets. In addition, be aware that connections are error prone when maintaining projects as they are not visible in normal mode and not possible to copy.

Example

The following example discuss the different use cases of the CDPBaseUiLoaderWidget. Each section add more functionality.

How to load a form within a form

A simple example of using the CDPBaseUiLoaderWidget is to create two form files, main.ui and load.ui. The main form is typically based on CDPBaseMainWindow and the second one is usually based on a standard QWidget. Add a CDPBaseUiLoaderWidget to the main form and make it load the load.ui form by editing the property named, uiFileName. The load.ui file must be added as a resource, be in the studio working directory or include full path to show in studio. The first option is usually the best one.

How to replace routings in a loaded form

Start by adding a CDPBaseMeter to the load.ui form and add the following routing to the cdpRouting property; AppName.$(SIGNAL).Value. In this string, the word $(SIGNAL) is what we want to replace. Replace AppName with the name of your application if it is named differently.

Next, we need to setup the replacement strings on the CDPBaseUiLoaderWidget in the main.ui form. Create a dynamic property by clicking on the plus icon next to the filter in the property panel and select String.... Name the property stringReplacement1 and repeat the steps to create a second property named stringReplacement2. Add the following value in the first property $(SIGNAL)=CPULoad and add $(SIGNAL)=MemUsedRelative to the second one.

Now, when the CDPBaseUiLoaderWidget receives the value 1 or 2, either by setRoutingReplacement slot or by adding routing in the property named cdpSelectReplacementRouting, the CDPBaseMeter will show CPULoad or MemUsedRelative respectively.

Member Type Documentation

typedef CDPBaseUiLoaderWidget::ComRoutingsMap

typedef CDPBaseUiLoaderWidget::ICDPRoutingsMap

Property Documentation

cdpSelectReplacementRouting : QString

This property holds the routing to the cdp object that are to control the index of the replacement strings to use on the loaded ui.

See the class details for more information about template variables and replacement strings.

Access functions:

QString replacementIndexRouting()
void setReplacementIndexRouting(const QString &routing)

uiFileName : QString

This property holds the path to the dialog we want to load when clicking the button.

Note: Make sure that all objects that are connected using signals and slots have unique names across .ui files. Failing to do so might cause source objects to connect wrong targets. In addition, be aware that connections are error prone when maintaining projects as they are not visible in normal mode and not possible to copy.

Access functions:

void setUiFileName(const QString &filename)

Member Function Documentation

CDPBaseUiLoaderWidget::CDPBaseUiLoaderWidget(QWidget *parent = 0)

Default constructs an instance of CDPBaseUiLoaderWidget.

[signal] void CDPBaseUiLoaderWidget::clicked()

[protected] void CDPBaseUiLoaderWidget::mapRoutedObjectsThatContainString(const QString &replaceable, QObject *mainObject)

[protected] void CDPBaseUiLoaderWidget::replaceRoutingsInMappedObjects()

[slot] void CDPBaseUiLoaderWidget::setRoutingReplacement(const QString &replaceable)

[slot] void CDPBaseUiLoaderWidget::setRoutingReplacement(int dynamicRouting)

[slot] void CDPBaseUiLoaderWidget::setRoutingReplacement(double dynamicRouting)

[virtual protected slot] void CDPBaseUiLoaderWidget::showDialog(bool show = true)

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

    © Copyright 2022 CDP Technologies. Privacy and cookie policy.

    Return to top