VR-Vantage
Loading...
Searching...
No Matches
exampleHumbleDialog

Overview

This tutorial shows how to add a custom dialog-page to the application GUI using a plug-in.

Expected Result

Humble Dialog Result

Example details

For this tutorial a brief explanation of the structure of the dialogs in VR-Vantage is useful. The GUI has a 'standard' dialog structure that is used throughout the application. The dialog is a floating GUI object with a frame, a title, a collection of pages (only one shown at a time), a list of tabs per page, and at least one button (a cancel or close button). It is the collection of pages that make up the content of the dialog. Each page generally provides the specific GUI elements related to a function, configuration or settings. The different pages of a single dialog usually are related in some way. The layout of each page in the application is usually a single widget (which contains all the GUI elements as its children) or the widget and a toolbar. The toolbar usually contains tools for saving and retrieving the settings of the widget. This tutorial does not include a toolbar. Look to exampleDialogPage for an example using the persistence toolbar.

VR-Vantage uses the Humble Dialog Pattern when creating the contents of each page. Don't confuse the Humble Dialog Pattern with the Dialog; the application uses this pattern for the contents of the pages. The Humble Dialog Pattern is a form of Model-View-Controller and is used to separate the front-end GUI elements from the implementation of the back-end logic that performs a task. As such, it is the widget object in the page that provides the front-end GUI elements. The page also manages a logic object that is independent of the GUI. Some of the benefits of the Humble Dialog Pattern are that the GUI and logic objects could be changed independently of each other, and that automated testing doesn't require a GUI to test the logic. The cost is that the GUI and logic are in at least two different classes making the code a little more complex.

To employ the Humble Dialog Pattern, the application creates an abstract interface class for each widget, which the widget class is derived from. It is important that the interface class provides a Non-GUI specific interface. That is, external objects can connect with, receive messages from and send messages to the interface without knowing how the underlying GUI was implemented. The logic class can then connect to and communicate with the widget through the interface without knowing about the widget. Generally each page in the dialog creates its specific widget object when the page is constructed. When the page is made active (made visible to the user) the page constructs the logic object and connects the logic to the widget's interface. When the page is deactivated (hidden from the user) it disconnects and tears down the logic object. When the page is destroyed, the widget is destroyed.

So to sum up, the general VR-Vantage dialog is a collection of pages (showing only one page at a time). Each page manages a GUI widget object and a logic object. The widget object is derived from a Non-GUI interface which the logic object uses to communicate with the widget.

The Widget, The Logic and The Interface

For this tutorial, the task to perform is pretty simple; take a user input string and print it to the console. For user-input there is a widget-object containing a textbox and a label. The user can type text into the textbox. When the user presses the Return or Enter key, the text is sent to a logic-object. The logic-object prints the text to the console, then tells the widget-object to clear the textbox. To keep the logic independent of how the widget is implemented, the logic will only communicate to the widget through a Non-GUI interface. This interface is declared as an abstract class in the HumbleDialogWidgetInterface.h file.

Interface for the HumbleDialogWidget. This class defines the implementation-agnostic interface for th...
Definition HumbleDialogWidgetInterface.h:25
{
public:
virtual void setText(const std::string& text) = 0;
virtual void setText(const std::string &text)=0
Called by the logic to set the text in the widget.
makVrv::vrvSignalsLib::signal<void (const std::string& text)> signal_processText;
makVrv::vrvSignalsLib::signal< void(const std::string &text)> signal_processText
Signal emitted when the user changes the text in the widget then presses the [Return] or [Enter] key....
Definition HumbleDialogWidgetInterface.h:34
};

The interface class declares two functions: a pure virtual setText() and a boost signal signal_processText. The setText() is the input to the widget that the logic-object will call to clear the textbox. The signal_processText signal is the output from the widget which tells the logic-object to print the text. The widget is derived from the interface class in the HumbleDialogWidget.h file.

Being a GUI object, the widget class is derived from both the interface defined above and a QWidget.

