///
///returns an identifying path from a widget
///
QString getWidgetPath(QObject* o)
{
    assert ( o );
    //get the object path
    QString opath;

    if ( o->isWidgetType() )
    {
        QWidget *w = dynamic_cast<QWidget*> ( o );

        if ( w->objectName() == "" )
            w->setObjectName ( getWidgetName ( w ) );

        opath = w->objectName();

        while ( w->parent() != NULL )
        {
            w = dynamic_cast<QWidget*> ( w->parent() );

            if ( w->objectName() == "" )
                w->setObjectName ( getWidgetName ( w ) );

            opath = w->objectName() + "/" + opath;
        }
    }

    return opath;
}
Beispiel #2
0
void WidgetComponent::cleanup(Window& parent) const
{
    if (!parent.isChild(getWidgetName()))
        return;

    Window* widget = parent.getChild(getWidgetName());
    // clean up up the event actions
    for (EventActionList::const_iterator i = d_eventActions.begin();
            i != d_eventActions.end();
            ++i)
    {
        (*i).cleanupWidget(*widget);
    }

    parent.destroyChild(widget);
}
int main()
{
    Widget w;

    auto n = getWidgetName();         // n is local variable

    w.setName(n);                     // moves n into w!

    std::cout << n << std::endl;      // n's value now unknown
}
Beispiel #4
0
void MLDrawing::dumpOperations()
{
	debug() << "MLDrawing " << getWidgetName() << ": \n";
	int c = 0;
	for(std::vector<MLDrawing::Operation>::iterator it = mOperations.begin(); it != mOperations.end(); it++)
	{
		const MLDrawing::Operation& op = *it;
		debug() << "    op" << c++ << ": " << op.type << "\n";
		debug() << "        args: ";
		for (int i=0; i<4; ++i)
		{
			debug() << op.args[i] << " ";
		}
		debug() << "\n";

	}
}
///
///returns a widget
///it supports repeated widget names
///
QWidget* getAbsoluteWidget(QStringList path)
{
    _log::misc << "(QWidgetUtils::getAbsoluteWidget)" << std::endl;
    ///update the view
    QWidgetUtils::updateAppView();

    ///get all the widgets
    QWidgetList qwl = qApp->allWidgets();

    ///get the widget name
    assert ( path.size() );
    QString name = path.back();
    if ( name == "" )
    {
        std::cout << "(QWidgetUtils::getAbsoluteWidget) ERROR. The name of the widget is empty." << std::endl;
        return NULL;
    }
    path.pop_back();

    //_log::misc << "(QWidgetUtils::getAbsoluteWidget) Name = " << name.toStdString() << std::endl;


    ///get all widgets with this name
    QWidgetList qws;
    foreach ( QWidget *w, qwl )
    {
        if ( getWidgetName ( w ) == name )
        {
            qws.push_back ( w );
        }
    }
    //_log::misc << "(QWidgetUtils::getAbsoluteWidget) OK" << std::endl;
    //if there are no selected widgets...
    if ( qws.size() == 0 )
    {
        _log::misc << "(QWidgetUtils::getAbsoluteWidget) ERROR. There are no selected widgets." << std::endl;
        return NULL;
    }
    //_log::misc << "(QWidgetUtils::getAbsoluteWidget) OK" << std::endl;

    ///get the concrete widget we are looking for...
    int level = 1;
    bool onTopLevel = false;
    int onTopLevelCount = 0;
    QWidgetList::iterator qit;

    /*for (qit = qws.begin(); qit != qws.end(); qit++)
      {
      QWidget* w = static_cast<QWidget*> ( *qit );
      _log::misc << getWidgetPath(w).toStdString() << std::endl;
      }*/

    // while more than 1 widget remaining
    // or every widget has been analyzed...
    while ( qws.size() > 1 && onTopLevelCount < qws.size() )
    {

        //_log::misc << "(QWidgetUtils::getAbsoluteWidget) OK -> " << qws.size() << std::endl;
        //for the remaining widgets...
        qit = qws.begin();
        while ( qit != qws.end() )
        {
            //get the parent widget
            QWidget* w = static_cast<QWidget*> ( *qit );
            QWidget* wParent = w;
            assert ( wParent );
            onTopLevel = false;

            for ( int i = 0; i < level; i++ )
            {
                //if we are in a top level widget (with no parent node)
                //we have to avoid this widget
                if ( wParent->parent() == NULL )
                {
                    onTopLevel = true;
                    onTopLevelCount++;
                    break;
                }
                //if not, we go on looking for up
                else
                {
                    wParent = static_cast<QWidget*> ( wParent->parent() );
                }
            }

            //if not at top level...
            if ( !onTopLevel )
            {
                //we chech the parent name and delete the
                //widgets whose parent name does not mach
                if ( getWidgetName ( wParent ) != path.back() )
                {
                    qit = qws.erase ( qit );
                }
                else
                {
                    qit++;
                }
            }
            else
            {
                qit++;
            }
        }

        //update the values
        level++;
        path.pop_back();

        //stop condition (end of the search path)
        if ( path.size() == 0 ) break;
    }

    //_log::misc << "(QWidgetUtils::getAbsoluteWidget) OK" << std::endl;

    //there has to be only one element at the list
    if ( qws.size() != 1 )
    {
        std::cout <<
            "(QWidgetUtils::getAbsoluteWidget) ERROR. None or more than one widget selected. Result = "
                  << qws.size() << std::endl;
        return NULL;
    }

    //if not, return the widget
    return qws.first();
}