• 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

  • Doc
  • 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
  • ResourceHandler

ResourceHandler Class

The ResourceHandler class provides functionality to handle custom resources within studio design mode. More...

Header: #include <CDPBaseWidgets/ResourceHandler.h>
  • List of all members, including inherited members

Public Functions

ResourceHandler(ParserSVG *svg = 0)
bool addPropertyToExecuteAfterTimedSvg(const QString &name, const QVariant &value, int postfix = 0)
void setParser(ParserSVG *svg)
virtual void setSvgFile(QString svg)

Static Public Members

int waitMs()
int waitOrderMs()

Protected Functions

virtual void processQueuedProperties()
virtual void processSvgFile(QString svgFile) = 0

Detailed Description

The ResourceHandler class provides functionality to handle custom resources within studio design mode.

Resource handling in design mode is required as resource files added to the project is not available when the form is loaded. Most of the widgets create pixmaps to minimize painting operations in the paintEvent. Hence, when the resource is not found, the widget will paint the fallback resource instead of the one you actually wanted. Adding an initial delay as provided by this class should ensure that the resource is available and ready for use.

Some widgets require multiple functions to be timed. In that scenario, the timeout values of this class can be used directly instead of implementing the virtual functions.

Also, widgets that calculate size based on resources will get wrong initial size and show default/wrong graphics while being dragged from the widget panel. To solve this, the widget needs to set the resource just before the sizeHint function is executed. At this point the resource is most likely, but not always, available. Hence, only executing resource loading functions from the sizeHint function is not enough. The timers are required in addition.

QSize CDPBaseSlider::sizeHint() const
{
  if(m_svg.svgOutOfDate())
    const_cast<CDPBaseSlider*>(this)->processSvgFile(m_svg.svgFileName());
  ...

The timeouts can be overrided by placing a file, resourcehandler.ini, in the studio working directory. To change the timeouts used when running an application, place the file in the Application directory next to the executable. The file contains a main waiting time and a timeout to ensure that timeouts follow a specific order:

WaitMs = 1500
WaitOrderMs = 500

Member Function Documentation

ResourceHandler::ResourceHandler(ParserSVG *svg = 0)

Default constructs an instance of ResourceHandler.

bool ResourceHandler::addPropertyToExecuteAfterTimedSvg(const QString &name, const QVariant &value, int postfix = 0)

Add properties to queue if SVG timer is running.

This ensures that properties are executed in correct order after svgFile is executed. The property name and value is provided in the name and value arguments. Use the postfix argument to add a postfix number greater than zero to the property name.

Returns true if the property was added to the execution queue. A false return value means that the timer is not running and can be executed directly. The function will not set the property after returning false.

[virtual protected] void ResourceHandler::processQueuedProperties()

[pure virtual protected] void ResourceHandler::processSvgFile(QString svgFile)

Function that is executed after a timeout to ensure that the resource is available when it is run. This is where you will typically also execute loading of pixmaps. The svgFile argument contains the full svg file name.

void ResourceHandler::processSvgFile(QString svgFile)
{
  if (m_svg.updateRequired(svgFile, this))
  {
    m_svg = m_svg.parseSvg(svgFile);
    ...
  }
}

void ResourceHandler::setParser(ParserSVG *svg)

[virtual] void ResourceHandler::setSvgFile(QString svg)

[static] int ResourceHandler::waitMs()

[static] int ResourceHandler::waitOrderMs()

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

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2024 CDP Technologies. Privacy and cookie policy.

Return to top