QWidget * KvsObject_wrapper::findTopLevelWidgetToWrap(const QString &szClass,const QString &szName,bool bRecursive) { QWidgetList list = g_pApp->topLevelWidgets(); if(list.isEmpty()) return NULL; Q_FOREACH(QWidget * w,list) { //qDebug("TLW: %s::%s (look for %s::%s)",w->metaObject()->className(),w->objectName().toUtf8().data(),szClass.toUtf8().data(),szName.toUtf8().data()); if( ( szClass.isEmpty() || KviQString::equalCI(w->metaObject()->className(),szClass) ) && ( szName.isEmpty() || KviQString::equalCI(w->objectName(),szName) ) ) return w; } if(bRecursive) { Q_FOREACH(QWidget * w,list) { w = findWidgetToWrap(szClass,szName,w,bRecursive); if(w) return w; } }
bool KvsObject_wrapper::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) { if( !pParams ) return false; QWidget *pWidget = 0; unsigned int i=0; while(i!=pParams->count()) { QString szClass; QString szName; QString s=0; pParams->at(i)->asString(s); if (!s.isEmpty()) { int idx = s.indexOf("::"); if( idx != -1 ) { szClass = s.left(idx); szName = s.right(s.length() - idx - 2); } else { szClass = s; szName = ""; } if(KviQString::equalCI(szClass,"WinId")) { if(pWidget) { pContext->warning(__tr2qs_ctx("The window identifier preceded by WinId must be the first object in the search path","objects")); return false; } else { pWidget = g_pApp->findWindow(szName); } } else { if(pWidget) { pWidget = findWidgetToWrap(!szClass.isEmpty() ? szClass.toUtf8().data() : "", !szName.isEmpty() ? szName.toUtf8().data() : "", pWidget); } else { pWidget = findTopLevelWidgetToWrap(!szClass.isEmpty() ? szClass.toUtf8().data() : "", !szName.isEmpty() ? szName.toUtf8().data() : ""); } } if( !pWidget ) { pContext->warning(__tr2qs_ctx("Failed to find one of the wrap path widgets ('%Q::%Q')","objects"),&szClass,&szName); return false; } } i++; } if( !pWidget ) { pContext->warning(__tr2qs_ctx("Failed to find the widget to wrap","objects")); return false; } setObject(pWidget,false); return true; }
bool KvsObject_wrapper::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) { if(!pParams) return false; QWidget *pWidget = NULL; unsigned int i = 0; while(i < pParams->count()) { QString szClass; QString szName; QString s=0; pParams->at(i)->asString(s); i++; if(s.isEmpty()) continue; bool bRecursive = false; if(s.startsWith("*")) { s.remove(0,1); bRecursive = true; if(s.isEmpty()) { pContext->error(__tr2qs_ctx("The search specifier can't be empty","objects")); return false; } } int idx = s.indexOf("::"); if(idx != -1) { szClass = s.left(idx); szName = s.right(s.length() - idx - 2); } else { szClass = s; szName = ""; } if( KviQString::equalCI(szClass,"!Window") || KviQString::equalCI(szClass,"WinId") // compat ) { if(pWidget) pContext->warning(__tr2qs_ctx("The window identifier preceded by '!Window' should be the first in the search path","objects")); pWidget = g_pApp->findWindow(szName); } else if(KviQString::equalCI(szClass,"!Parent")) { if(!pWidget) { pContext->warning(__tr2qs_ctx("The '!Parent' specifier can't be used as first in the search path","objects")); return false; } int iLevels = 1; if(!szName.isEmpty()) { bool ok; int iLevels = szName.toInt(&ok); if(!ok) { pContext->warning(__tr2qs_ctx("Bad number of levels for the '!Parent' specifier","objects")); return false; } } while(iLevels > 0) { pWidget = pWidget->parentWidget(); if(!pWidget) { pContext->warning(__tr2qs_ctx("The '!Parent' specifier was applied to a widget that has no parent","objects")); return false; } iLevels--; } } else { if(pWidget) pWidget = findWidgetToWrap(szClass,szName,pWidget,bRecursive); else pWidget = findTopLevelWidgetToWrap(szClass,szName,bRecursive); } if(!pWidget) { pContext->error(__tr2qs_ctx("Failed to find one of the wrap path widgets ('%Q::%Q')","objects"),&szClass,&szName); return false; } } if(!pWidget) { pContext->error(__tr2qs_ctx("Failed to find the widget to wrap","objects")); return false; } setObject(pWidget,false); return true; }