Rutin to log the actual widget tree / written by and useful for me
Added by Tibor Peak almost 7 years ago
I just share these routines that I use for debugging purposes:
The first is to show the widget variable name on the GUI when mouse pointer is hold over a widget:
#define DebugTooltip(vName) vName->setAttributeValue("title",#vName)
void myApplication::AddWidgetStructureDebugTitles(){
DebugTooltip(firstLine_CW);
DebugTooltip(secondLine_CW);
DebugTooltip(siaLogo_Img);
// .......
DebugTooltip(Feedback_OMF);
}
The second routine logs the widget tree structure (starting with the widget received as a parameter),
using the title attributes set by the previous routine:
void myApplication::ListWidgets(WWebWidget *startPoint, long Counter){
WWebWidget *thisWebWidget;
WTabWidget *thisTabWidget;
std::string thisTypeName;
std::string thisMessage;
std::string spaces(" "); // 48 space chars
char Buf[17];
std::vector< WWidget * > WidgetList;
WidgetList = startPoint->children();
for (vector<WWidget *>::iterator it = WidgetList.begin(); it != WidgetList.end(); ++it) {
thisWebWidget = (WWebWidget *)*it;
thisTypeName = typeid(*thisWebWidget).name();
sprintf(Buf,"%02ld",Counter);
thisMessage = Buf + (string)". " + spaces.substr(0, (Counter - 1) * 2) + thisTypeName;
thisMessage = thisMessage + spaces.substr(0, max(1, (40 - thisMessage.length())));
if (thisTypeName == "class Wt::WTabWidget") {
thisTabWidget = (WTabWidget *)*it;
wApp->log("Info:") << thisMessage << " / " << thisTabWidget->attributeValue("title");
short tabCount = thisTabWidget->count();
for (short i = 0; i < tabCount; i++) {
thisWebWidget = (WWebWidget *)(thisTabWidget->widget(i));
thisTypeName = typeid(*thisWebWidget).name();
thisMessage = Buf + (string)". " + spaces.substr(0, (Counter - 1) * 2) + thisTypeName;
thisMessage = thisMessage + spaces.substr(0, max(1, (40 - thisMessage.length())));
wApp->log("Info:") << thisMessage << " / " << thisWebWidget->attributeValue("title");
if (thisWebWidget->children().size() > 0) {
ListWidgets(thisWebWidget, Counter + 1);
}
}
} else {
wApp->log("Info:") << thisMessage << " / " << thisWebWidget->attributeValue("title");
if (thisWebWidget->children().size() > 0) {
ListWidgets(thisWebWidget, Counter + 1);
}
}
}
}
Feel free to use it.
Replies (3)
RE: Rutin to log the actual widget tree / written by and useful for me - Added by Mark Petryk almost 7 years ago
Thank you, Tibor.
Do you mind if I include these in some techniques on these Wt reference pages I'm assembling?
RE: Rutin to log the actual widget tree / written by and useful for me - Added by Tibor Peak almost 7 years ago
Hello Mark, it is ok for me.
RE: Rutin to log the actual widget tree / written by and useful for me - Added by Mark Petryk almost 7 years ago
You have hereby been immortalized, sir!
https://support.lorimarksolutions.com/wtx/domtree.html
Thank you.