Read only display widgets in the Workspace editor

December 9th, 2016

One of many improvements that will be introduced with Workspace 4.0 is “read only mode” for all display widgets which Workspace will automatically toggle when the underlying data is not available for modification. Consider the following scenario using version 3.5.1 of the Workspace editor.

Using a StringsConcatenator, LogText and WorkspaceOutput operation, let’s create a simple “Hello World!” workflow.

read-only-display-widgets-1

So far so good. Now let’s select the LogText operation to have a look at it’s input QString value which should be empty if you haven’t executed your workflow yet.

read-only-display-widgets-2

Now let’s try setting a string value and executing the workflow to see what happens.

read-only-display-widgets-3

Oh no! Our string value has disappeared… it appears that a nefarious upstream StringsConcatenator operation has overwritten our value. This is very sad indeed, but rest assured that this won’t happen in Workspace 4.0. We’ve done some work under the hood so that widgets are automatically set to read only mode when they’re attached to an operation input which itself is connected to an upstream operation. This change also applies to all operation outputs whether or not they’re connected because outputs are typically overwritten on each re-execution of an operation.

read-only-display-widgets-4

We’ve also added a handy little indicator icon next to input and output labels for visual assistance purposes!

So as a Workspace plugin developer, how does this change affect you? Well, by default widgets defined within your own Workspace plugins will be disabled in the Workspace editor when they are attached to a connected input or any output. You can however override this default read only behaviour by implementing a new virtual method in your QWidgetConnector classes. The following code snippets show you how:

myspecialwidgetconnector.h

class MySpecialWidgetConnector : public CSIRO::Widgets::QWidgetConnector
{
public:
    virtual void setWidgetReadOnly(bool b);
};

myspecialwidgetconnector.cpp

void MySpecialWidgetConnector::setWidgetReadOnly(bool b)
{
    MySpecialWidget* mySpecialWidget = qobject_cast<MySpecialWidget*>(&getWidget());
    assert(mySpecialWidget);

    // You will most likely need to define your own setReadOnly method within your widget class.
    mySpecialWidget->setReadOnly(b);
}

On the other hand, if your widget is inherently read only (such as an image display widget) you may want to override the setWidgetReadOnly() method to do nothing at all:

myspecialwidgetconnector.cpp

void MySpecialWidgetConnector::setWidgetReadOnly(bool b)
{
    // This macro will keep your compiler quiet!
    Q_UNUSED(b);
}

Some general guidelines for widget read only customisations:

  • Most Qt widgets already provide methods to toggle read only behaviour. As usual, check the Qt docs first!
  • It may be worth considering hiding certain sub-components of your widget when in read only mode. An example may be a QPushButton that appends items to a sibling list widget. Such a button would be best hidden in read only mode.
  • Ensure that your widgets provide essential interactivity whether in read only mode or not. A user should always be able to scroll up and down within a QTableView widget even if the cells are non-editable.

Happy Workspacing!