mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 16:30:10 +02:00
complete Group Functionality i.e Group,GroupCollapsed,GroupEnd
This commit is contained in:
parent
c5d8268007
commit
2bd2804d0b
2 changed files with 140 additions and 126 deletions
|
@ -17,115 +17,122 @@
|
|||
#include "ScriptEngine.h"
|
||||
|
||||
void ConsoleScriptingInterface::info(QString message) {
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptInfoMessage(message);
|
||||
}
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptInfoMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleScriptingInterface::log(QString message) {
|
||||
void ConsoleScriptingInterface::log(QString message) {
|
||||
/*if (!listgrp.isEmpty()){
|
||||
listgrp.append(qMakePair(currentGroupSelection, message));
|
||||
listgrp.append(qMakePair(currentGroupSelection, message));
|
||||
}*/
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptPrintedMessage(message);
|
||||
}
|
||||
/*_listOfGroupData.append(qMakePair(_selectedGroup, message));
|
||||
if (!_listOfGroupData.isEmpty()) {
|
||||
showdata(_selectedGroup, message);
|
||||
}*/
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptPrintedMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleScriptingInterface::debug(QString message) {
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptPrintedMessage(message);
|
||||
}
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptPrintedMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleScriptingInterface::warn(QString message) {
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptWarningMessage(message);
|
||||
}
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptWarningMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleScriptingInterface::error(QString message) {
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptErrorMessage(message);
|
||||
}
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptErrorMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleScriptingInterface::exception(QString message) {
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptErrorMessage(message);
|
||||
}
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptErrorMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleScriptingInterface::time(QString labelName) {
|
||||
QDateTime _currentTime = QDateTime::currentDateTime().toUTC();
|
||||
_listOfTimeValues.insert(labelName, _currentTime.toUTC());
|
||||
QDateTime _currentTime = QDateTime::currentDateTime().toUTC();
|
||||
_listOfTimeValues.insert(labelName, _currentTime.toUTC());
|
||||
}
|
||||
|
||||
void ConsoleScriptingInterface::timeEnd(QString labelName) {
|
||||
QDateTime _dateTimeOfLabel;
|
||||
QString message;
|
||||
qint64 millisecondsDiff = 0;
|
||||
QDateTime _dateTimeOfLabel;
|
||||
QString message;
|
||||
qint64 millisecondsDiff = 0;
|
||||
|
||||
bool _labelInList = _listOfTimeValues.contains(labelName);
|
||||
|
||||
//Check if not exist items in list
|
||||
if (!_labelInList) {
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
message = "No such label found " + labelName;
|
||||
scriptEngine->scriptErrorMessage(message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
bool _labelInList = _listOfTimeValues.contains(labelName);
|
||||
|
||||
QDateTime _currentDateTimeValue = QDateTime::currentDateTime().toUTC();
|
||||
_dateTimeOfLabel = _listOfTimeValues.value(labelName);
|
||||
//Check if not exist items in list
|
||||
if (!_labelInList) {
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
message = "No such label found " + labelName;
|
||||
scriptEngine->scriptErrorMessage(message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_dateTimeOfLabel.isNull()) {
|
||||
_listOfTimeValues.remove(labelName);
|
||||
}
|
||||
|
||||
if (_dateTimeOfLabel.toString(TIME_FORMAT) == _currentDateTimeValue.toString(TIME_FORMAT)) {
|
||||
millisecondsDiff = _dateTimeOfLabel.msecsTo(_currentDateTimeValue);
|
||||
message = QString::number(millisecondsDiff) + " ms";
|
||||
} else {
|
||||
message = secondsToString(_dateTimeOfLabel.secsTo(_currentDateTimeValue));
|
||||
}
|
||||
QDateTime _currentDateTimeValue = QDateTime::currentDateTime().toUTC();
|
||||
_dateTimeOfLabel = _listOfTimeValues.value(labelName);
|
||||
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptPrintedMessage("Time : " + message);
|
||||
}
|
||||
if (!_dateTimeOfLabel.isNull()) {
|
||||
_listOfTimeValues.remove(labelName);
|
||||
}
|
||||
|
||||
if (_dateTimeOfLabel.toString(TIME_FORMAT) == _currentDateTimeValue.toString(TIME_FORMAT)) {
|
||||
millisecondsDiff = _dateTimeOfLabel.msecsTo(_currentDateTimeValue);
|
||||
message = QString::number(millisecondsDiff) + " ms";
|
||||
}
|
||||
else {
|
||||
message = secondsToString(_dateTimeOfLabel.secsTo(_currentDateTimeValue));
|
||||
}
|
||||
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptPrintedMessage("Time : " + message);
|
||||
}
|
||||
}
|
||||
|
||||
QString ConsoleScriptingInterface::secondsToString(qint64 seconds)
|
||||
{
|
||||
qint64 days = seconds / DAY;
|
||||
QTime timeDuration = QTime(0, 0).addSecs(seconds % DAY);
|
||||
{
|
||||
qint64 days = seconds / DAY;
|
||||
QTime timeDuration = QTime(0, 0).addSecs(seconds % DAY);
|
||||
|
||||
return QString("%1 days, %2 hours, %3 minutes, %4 seconds")
|
||||
.arg(QString::number(days)).arg(QString::number(timeDuration.hour())).arg(QString::number(timeDuration.minute())).arg(QString::number(timeDuration.second()));
|
||||
return QString("%1 days, %2 hours, %3 minutes, %4 seconds")
|
||||
.arg(QString::number(days)).arg(QString::number(timeDuration.hour())).arg(QString::number(timeDuration.minute())).arg(QString::number(timeDuration.second()));
|
||||
}
|
||||
|
||||
void ConsoleScriptingInterface::asserts(bool condition, QString message) {
|
||||
if (!condition) {
|
||||
QString assertFailed = "Assertion failed";
|
||||
if (message.isEmpty()) {
|
||||
message = assertFailed;
|
||||
} else {
|
||||
if (typeid(message) != typeid(QString)) {
|
||||
message = assertFailed;
|
||||
} else {
|
||||
message = assertFailed + " " + message;
|
||||
}
|
||||
}
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptErrorMessage(message);
|
||||
}
|
||||
}
|
||||
if (!condition) {
|
||||
QString assertFailed = "Assertion failed";
|
||||
if (message.isEmpty()) {
|
||||
message = assertFailed;
|
||||
}
|
||||
else {
|
||||
if (typeid(message) != typeid(QString)) {
|
||||
message = assertFailed;
|
||||
}
|
||||
else {
|
||||
message = assertFailed + " " + message;
|
||||
}
|
||||
}
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptErrorMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleScriptingInterface::trace(QString labelName) {
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptErrorMessage(labelName);
|
||||
}
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->scriptErrorMessage(labelName);
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleScriptingInterface::clear() {
|
||||
|
@ -135,60 +142,62 @@ void ConsoleScriptingInterface::clear() {
|
|||
}
|
||||
|
||||
void ConsoleScriptingInterface::group(QString groupName) {
|
||||
listgrp.append(qMakePair(defaultGroupName, groupName));
|
||||
currentGroupSelection = groupName;
|
||||
_listOfGroupData.append(qMakePair(GROUP, groupName));
|
||||
_selectedGroup = groupName;
|
||||
showdata(GROUP, groupName);
|
||||
}
|
||||
|
||||
void ConsoleScriptingInterface::groupCollapsed(QString groupName) {
|
||||
listgrp.append(qMakePair(defaultGroupCollapseName, groupName));
|
||||
currentGroupSelection = groupName;
|
||||
_listOfGroupData.append(qMakePair(GROUPCOLLAPSED, groupName));
|
||||
_selectedGroup = groupName;
|
||||
showdata(GROUPCOLLAPSED, groupName);
|
||||
}
|
||||
|
||||
void ConsoleScriptingInterface::consoleLog(QString groupName) {
|
||||
if (!listgrp.isEmpty()){
|
||||
listgrp.append(qMakePair(currentGroupSelection, groupName));
|
||||
void ConsoleScriptingInterface::consoleLog(QString message) {
|
||||
_listOfGroupData.append(qMakePair(_selectedGroup, message));
|
||||
if (!_listOfGroupData.isEmpty()) {
|
||||
showdata(_selectedGroup, message);
|
||||
}
|
||||
}
|
||||
|
||||
int collapseCount = 0;
|
||||
QString addSpace = " ";
|
||||
void ConsoleScriptingInterface::groupEnd() {
|
||||
QString endGroup= "endGroup";
|
||||
listgrp.append(qMakePair(currentGroupSelection, endGroup));
|
||||
//currentGroupSelection = groupName;
|
||||
void ConsoleScriptingInterface::groupEnd() {
|
||||
_listOfGroupData.append(qMakePair(_selectedGroup, GROUPEND));
|
||||
showdata(_selectedGroup, GROUPEND);
|
||||
}
|
||||
|
||||
void show(){
|
||||
QString tmp;
|
||||
QPair<QString, QString> pair;
|
||||
for (int i = 0; i<listgrp.count(); i++) {
|
||||
pair = listgrp.at(i);
|
||||
if (pair.first == "group") {
|
||||
tmp = pair.second;
|
||||
addSpace = "";
|
||||
debug(pair.second);
|
||||
}
|
||||
else if (pair.first == "groupCollapse") {
|
||||
tmp = pair.second;
|
||||
int count = 0;
|
||||
addSpace = collapseCount == 0 ? "\t" : " ";
|
||||
while (count<collapseCount) {
|
||||
addSpace += '\t\t';
|
||||
count++;
|
||||
void ConsoleScriptingInterface::showdata(QString currentGroup, QString groupName) {
|
||||
QPair<QString, QString> groupData;
|
||||
QString firstGroupData;
|
||||
|
||||
for (int index = 0; index<_listOfGroupData.count(); index++) {
|
||||
groupData = _listOfGroupData.at(index);
|
||||
firstGroupData = groupData.first;
|
||||
if (groupData.first == GROUP || groupData.first == GROUPCOLLAPSED) {
|
||||
firstGroupData = groupData.second;
|
||||
if (_isSameLevel) {
|
||||
_addSpace = _addSpace.mid(0, _addSpace.length() - 3);
|
||||
}
|
||||
collapseCount++;
|
||||
pair.second = addSpace + pair.second;
|
||||
debug(pair.second);
|
||||
}
|
||||
else {
|
||||
if (pair.first == tmp) {
|
||||
pair.second = addSpace + pair.second;
|
||||
debug(pair.second);
|
||||
_addSpace += " "; //add inner groupcollapsed
|
||||
|
||||
if (groupData.first == GROUPCOLLAPSED) {
|
||||
QString space = _addSpace.mid(0, _addSpace.length() - 1);
|
||||
debug(space + groupData.second);
|
||||
} else {
|
||||
debug(_addSpace + groupData.second);
|
||||
}
|
||||
_isSameLevel = false;
|
||||
} else if (groupData.second == GROUPEND) {
|
||||
_addSpace = _addSpace.mid(0, _addSpace.length() - 3);
|
||||
} else {
|
||||
if (groupData.first == firstGroupData && groupData.first != GROUPCOLLAPSED && groupData.first != GROUP && groupData.second != GROUPEND) {
|
||||
if (!_isSameLevel) {
|
||||
_addSpace += " "; //2 space inner element
|
||||
_isSameLevel = true; //same level log entry
|
||||
}
|
||||
debug(_addSpace + groupData.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
addSpace = "";
|
||||
tmp = "";
|
||||
collapseCount = 0;
|
||||
listgrp.clear();
|
||||
}
|
||||
_listOfGroupData.removeOne(qMakePair(currentGroup, groupName));
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <QtCore/QString>
|
||||
#include <QtScript/QScriptable>
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
|
||||
|
||||
/// Scriptable interface of console object. Used exclusively in the JavaScript API
|
||||
|
@ -35,25 +36,29 @@ public slots:
|
|||
void error(QString message);
|
||||
void exception(QString message);
|
||||
void time(QString labelName);
|
||||
void timeEnd(QString labelName);
|
||||
void timeEnd(QString labelName);
|
||||
void asserts(bool condition, QString message = "");
|
||||
void trace(QString labelName);
|
||||
void clear();
|
||||
void clear();
|
||||
void group(QString groupName);
|
||||
void groupCollapsed(QString groupName);
|
||||
void consoleLog(QString groupName);
|
||||
void groupEnd();
|
||||
void groupCollapsed(QString groupName);
|
||||
void groupEnd();
|
||||
void consoleLog(QString message);
|
||||
void showdata(QString currentGroup, QString groupName);
|
||||
public:
|
||||
QString secondsToString(qint64 seconds);
|
||||
bool isInteger(const std::string & s);
|
||||
private:
|
||||
QHash<QString, QDateTime> _listOfTimeValues;
|
||||
const qint64 DAY = 86400;
|
||||
const QString TIME_FORMAT = "yyyy-MM-dd HH:mm";
|
||||
QString currentGroupSelection;
|
||||
QString defaultGroupName = "group";
|
||||
QString defaultGroupCollapseName = "groupCollapse";
|
||||
QList<QPair<QString, QString> > listgrp;
|
||||
const QString TIME_FORMAT = "yyyy-MM-dd HH:mm";
|
||||
QString _selectedGroup;
|
||||
const QString GROUP = "group";
|
||||
const QString GROUPCOLLAPSED = "groupCollapse";
|
||||
const QString GROUPEND = "groupEnd";
|
||||
bool _isSameLevel = false;
|
||||
QString _addSpace = "";
|
||||
QList<QPair<QString, QString> > _listOfGroupData;
|
||||
};
|
||||
|
||||
#endif // hifi_ConsoleScriptingInterface_h
|
||||
|
|
Loading…
Reference in a new issue