VR-Forces 4.0.4 Class Documentation
exampleHumbleDialog

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

Overview

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.

class HumbleDialogWidgetInterface
{
public:
    virtual void setText(const std::string& text) = 0;
    boost::signal<void (const std::string& text)> signal_processText;
};

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.

class HumbleDialogWidget
    : public QWidget
    , public HumbleDialogWidgetInterface
{
    Q_OBJECT
public:
    HumbleDialogWidget(QWidget* parent = 0, Qt::WindowFlags f = Qt::Widget);
    virtual ~HumbleDialogWidget();

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);

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();

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

private:
    QLineEdit* myTextBox;
};

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.

HumbleDialogWidget::HumbleDialogWidget(QWidget* parent, Qt::WindowFlags f)
    : 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.

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.

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

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, _1)));
}

HumbleDialogLogic::~HumbleDialogLogic()
{
        std::cout << "Humble Dialog Text:[" << text << "]"  << std::endl;
        myInterface.setText(std::string(""));
    }

The Page Manages the Widget and the Logic

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.

class HumbleDialogPage : public makVrv::DtPage
{
    Q_OBJECT;
public:
    HumbleDialogPage(
        makVrv::DtDe& de,
        QWidget* parent = 0,
        Qt::WindowFlags f = Qt::Widget);
    virtual ~HumbleDialogPage();
    virtual QIcon icon();
    virtual QString title();
    virtual const std::string& pageClassName() const;
protected:
    virtual void activate();
    virtual void deactivate();
private:
    HumbleDialogWidget* myWidget;
    HumbleDialogLogic* myLogic;
};

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

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)
    , myDe(de)
    , 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.

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

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.

//! \file exampleHumbleDialogPlugin.h
#  ifdef EXAMPLEHUMBLEDIALOG_EXPORTS
#     define DT_DE_PLUGIN_EXPORT_MACRO __declspec ( dllexport )
#  else
#     define DT_DE_PLUGIN_EXPORT_MACRO __declspec ( dllimport )
#  endif
#include <vrvCore/exportPlugin.h>

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);

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;
}

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)
{
    DT_DE_INIT_ONCE(de);

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

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(
            new HumbleDialogPageCreator(de));

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(
            new HumbleDialogMenuItem(de));
            app->masterModeMenuConfiguration().addMenuPath(
                makVrv::DtMenuPath::mainMenu("HumbleDialogMenu"));
            app->masterModeMenuConfiguration().addMenuPath(
                makVrv::DtMenuPath::mainMenu("HumbleDialogMenu").item(
                "HumbleDialogMenuItem"));

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(
                makVrv::DtPagePath::collection("HumbleDialog").page(
                "HumbleDialogPage"));

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.

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 ./bin/exampleHumbleDialog_stealth.bat (on Windows) or ./bin/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 Exercises 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) 2012 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

#include <vrvUtil/signalslib.h>

// Export standard plugging function bool initDeModule(DtDe* de).
#include <vrvCore/exportPlugin.h>

namespace makVrv { class DtDe; }

void init(makVrv::DtDe& de);



exampleHumbleDialogPlugin.cxx