The main widget for the HumbleDialogPage. This class does not contain any application logic,...
Definition HumbleDialogWidget.h:34
: public QWidget
{
Q_OBJECT
public:
HumbleDialogWidget(QWidget* parent = 0, Qt::WindowFlags f = Qt::Widget);
HumbleDialogWidget(QWidget *parent=0, Qt::WindowFlags f=Qt::Widget)
CTOR.
virtual ~HumbleDialogWidget()
Virtual DTOR.

The widget must implement the pure virtual function inherited from its interface base class. The implementation of this function just set a child textbox to display the given string.

virtual void setText(const std::string& text);
virtual void setText(const std::string &text)
Sets the text in the QLineEdit widget. Calling this function does not cause any signals to be emitted...

The widget inherits a boost signal from its interface base class, but it also has its own Qt slot for catching Qt signals from its own child textbox. The implementation of this slot simply reads the contents of the textbox, then sends a boost signal.

public slots:
void slot_onReturnPressed()
Called when the user presses the Return or Enter key while changing text in the QLineEdit widget....

Last, the widget keeps a handle to its child textbox.

private:
QLineEdit * myTextBox
Definition HumbleDialogWidget.h:59
};

During construction of the widget object, the widget creates the textbox (making itself the textbox's parent), then it connects the returnPressed() Qt signal of the textbox to the widget's own slot_onReturnPressed() Qt slot.

: QWidget(parent, f)
, myTextBox(0)
{
myTextBox = new QLineEdit(this);
connect(
myTextBox, SIGNAL(returnPressed()),
this, SLOT(slot_onReturnPressed()) );
}

When the Qt slot of the widget receives a signal that the user pressed the Return or Enter key, the slot just turns around and sends the contents of the textbox out the boost signal.

{
signal_processText(myTextBox->text().toStdString());
}

When the widget is called to set the text of the textbox, it just converts the text from an std::string to a QString and writes it into the textbox.

void HumbleDialogWidget::setText(const std::string& text)
{
myTextBox->setText(QString::fromStdString(text));
}

The logic is declared as a simple class that takes an interface in its constructor. It also has a function that gets connected to the interface's boost signal to process the text. To help with managing the boost connection the logic class contains a DtSignalConnectionManager. The DtSignalConnectionManager is only used to automatically disconnect the logic's slot from the interface's boost signal. Without the connection-manager, the logic class would need to manually disconnect from the interface when the logic is destroyed.

The logic for the HumbleDialogWidget. This class does not have knowledge about how the widget was imp...
Definition HumbleDialogLogic.h:28
{
public:
HumbleDialogLogic(HumbleDialogWidgetInterface &iFace)
At construction time, this logic is connected to the boost::signals of the widget-interface to receiv...
void slot_processText(const std::string& text);
void slot_processText(const std::string &text)
Called when the user presses Return or Enter in the widget. When signaled the given text is simply pr...
private:
HumbleDialogWidgetInterface & myInterface
Definition HumbleDialogLogic.h:50
makVrv::DtSignalConnectionManager myConnections
Definition HumbleDialogLogic.h:51
Class to manage disconnection of boost connections on deletion.
Definition DtSignalConnectionManager.h:21
};

During construction the logic object is given an interface to connect with.

: myInterface(iFace)
, myConnections()
{
myConnections.manageConnection(myInterface.signal_processText.connect(
boost::bind(&HumbleDialogLogic::slot_processText, this, boost::placeholders::_1)));
}

When signaled from the interface, the logic object simply prints the given text to the console, then calls the interface to set the text to an empty string (thus clearing the underlying widget's textbox).

boost::bind(&HumbleDialogLogic::slot_processText, this, boost::placeholders::_1)));
}
{
virtual ~HumbleDialogLogic()
Disconnect from the boost::signals of the widget-interface.
std::cout << "Humble Dialog Text:[" << text << "]" << std::endl;
myInterface.setText(std::string(""));
}

The Page Manages the Widget.

As stated in the Overview, the standard dialogs in VR-Vantage are collections of pages. Each page is derived from a makVrv::DtPage class in the vrvCoreQt library. The DtPage class is itself derived from a QWidget so the DtPage class is a GUI element. The DtPage class is an abstract class which requires derivations of it to implement functions which return an icon, return a title and return a class-name. The DtPage class also has two more pure virtual functions that derived classes must implement: activate() and deactivate(). These two functions are called when the page is shown and hidden, respectively.

