Skip to content

Commit d6bb576

Browse files
utkarshayachitkwrobot
authored andcommitted
Merge topic 'fix_bad_object_names'
20f23d3 Fixes issues when test playback fails to find an object. Acked-by: Kitware Robot <[email protected]> Acked-by: Ben Boeckel <[email protected]> Merge-request: !10
2 parents c44b32f + 20f23d3 commit d6bb576

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

pqEventPlayer.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ void pqEventPlayer::playEvent(const QString& objectString,
178178

179179
if(!object && !command.startsWith("comment"))
180180
{
181-
qCritical() << pqObjectNaming::lastErrorMessage();
182-
emit this->errorMessage(pqObjectNaming::lastErrorMessage());
181+
QString errorMsg = pqObjectNaming::lastErrorMessage();
182+
qCritical() << (errorMsg.toLocal8Bit().data());
183+
emit this->errorMessage(errorMsg);
183184
error = true;
184185
return;
185186
}

pqObjectNaming.cxx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5151
#include <QStackedWidget>
5252
#include <QTabBar>
5353
#include <QTabWidget>
54+
#include <QtDebug>
55+
#include <QTextStream>
5456
#include <QToolBar>
5557
#include <QToolButton>
56-
#include <QtDebug>
57-
5858

5959
namespace
6060
{
@@ -250,34 +250,46 @@ QObject* pqObjectNaming::GetObject(const QString& Name)
250250

251251
if(result)
252252
return result;
253-
254-
ErrorMessage = QString("Couldn't find object %1\n").arg(Name);
255-
if(lastObject)
253+
254+
ErrorMessage.clear();
255+
QTextStream stream(&ErrorMessage);
256+
stream << "Couldn't find object `"<< Name << "`\n";
257+
if (lastObject)
256258
{
257-
ErrorMessage += QString("Found up to %1\n").arg(
258-
pqObjectNaming::GetName(*lastObject));
259+
stream << "Found up to `" << pqObjectNaming::GetName(*lastObject) << "`\n";
259260
}
261+
262+
// controls how many matches to dump in error message.
263+
QString matchLimitEnv = QString::fromLocal8Bit(qgetenv("PQOBJECTNAMING_MATCH_LIMIT"));
264+
const int matchLimit = matchLimitEnv.isEmpty() ? 20 : matchLimitEnv.toInt();
265+
260266
bool foundMatch = false;
261267
if(lastObject)
262268
{
263-
QObjectList matches =
264-
lastObject->findChildren<QObject*>(names[names.size()-1]);
265-
foreach(QObject* o, matches)
269+
const QObjectList matches = lastObject->findChildren<QObject*>(names[names.size()-1]);
270+
for (int cc=0; (matchLimit <= 0 || cc < matchLimit) && cc < matches.size(); ++cc)
271+
{
272+
stream << "\tPossible match: `" << pqObjectNaming::GetName(*matches[cc]) << "`\n";
273+
}
274+
if (matchLimit > 0 && matches.size() > matchLimit)
266275
{
267-
ErrorMessage += QString("\tPossible match: %1\n").arg(pqObjectNaming::GetName(*o));
268-
foundMatch = true;
276+
stream << "\tPossible match: .... (and " << (matches.size() - matchLimit) << " more!)\n"
277+
<< "\tSet PQOBJECTNAMING_MATCH_LIMIT environment var to a +'ve number to limit entries (or 0 for unlimited).\n";
269278
}
270279
}
271280
if (!foundMatch)
272281
{
273-
QObjectList matches = lastObject->findChildren<QObject*>();
274-
foreach(QObject* o, matches)
282+
const QObjectList matches = lastObject->findChildren<QObject*>();
283+
for (int cc=0; (matchLimit <= 0 || cc < matchLimit) && cc < matches.size(); ++cc)
275284
{
276-
ErrorMessage += QString("\tAvailable widget: %1\n").arg(pqObjectNaming::GetName(*o));
285+
stream << "\tAvailable widget: `" << pqObjectNaming::GetName(*matches[cc]) << "`\n";
286+
}
287+
if (matchLimit > 0 && matches.size() > matchLimit)
288+
{
289+
stream << "\tAvailable widget: .... (and " << (matches.size() - matchLimit) << " more!)\n"
290+
<< "\tSet PQOBJECTNAMING_MATCH_LIMIT environment var to a +'ve number to limit entries (or 0 for unlimited).\n";
277291
}
278292
}
279-
280-
qCritical() << ErrorMessage ;
281293
return 0;
282294
}
283295

0 commit comments

Comments
 (0)