/*****************************************************************************
* Copyright (c) 2012 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/


#include "exampleHumbleDialogPlugin.h"
#include "HumbleDialogPage.h"
#include "HumbleDialogMenu.h"

#include <vrvCore/DtDe.h>
#include <vrvCoreQt/DtQtPageAssembler.h> 
#include <vrvCore/DtVrvApplication.h>
#include <vrvCore/DtMenuPath.h>
#include <vrvCoreQt/DtQtMenuAssembler.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)
{
    DT_DE_INIT_ONCE(de);

    try
    {
        // First make sure that the vrvCoreQt module is initialized.
        vrvCoreQt::init(de);

        // Register HumbleDialogPageCreator with the page-assembler.
        // The page-assembler was created in vrvCoreQt::init().
        DtQtPageAssembler::instance(de).registerPageCreator(
            new HumbleDialogPageCreator(de));

        // 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(
            new HumbleDialogMenuItem(de));

        // Add the menu and dialog to the application.
        makVrv::DtVrvApplication* app =
            makVrv::DtVrvApplication::findFromDe(de);
        if (app)
        {
            // Add the HumbleDialogMenu to the main menu.
            app->masterModeMenuConfiguration().addMenuPath(
                makVrv::DtMenuPath::mainMenu("HumbleDialogMenu"));
            app->masterModeMenuConfiguration().addMenuPath(
                makVrv::DtMenuPath::mainMenu("HumbleDialogMenu").item(
                "HumbleDialogMenuItem"));

            // Create and add the HumbleDialog to the application.
            app->masterModePageConfiguration().addPageCollection(
                "HumbleDialog",
                DtUnicode::fromAscii("Example Dialog"),
                DtPageConfiguration::Dialog,
                true,
                "HumbleDialogPage");

            // Add the HumbleDialogPage to the HumbleDialog (the only page).
            app->masterModePageConfiguration().addPagePath(
                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.
            app->masterModePageConfiguration().addPagePath(
                makVrv::DtPagePath::collection("DtLogs").page(
                "HumbleDialogPage"));
        }
    }
    DtCATCH_AND_PROPAGATE(DtCorruptedState)
}


HumbleDialogMenu.h

/*****************************************************************************
* Copyright (c) 2012 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/


#pragma once

#include "exampleHumbleDialogPlugin.h"

#include <vrvCoreQt/DtMenuItem.h>
#include <vrvCoreQt/DtMenu.h>

namespace makVrv
{
    class DtDe;
}

class HumbleDialogMenu : public makVrv::DtMenu
{
public:

    HumbleDialogMenu(makVrv::DtDe& de);

    virtual ~HumbleDialogMenu();

    virtual QMenu* createMenu(makVrv::DtDe&, QWidget* parent);
};


class HumbleDialogMenuItem : public makVrv::DtMenuItem
{
public:

    HumbleDialogMenuItem(makVrv::DtDe& de);

    virtual ~HumbleDialogMenuItem();

    virtual QAction* createAction(makVrv::DtDe&, QWidget* parent);

protected:

    virtual void on_triggered();

protected:

    makVrv::DtDe& myDe;
};

HumbleDialogMenu.cxx

/*****************************************************************************
* Copyright (c) 2012 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/


#include <vrvCore/DtPageCollectionManager.h>

#include "HumbleDialogMenu.h"

#include <QtGui/QMenu>        // Qt headers must be include last due to signals

using namespace makVrv;

// Implementing the menu //

HumbleDialogMenu::HumbleDialogMenu(DtDe& de)
    : DtMenu(de, std::string("HumbleDialogMenu") )
{
}

HumbleDialogMenu::~HumbleDialogMenu()
{
}

QMenu* HumbleDialogMenu::createMenu(DtDe&, QWidget* parent)
{
    QMenu* menu = new QMenu(QMenu::tr("Examples"), parent);
    return menu;
}

// Implementing the menu-item //

HumbleDialogMenuItem::HumbleDialogMenuItem(DtDe& de)
    : DtMenuItem(std::string("HumbleDialogMenuItem"))
    , myDe(de)
{
}

HumbleDialogMenuItem::~HumbleDialogMenuItem()
{
}

QAction* HumbleDialogMenuItem::createAction(DtDe&, QWidget* parent)
{
    QAction* action = new QAction(parent);
    action->setText(DtMenuItem::tr("Show Humble Dialog..."));
    action->setIcon(QIcon(":/icons/exampleIcon.png"));
    return action;
}

void HumbleDialogMenuItem::on_triggered()
{
    // The HumbleDialog was registered in exampleHumbleDialogPluginInit.
    // Here we're calling it by name and requesting it to be shown.
    DtPageCollectionManager::instance(myDe).showCollection("HumbleDialog");
}



HumbleDialogPage.h

/*****************************************************************************
* Copyright (c) 2012 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/


#pragma once

#include "exampleHumbleDialogPlugin.h"

#include <vrvCoreQt/DtPage.h>

namespace makVrv { class DtDe; }

class HumbleDialogWidget;
class HumbleDialogLogic;

class HumbleDialogPage : public makVrv::DtPage
{
    Q_OBJECT;

public:

    HumbleDialogPage(
        makVrv::DtDe& de,
        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:

    makVrv::DtDe& myDe;
    HumbleDialogWidget* myWidget;
    HumbleDialogLogic* myLogic;
};

typedef makVrv::DtPageCreatorTemplate<HumbleDialogPage> HumbleDialogPageCreator;

HumbleDialogPage.cxx

/*****************************************************************************
* Copyright (c) 2012 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/


#include "HumbleDialogPage.h"
#include "HumbleDialogWidget.h"
#include "HumbleDialogLogic.h"

#include <QtGui/QVBoxLayout>

using namespace makVrv;

HumbleDialogPage::HumbleDialogPage(DtDe& de, QWidget* parent, Qt::WindowFlags f)
    : DtPage(de, parent, f)
    , myDe(de)
    , 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);
}

HumbleDialogPage::~HumbleDialogPage()
{
    // make sure the logic object is destroyed
   delete myLogic;
   myLogic = 0;
}

void HumbleDialogPage::activate()
{
    if (! myLogic)
    {
        myLogic = new HumbleDialogLogic(*myWidget);
    }
}

void HumbleDialogPage::deactivate()
{
    delete myLogic;
    myLogic = 0;
}

QIcon HumbleDialogPage::icon()
{
    return QIcon (":/icons/exampleIcon.png");
}

QString HumbleDialogPage::title()
{
    return HumbleDialogPage::tr("Humble Dialog Page");
}

const std::string& HumbleDialogPage::pageClassName() const
{
    return thePageClassName();
}

const std::string& HumbleDialogPage::thePageClassName()
{
    static std::string theClassName("HumbleDialogPage");
    return theClassName;
}

application.qrc

 <!DOCTYPE RCC><RCC version="1.0">
 <qresource>
     <file>icons/exampleIcon.png</file>
 </qresource>
 </RCC> 

HumbleDialogWidgetInterface.h

/*****************************************************************************
* Copyright (c) 2012 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/


#pragma once

#include <boost/signal.hpp>

#include "exampleHumbleDialogPlugin.h"

class HumbleDialogWidgetInterface
{
public:

    virtual void setText(const std::string& text) = 0;

    boost::signal<void (const std::string& text)> signal_processText;
};

HumbleDialogWidget.h

/*****************************************************************************
* Copyright (c) 2012 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/


#pragma once

#include "exampleHumbleDialogPlugin.h"
#include "HumbleDialogWidgetInterface.h"

#include <QtGui/QWidget>     // Qt headers must be include last due to signals
#include <QtGui/QLineEdit>


class HumbleDialogWidget
    : public QWidget
    , public HumbleDialogWidgetInterface
{
    Q_OBJECT

public:

    HumbleDialogWidget(QWidget* parent = 0, Qt::WindowFlags f = Qt::Widget);

    virtual ~HumbleDialogWidget();

    virtual void setText(const std::string& text);

    public slots:

        void slot_onReturnPressed();

private:
    QLineEdit* myTextBox;
};


HumbleDialogWidget.cxx

/*****************************************************************************
* Copyright (c) 2012 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/


#include "HumbleDialogWidget.h"

#include <QtGui/QLabel>       // Qt headers must be include last due to signals
#include <QtGui/QVBoxLayout>


HumbleDialogWidget::HumbleDialogWidget(QWidget* parent, Qt::WindowFlags f)
    : 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()) );
}

HumbleDialogWidget::~HumbleDialogWidget()
{
    // 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);
}

void HumbleDialogWidget::slot_onReturnPressed()
{
    signal_processText(myTextBox->text().toStdString());
}


HumbleDialogLogic.h

/*****************************************************************************
* Copyright (c) 2012 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/


#pragma once

#include <vrvUtil/DtSignalConnectionManager.h>

#include "exampleHumbleDialogPlugin.h"


class HumbleDialogWidgetInterface;

class HumbleDialogLogic
{
public:

    HumbleDialogLogic(HumbleDialogWidgetInterface& iFace);

    virtual ~HumbleDialogLogic();

    void slot_processText(const std::string& text);

private:

    HumbleDialogWidgetInterface& myInterface;
    makVrv::DtSignalConnectionManager myConnections;
};


HumbleDialogLogic.cxx

/*****************************************************************************
* Copyright (c) 2012 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/


#include <boost/bind.hpp>

#include <vrvCore/DtDe.h>

#include "HumbleDialogLogic.h"
#include "HumbleDialogWidgetInterface.h"


HumbleDialogLogic::HumbleDialogLogic(HumbleDialogWidgetInterface& iFace)
    : 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, _1)));
}

HumbleDialogLogic::~HumbleDialogLogic()
{
    // 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(""));
    }
}

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)