This tutorial declares its page in the HumbleDialogPage.h file. The page is used to manage both the widget object and the logic object. The page implements all the virtual functions required by its parent abstract class. The icon returned is defined in the application.qrc resource file, and the title and class names returned are just strings.

The example page that will be inserted into the example dialog. This page contains a widget and logic...
Definition HumbleDialogPage.h:30
The page is a single widget component which is viewed in a page collection.
Definition DtPage.h:52
{
Q_OBJECT;
public:
HumbleDialogPage(makVrv::DtDe &de, QWidget *parent=0, Qt::WindowFlags f=Qt::Widget)
CTOR. This constructor creates the main widget of the HumbleDialogPage. The logic is created at a lat...
QWidget* parent = 0,
Qt::WindowFlags f = Qt::Widget);
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
virtual ~HumbleDialogPage();
virtual ~HumbleDialogPage()
Virtual DTOR.
virtual QIcon icon();
virtual QIcon icon()
Get the icon of the page. DtPage requires this function to be implemented.
virtual QString title();
virtual QString title()
Get the title of the page. DtPage requires this function to be implemented.
virtual const std::string& pageClassName() const;
virtual const std::string & pageClassName() const
Get the class name of the page. DtPage requires this function to be implemented.
protected:
virtual void activate();
virtual void activate()
Called by the Pager when this page becomes active. Called when the HumbleDialogPage is shown,...
virtual void deactivate();
virtual void deactivate()
Called by the Pager when this page becomes active. Called when the HumbleDialogPage is hidden,...
private:
HumbleDialogWidget * myWidget
Definition HumbleDialogPage.h:82
HumbleDialogLogic * myLogic
Definition HumbleDialogPage.h:83
};

The HumbleDialogPage.h file also declares a creator for the page using the built in template for creating pages.

Definition DtPage.h:182
makVrv::DtPageCreatorTemplate< HumbleDialogPage > HumbleDialogPageCreator
A creator class for makVrv::HumbleDialogPage.
Definition HumbleDialogPage.h:90

The page in this tutorial creates the widget within the constructor of the page.

HumbleDialogPage::HumbleDialogPage(DtDe& de, QWidget* parent, Qt::WindowFlags f)
: DtPage(de, parent, f)
, myWidget(0)
, myLogic(0)
{
myWidget = new HumbleDialogWidget(this);
}

When the page is shown, its activate() function is called. When called this page creates a logic object. The logic object is given the widget in the logic's constructor so that the logic can connect its boost slot to the widget's boost signal.

{
myLogic = new HumbleDialogLogic(*myWidget);
}

When the page is hidden, its deactivate() is called. When called this page destroys the logic object.

{
delete myLogic;
}

Setting Up a Plug-in

Two files are needed to create a plug-in.

The first file, exampleHumbleDialogPlugin.h, is used to create the dll inport/export symbols and declare the entry point function for the plug-in. All VR-Vantage plug-ins use the same signature for their entry point. The signature is declared in core header file vrvCore/exportPlugin.h. Before including the core header file, the specific symbol must be defined as the import/export symbol as shown below.

# ifdef EXAMPLEHUMBLEDIALOG_EXPORTS
# define DT_DE_PLUGIN_EXPORT_MACRO __declspec ( dllexport )
# else
# define DT_DE_PLUGIN_EXPORT_MACRO __declspec ( dllimport )
# endif

A compilation error will occur if the DT_DE_PLUGIN_EXPORT_MACRO symbol is not declared prior to including the core header file. Finally the initializer function for this plug-in is declared.

void init(makVrv::DtDe& de);
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)

The second file, exampleHumbleDialogPlugin.cxx, implements both the plug-in entry point and the initializer function. All the entry point function does is call the initializer.

// Implement the standard plug-in function initDeModule().
// This standard function calls the specialized initializer
// for the example humble-dialog plug-in.
// The prototype for this function was created when this file's header
// included the core header-file 'vrvCore/exportPlugin.h'.
bool initDeModule(DtDe* de)
{
init(*de);
return true;
}
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)

