Commit a6d329c5 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

QTabBar player/recorder now uses Tab-names for reliability.

pqTabBarEventPlayer still supports old-style test scripts that use indexes for
tab widget.
parent c56dc4ee
...@@ -41,37 +41,59 @@ pqTabBarEventPlayer::pqTabBarEventPlayer(QObject* p) ...@@ -41,37 +41,59 @@ pqTabBarEventPlayer::pqTabBarEventPlayer(QObject* p)
{ {
} }
bool pqTabBarEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) bool pqTabBarEventPlayer::playEvent(
QObject* target, const QString& command, const QString& arguments, bool& error_flag)
{ {
if(Command != "set_tab") if (command != "set_tab" && command != "set_tab_with_text")
{
// I don't handle this. Return false
return false; return false;
}
const QString value = Arguments; const QString value = arguments;
if(QTabBar* const object = qobject_cast<QTabBar*>(Object)) QTabBar* const tab_bar = qobject_cast<QTabBar*>(target);
if (tab_bar && command=="set_tab")
{ {
// "set_tab" saves tab index. This was done in the past. Newly recorded
// tests will use set_tab_with_text for more reliable playback.
bool ok = false; bool ok = false;
int which = value.toInt(&ok); int which = value.toInt(&ok);
if(!ok) if(!ok)
{ {
qCritical() << "calling set_tab with invalid argument on " << Object; qCritical() << "calling set_tab with invalid argument on " << target;
Error = true; error_flag = true;
} }
else if(object->count() < which) else if(tab_bar->count() < which)
{ {
qCritical() << "calling set_tab with out of bounds index on " << Object; qCritical() << "calling set_tab with out of bounds index on " << target;
Error = true; error_flag = true;
} }
else else
{ {
object->setCurrentIndex(which); tab_bar->setCurrentIndex(which);
}
return true;
}
if (tab_bar && command == "set_tab_with_text")
{
for (int cc=0 ; cc < tab_bar->count(); cc++)
{
if (tab_bar->tabText(cc) == value)
{
tab_bar->setCurrentIndex(cc);
return true;
}
} }
qCritical() << "calling set_tab with unknown tab " << value;
error_flag = true;
return true; return true;
} }
qCritical() << "calling set_tab on unhandled type " << Object; qCritical() << "calling set_tab on unhandled type " << target;
Error = true; error_flag = true;
return true; return true;
} }
...@@ -70,7 +70,7 @@ bool pqTabBarEventTranslator::translateEvent(QObject* Object, QEvent* Event, boo ...@@ -70,7 +70,7 @@ bool pqTabBarEventTranslator::translateEvent(QObject* Object, QEvent* Event, boo
void pqTabBarEventTranslator::indexChanged(int which) void pqTabBarEventTranslator::indexChanged(int which)
{ {
emit recordEvent(this->CurrentObject, "set_tab", emit recordEvent(this->CurrentObject, "set_tab_with_text",
QString("%1").arg(which)); this->CurrentObject->tabText(which));
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment