@@ -51,10 +51,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51
51
#include < QStackedWidget>
52
52
#include < QTabBar>
53
53
#include < QTabWidget>
54
+ #include < QtDebug>
55
+ #include < QTextStream>
54
56
#include < QToolBar>
55
57
#include < QToolButton>
56
- #include < QtDebug>
57
-
58
58
59
59
namespace
60
60
{
@@ -250,34 +250,46 @@ QObject* pqObjectNaming::GetObject(const QString& Name)
250
250
251
251
if (result)
252
252
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)
256
258
{
257
- ErrorMessage += QString (" Found up to %1\n " ).arg (
258
- pqObjectNaming::GetName (*lastObject));
259
+ stream << " Found up to `" << pqObjectNaming::GetName (*lastObject) << " `\n " ;
259
260
}
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
+
260
266
bool foundMatch = false ;
261
267
if (lastObject)
262
268
{
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 << " \t Possible match: `" << pqObjectNaming::GetName (*matches[cc]) << " `\n " ;
273
+ }
274
+ if (matchLimit > 0 && matches.size () > matchLimit)
266
275
{
267
- ErrorMessage += QString ( " \t Possible match: %1 \n " ). arg ( pqObjectNaming::GetName (*o));
268
- foundMatch = true ;
276
+ stream << " \t Possible match: .... (and " << (matches. size () - matchLimit) << " more!) \n "
277
+ << " \t Set PQOBJECTNAMING_MATCH_LIMIT environment var to a +'ve number to limit entries (or 0 for unlimited). \n " ;
269
278
}
270
279
}
271
280
if (!foundMatch)
272
281
{
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 )
275
284
{
276
- ErrorMessage += QString (" \t Available widget: %1\n " ).arg (pqObjectNaming::GetName (*o));
285
+ stream << " \t Available widget: `" << pqObjectNaming::GetName (*matches[cc]) << " `\n " ;
286
+ }
287
+ if (matchLimit > 0 && matches.size () > matchLimit)
288
+ {
289
+ stream << " \t Available widget: .... (and " << (matches.size () - matchLimit) << " more!)\n "
290
+ << " \t Set PQOBJECTNAMING_MATCH_LIMIT environment var to a +'ve number to limit entries (or 0 for unlimited).\n " ;
277
291
}
278
292
}
279
-
280
- qCritical () << ErrorMessage ;
281
293
return 0 ;
282
294
}
283
295
0 commit comments