The plug-in initializer is more interesting. It starts by registering itself with the display engine using a standard VR-Vantage macro.

void init(DtDe& de)
{
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30

This macro ensures that the plug-in module is registered with the display engine once and only once. Next the core Qt is initialized.

vrvCoreQt::init(de);

When the vrvCoreQt is initialized, many types of assemblers are created and the default menus, dialogs and panels are registered. The assemblers, in this case, are used to assemble the GUI elements. After vrvCoreQt is initialized the creator for the page (The one that was constructed from a template in HumbleDialogPage.h) is registered with the page assembler.

DtQtPageAssembler::instance(de).registerPageCreator(

A DtMenu and DtMenuItem are also registered. Building these menus is not the purpose of this tutorial, but something is needed to allow the user to pop up the dialog. The menu files are included for the readers benefit: HumbleDialogMenu.h, HumbleDialogMenu.cxx. Both the menu and menu-item are registered with a menu assembler and then configured with the application.

DtQtMenuAssembler::instance(de).registerMenu(
new HumbleDialogMenu(de));
DtQtMenuAssembler::instance(de).registerMenu(
The HumbleDialog menu to be added to the main menu bar.
Definition HumbleDialogMenu.h:27
The item for bringing up a HumbleDialog dialog. This DtMenuItem is added to the HumbleDialogMenu menu...
Definition HumbleDialogMenu.h:47
app->masterModeMenuConfiguration().addMenuPath(
makVrv::DtMenuPath::mainMenu("HumbleDialogMenu"));
app->masterModeMenuConfiguration().addMenuPath(
makVrv::DtMenuPath::mainMenu("HumbleDialogMenu").item(
"HumbleDialogMenuItem"));
static MenuPathBuilder mainMenu(const std::string &name)

The application is then configured to build a dialog. Notice that this plug-in does not derive a dialog from a class, but rather allows the application to build it. The dialog is a collection of pages, so the initializer adds a page collection to the page configuration.

app->masterModePageConfiguration().addPageCollection(
"HumbleDialog",
DtUnicode::fromAscii("Example Dialog"),
DtPageConfiguration::Dialog,
true,
"HumbleDialogPage");

The dialog is named HumbleDialog and its starting page (the one that is first viewable) is the HumbleDialogPage. The MasterMode specification in the call means that the dialog will only be present when the application runs in master mode. The page configuration is then told to add the page to the dialog that was just configured.

app->masterModePageConfiguration().addPagePath(
"HumbleDialogPage"));
static PagePathBuilder collection(const std::string &name)
Start a main menu.
DtPagePath page(const std::string &name) const
Add a menu item to the path. Returns a DtPagePath which can't be added to.

This tells the page configuration that we wish to add the HumbleDialogPage to the dialog called HumbleDialog. We could have chosen to add the page to a different dialog, maybe an already existing dialog. In fact, plug-ins frequently do that. If that were the case, the initializer would not need to create a new dialog, nor would it need to create a menu, as the existing dialog would already be configured with those. Just as an exercise to prove this point, this plug-in adds a second copy of the HumbleDialogPage to the already existing dialog named DtLogs.

app->masterModePageConfiguration().addPagePath(
"HumbleDialogPage"));

Building the Example

VR-Vantage includes pre-built versions of the example plug-in. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.

Running the Example

This example is a plug-in. You can run it by running ./bin64/exampleHumbleDialog_stealth.bat (on Windows) or ./bin64/exampleHumbleDialog_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.

When the application is run, the main menu bar has a new Examples menu where the HumbleDialog can be popped up. The HumbleDialog shows a single page, the HumbleDialogPage page. On the Help menu, the Error Message menu-item will pop up the DtLogs dialog, where the user can see a second HumbleDialogPage mixed in with the existing pages.

Example Source Files


exampleHumbleDialogPlugin.h

/*****************************************************************************
* Copyright (c) 2019 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#pragma once
// Setup proper plug-in export symbol.
#ifdef _WIN32
# ifdef EXAMPLEHUMBLEDIALOG_EXPORTS
# define DT_DE_PLUGIN_EXPORT_MACRO __declspec ( dllexport )
# else
# define DT_DE_PLUGIN_EXPORT_MACRO __declspec ( dllimport )
# endif
#else
# define DT_DE_PLUGIN_EXPORT_MACRO
#endif
// Export standard plugging function bool initDeModule(DtDe* de).
namespace makVrv { class DtDe; }
void init(makVrv::DtDe& de);
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16

exampleHumbleDialogPlugin.cxx

/*****************************************************************************
* Copyright (c) 2019 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <vrvCore/DtDe.h>
using namespace makVrv;
// Implement the standard plug-in function initDeModule().
// This standard function calls the specialized initializer
// for the example humble-dialog plug-in.
// The prototype for this function was created when this file's header
// included the core header-file 'vrvCore/exportPlugin.h'.
bool initDeModule(DtDe* de)
{
init(*de);
return true;
}
// Implement the specialized initializer for the example humble-dialog
// plug-in.
void init(DtDe& de)
{
try
{
// First make sure that the vrvCoreQt module is initialized.
// Register HumbleDialogPageCreator with the page-assembler.
// The page-assembler was created in vrvCoreQt::init().
DtQtPageAssembler::instance(de).registerPageCreator(
// Register the HumbleDialogMenu and HumbleDialogMenuItem with the
// menu-assembler The menu-assembler was created in
// vrvCoreQt::init().
DtQtMenuAssembler::instance(de).registerMenu(
new HumbleDialogMenu(de));
DtQtMenuAssembler::instance(de).registerMenu(
// Add the menu and dialog to the application.
if (app)
{
// Add the HumbleDialogMenu to the main menu.
makVrv::DtMenuPath::mainMenu("HumbleDialogMenu"));
makVrv::DtMenuPath::mainMenu("HumbleDialogMenu").item(
"HumbleDialogMenuItem"));
// Create and add the HumbleDialog to the application.
"HumbleDialog",
DtUnicode::fromAscii("Example Dialog"),
true,
"HumbleDialogPage");
// Add the HumbleDialogPage to the HumbleDialog (the only page).
makVrv::DtPagePath::collection("HumbleDialog").page(
"HumbleDialogPage"));
// Just for kicks, add another HumbleDialogPage to the DtLogs
// dialog. This page can be seen by clicking on the 'Help'
// menu, then clicking on the 'Error Message' menu-item.
"HumbleDialogPage"));
}
}
DtCATCH_AND_PROPAGATE(DtCorruptedState)
}
Contains makVrv::DtDe class.
Contains makVrv::DtMenuPath class.
Contains makVrv::DtQtMenuAssembler class.
Contains makVrv::DtQtPageAssembler class.
Contains makVrv::DtVrvApplication implementation.
Contains the HumbleDialogMenu class declaration.
Contains the HumbleDialogPage class declaration.
void addMenuPath(const DtMenuPath &, const MenuSortFlags &sortFlagsIfMenu=(MenuSortFlags)(SortAllAlphabetically|SortWithinSubmenus|SortBetweenSeparators))
Adds the menu path (as well as its entire family).
void addPagePath(const DtPagePath &, int weight=-1)
Adds the menu path (as well as its entire family).
void addPageCollection(const std::string &collectionClassName, const DtUnicode &pageTitle, PageCollectionLocation location, bool visible, const std::string &pageClassToShow, bool closable=true, bool floatable=true, bool movable=true)
Add a new page collection to the configuration.
@ Dialog
Definition DtPageConfiguration.h:52
static DtQtMenuAssembler & instance(DtDe &de)
Get an instance of the assembler.
static DtQtPageAssembler & instance(DtDe &de)
Get an instance of the Qt page Assembler.
static DtUnicode fromAscii(const std::string &ascii)
Definition DtUnicode.inl:285
The Root IG Application object. To run the IG simply create one, initialize it and call run.
Definition DtVrvApplication.h:58
DtMenuConfiguration & masterModeMenuConfiguration()
Get the menu configuration which may be altered by plugins.
DtPageConfiguration & masterModePageConfiguration()
Get the page configuration which may be altered by plugins.
static DtVrvApplication * findFromDe(DtDe &)
Contains the plug-in export macro.
DT_DLL_VRVCOREQT void init(DtDe &de)

HumbleDialogMenu.h

/*****************************************************************************
* Copyright (c) 2019 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#pragma once
namespace makVrv
{
class DtDe;
}
{
public:
virtual ~HumbleDialogMenu();
virtual QMenu* createMenu(makVrv::DtDe&, QWidget* parent);
};
{
public:
protected:
virtual void on_triggered();
protected:
};
virtual QMenu * createMenu(makVrv::DtDe &, QWidget *parent)
Build a menu.
virtual ~HumbleDialogMenu()
Virtual DTOR.
HumbleDialogMenu(makVrv::DtDe &de)
CTOR.
virtual void on_triggered()
When the item is triggered.
virtual QAction * createAction(makVrv::DtDe &, QWidget *parent)
Build a menu item (via an action).
makVrv::DtDe & myDe
Definition HumbleDialogMenu.h:66
virtual ~HumbleDialogMenuItem()
Virtual DTOR.
HumbleDialogMenuItem(makVrv::DtDe &de)
CTOR.
The abstract base menu class.
Definition DtMenu.h:24
Definition DtMenuItem.h:24

HumbleDialogMenu.cxx

/*****************************************************************************
* Copyright (c) 2021 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <QtWidgets/QMenu> // Qt headers must be include last due to signals
using namespace makVrv;
// Implementing the menu //
: DtMenu(de, std::string("HumbleDialogMenu") )
{
}
{
}
{
QMenu* menu = new QMenu(QMenu::tr("Examples"), parent);
return menu;
}
// Implementing the menu-item //
: DtMenuItem(std::string("HumbleDialogMenuItem"))
, myDe(de)
{
}
{
}
{
QAction* action = new QAction(parent);
action->setText(DtMenuItem::tr("Show Humble Dialog..."));
DtWidgetIconStyleManager::instance(myDe).manageWidget(action, "ObjectPlanEdit.svg");
return action;
}
{
// The HumbleDialog was registered in exampleHumbleDialogPluginInit.
// Here we're calling it by name and requesting it to be shown.
DtPageCollectionManager::instance(myDe).showCollection("HumbleDialog");
}
Contains makVrv::DtPageCollectionManager class.
Contains makVrv::DtWidgetIconStyleManager class declaration.

HumbleDialogPage.h

/*****************************************************************************
* Copyright (c) 2021 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#pragma once
{
Q_OBJECT;
public:
QWidget* parent = 0,
Qt::WindowFlags f = Qt::Widget);
virtual ~HumbleDialogPage();
virtual QIcon icon();
virtual QString title();
virtual const std::string& pageClassName() const;
static const std::string& thePageClassName();
protected:
virtual void activate();
virtual void deactivate();
private:
};
Contains makVrv::DtPage class declaration.
static const std::string & thePageClassName()
Get the class name of the page. DtPageCreatorTemplate requires this function to be implemented.
virtual makVrv::DtQIconConfigurations qIconConfigurations() const
Get the icon configurations for the page. This is used to style the page's icon based on application ...
A collection of icon configurations. The collection maintains flags indicating whether to generate ic...
Definition DtQIconConfiguration.h:132

HumbleDialogPage.cxx

/*****************************************************************************
* Copyright (c) 2021 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <QtWidgets/QVBoxLayout>
using namespace makVrv;
HumbleDialogPage::HumbleDialogPage(DtDe& de, QWidget* parent, Qt::WindowFlags f)
: DtPage(de, parent, f)
, myWidget(0)
, myLogic(0)
{
// Create a layout for this page
QVBoxLayout* mainLayout = new QVBoxLayout(this);
mainLayout->setMargin(0);
// Create the example widget.
myWidget = new HumbleDialogWidget(this);
mainLayout->addWidget(myWidget);
mainLayout->addStretch(1);
}
{
// make sure the logic object is destroyed
delete myLogic;
myLogic = 0;
}
{
if (! myLogic)
{
}
}
{
delete myLogic;
myLogic = 0;
}
{
return QIcon (":/icons/exampleIcon.png");
}
{
DtQIconConfigurations result;
result.addConfiguration(DtQIconConfiguration("FileDocument.svg"));
return result;
}
{
return HumbleDialogPage::tr("Humble Dialog Page");
}
const std::string& HumbleDialogPage::pageClassName() const
{
return thePageClassName();
}
{
static std::string theClassName("HumbleDialogPage");
return theClassName;
}
Contains the HumbleDialogLogic class declaration.
Contains the HumbleDialogWidget class declaration.
virtual void addConfiguration(const DtQIconConfiguration &configuration)
Add an icon configuration to this list of configurations When adding a configuration,...

application.qrc


HumbleDialogWidgetInterface.h

/*****************************************************************************
* Copyright (c) 2023 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#pragma once
{
public:
virtual void setText(const std::string& text) = 0;
makVrv::vrvSignalsLib::signal<void (const std::string& text)> signal_processText;
};

HumbleDialogWidget.h

/*****************************************************************************
* Copyright (c) 2019 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#pragma once
#include <QtWidgets/QWidget> // Qt headers must be include last due to signals
#include <QtWidgets/QLineEdit>
: public QWidget
{
Q_OBJECT
public:
HumbleDialogWidget(QWidget* parent = 0, Qt::WindowFlags f = Qt::Widget);
virtual void setText(const std::string& text);
public slots:
private:
};
Contains the HumbleDialogWidgetInterface class declaration.

HumbleDialogWidget.cxx

/*****************************************************************************
* Copyright (c) 2019 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <QtWidgets/QLabel> // Qt headers must be include last due to signals
#include <QtWidgets/QVBoxLayout>
: QWidget(parent, f)
, myTextBox(0)
{
// Create a layout for this widget
QVBoxLayout* myLayout = new QVBoxLayout(this);
myLayout->setMargin(0);
// Create a label for the this widget.
QLabel* label = new QLabel("Edit the text. Press enter to print.");
label->setObjectName("theLabel");
myLayout->addWidget(label);
// Create a text-box for this widget.
myTextBox = new QLineEdit(this);
myTextBox->setObjectName("theTextBox");
myLayout->addWidget(myTextBox);
// Connect the text-box signals to our Qt slots.
connect(
myTextBox, SIGNAL(returnPressed()),
this, SLOT(slot_onReturnPressed()) );
}
{
// Don't delete since myTextBox is managed by this QWidget.
myTextBox = NULL;
}
void HumbleDialogWidget::setText(const std::string& text)
{
bool restore = myTextBox->blockSignals(true);
myTextBox->setText(QString::fromStdString(text));
myTextBox->blockSignals(restore);
}
{
signal_processText(myTextBox->text().toStdString());
}

HumbleDialogLogic.h

/*****************************************************************************
* Copyright (c) 2019 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#pragma once
{
public:
virtual ~HumbleDialogLogic();
void slot_processText(const std::string& text);
private:
};
Base class to provide boost signal/slot management.

HumbleDialogLogic.cxx

/*****************************************************************************
* Copyright (c) 2024 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <boost/bind/bind.hpp>
#include <vrvCore/DtDe.h>
#include <iostream>
: myInterface(iFace)
, myConnections()
{
// Tell the widget to clear the text box.
myInterface.setText(std::string(""));
// Connect the interface signals to the logic slots.
myConnections.manageConnection(myInterface.signal_processText.connect(
boost::bind(&HumbleDialogLogic::slot_processText, this, boost::placeholders::_1)));
}
{
// Interface signals are automatically disconnected from the logic slots
// because they are being managed by a DtSignalConnectionManager
// (myConnections) which performs disconnections during destruction.
}
void HumbleDialogLogic::slot_processText(const std::string& text)
{
// print out the string to the console then clear the widget.
if (text.size()) {
std::cout << "Humble Dialog Text:[" << text << "]" << std::endl;
myInterface.setText(std::string(""));
}
}