Make jsdebug window update globals only on user request. This makes UI

much easier to work with, and prevents massive slowdown when big globals
are continuously updated in display.
master
per 2013-04-27 13:44:14 +02:00
parent 1e6e097e7a
commit 9fbf38f82b
3 changed files with 44 additions and 6 deletions

View File

@ -52,9 +52,12 @@
#define ATTACK_THROTTLE 1000
typedef QList<QStandardItem *> QStandardItemList;
/// selection changes are too often and too erratic to trigger immediately,
/// so until we have a queue system for events, delay triggering this way.
static bool selectionChanged = false;
extern bool doUpdateModels; // ugh-ly hack; fix with signal when moc-ing this file
enum timerType
{
@ -466,9 +469,10 @@ bool updateScripts()
callFunction(iter->engine, iter->function, args, true);
}
if (globalDialog)
if (globalDialog && doUpdateModels)
{
updateGlobalModels();
doUpdateModels = false;
}
return true;
@ -709,6 +713,31 @@ bool loadScriptStates(const char *filename)
return true;
}
static QStandardItemList addModelItem(QScriptValueIterator &it)
{
QStandardItemList l;
QStandardItem *key = new QStandardItem(it.name());
QStandardItem *value = NULL;
if (it.value().isObject() || it.value().isArray())
{
QScriptValueIterator obit(it.value());
while (obit.hasNext())
{
obit.next();
key->appendRow(addModelItem(obit));
}
value = new QStandardItem("[Object]");
}
else
{
value = new QStandardItem(it.value().toString());
}
l += key;
l += value;
return l;
}
static void updateGlobalModels()
{
for (int i = 0; i < scripts.size(); ++i)
@ -721,12 +750,11 @@ static void updateGlobalModels()
while (it.hasNext())
{
it.next();
if (!internalNamespace.contains(it.name()) && !it.value().isFunction())
if ((!internalNamespace.contains(it.name()) && !it.value().isFunction())
|| it.name() == "Upgrades" || it.name() == "Stats")
{
int nextRow = m->rowCount();
m->setRowCount(nextRow);
m->setItem(nextRow, 0, new QStandardItem(it.name()));
m->setItem(nextRow, 1, new QStandardItem(it.value().toString()));
QStandardItemList list = addModelItem(it);
m->appendRow(list);
}
}
}

View File

@ -51,6 +51,7 @@
#include "qtscriptfuncs.h"
static ScriptDebugger *globalDialog = NULL;
bool doUpdateModels = false;
// ----------------------------------------------------------
@ -74,11 +75,14 @@ ScriptDebugger::ScriptDebugger(const MODELMAP &models, QStandardItemModel *trigg
QLineEdit *lineEdit = new QLineEdit(this);
QVBoxLayout *layout = new QVBoxLayout();
QHBoxLayout *layout2 = new QHBoxLayout();
QPushButton *updateButton = new QPushButton("Update", this);
QPushButton *button = new QPushButton("Run", this);
connect(button, SIGNAL(pressed()), signalMapper, SLOT(map()));
connect(updateButton, SIGNAL(pressed()), this, SLOT(updateModels()));
signalMapper->setMapping(button, engine);
editMap.insert(engine, lineEdit); // store this for slot
layout->addWidget(view);
layout2->addWidget(updateButton);
layout2->addWidget(lineEdit);
layout2->addWidget(button);
layout->addLayout(layout2);
@ -133,6 +137,11 @@ void ScriptDebugger::runClicked(QObject *obj)
}
}
void ScriptDebugger::updateModels()
{
doUpdateModels = true;
}
void ScriptDebugger::labelClicked()
{
QItemSelectionModel *selected = labelView.selectionModel();

View File

@ -61,6 +61,7 @@ protected slots:
void labelClickedIdx(const QModelIndex &idx);
void labelClicked();
void runClicked(QObject *obj);
void updateModels();
};
void jsDebugCreate(const MODELMAP &models, QStandardItemModel *triggerModel);