Formats minimally release source files based on former clang-format

This commit is contained in:
torsten committed 2026-10-14 13:28:01 +00:00
1 parent b662e4daf9
commit 5644914fe3
387 files changed
+37323 -38074

No files matched your search

@@ -17,8 +17,7 @@
#include <TrainingAreaBase/training_area_telegrams.h>
static QSet<int> s_eqIds;
template <typename T>
bool validEqId(const T &tele)
template <typename T> bool validEqId(const T &tele)
{
if (!s_eqIds.isEmpty() && !s_eqIds.contains(tele.header.equipmentNumber))
return false;
@@ -46,24 +45,21 @@ int main(int argc, char **argv)
if (app.arguments().count() < 3)
{
ERROR_LOG(logger) << "Usage: " << app.arguments().at(0)
<< " <logfile> <telId> <equipId>";
ERROR_LOG(logger) << "Usage: " << app.arguments().at(0) << " <logfile> <telId> <equipId>";
return 1;
}
QFile telegramFile(app.arguments().at(1));
if (!telegramFile.open(QIODevice::ReadOnly))
{
ERROR_LOG(logger) << "Error opening " << telegramFile.fileName()
<< " for reading: " << telegramFile.errorString();
ERROR_LOG(logger) << "Error opening " << telegramFile.fileName() << " for reading: " << telegramFile.errorString();
return 2;
}
bool bOk;
int telIdToSearch = app.arguments().at(2).toUShort(&bOk);
if (!bOk)
{
ERROR_LOG(logger) << "Error reading telId - not a (valid) number: "
<< app.arguments().at(2);
ERROR_LOG(logger) << "Error reading telId - not a (valid) number: " << app.arguments().at(2);
return 3;
}
s_eqIds.clear();
@@ -72,8 +68,7 @@ int main(int argc, char **argv)
int eqId = app.arguments().at(i).toUShort(&bOk);
if (!bOk)
{
ERROR_LOG(logger) << "Error reading equipId - not a (valid) number: "
<< app.arguments().at(i);
ERROR_LOG(logger) << "Error reading equipId - not a (valid) number: " << app.arguments().at(i);
return 4;
}
s_eqIds += eqId;
@@ -94,97 +89,81 @@ int main(int argc, char **argv)
if (telegramLength == telegramFile.read(telegramData.data(), telegramLength))
{
// add the telegram to telegram-list
N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol dest = (N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol)
(lh.m_Protocol & N_CoPrtCnv::CoPrtCnvLogHeader::e_DestProtocolMask);
N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol dest =
(N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol)(lh.m_Protocol & N_CoPrtCnv::CoPrtCnvLogHeader::e_DestProtocolMask);
switch (dest)
{
case N_CoPrtCnv::CoPrtCnvLogHeader::e_DestProtocolCentral:
{
const QJsonObject obj = QJsonDocument::fromJson(telegramData).object();
int telId = obj.value(QStringLiteral("typeId")).toInt();
if (telIdToSearch != telId)
continue;
case N_CoPrtCnv::CoPrtCnvLogHeader::e_DestProtocolCentral:
{
const QJsonObject obj = QJsonDocument::fromJson(telegramData).object();
int telId = obj.value(QStringLiteral("typeId")).toInt();
if (telIdToSearch != telId)
continue;
const QJsonObject objData = obj.value(QStringLiteral("data")).toObject();
const QJsonObject objData = obj.value(QStringLiteral("data")).toObject();
const QByteArray tBA = formatTime(lh.m_Time);
const char *timeStr = tBA.constData();
switch (telId)
{
case Constraints<CreateFunctionalArea>::id():
{
const CreateFunctionalArea tele(CreateFunctionalArea::fromJson(objData));
if (!validEqId(tele))
break;
fprintf(stdout, "%s, FUNKTIONSRAUM: '%s', %d, %d\n",
timeStr,
tele.name.c_str(),
tele.aesDdsId,
tele.header.equipmentNumber
);
break;
}
case Constraints<DeactivateEffectSimulation>::id():
{
const DeactivateEffectSimulation tele(DeactivateEffectSimulation::fromJson(objData));
fprintf(stdout, "%s, DEAKTIVIERUNG_WIRKFELD: typ: %d - kennung: %d\n",
timeStr,
int(tele.aesType),
tele.aesDdsId
);
break;
}
case Constraints<PositionReport>::id():
{
const PositionReport tele(PositionReport::fromJson(objData));
if (!validEqId(tele))
break;
if (tele.opsPosition.opsId == 0)
break;
fprintf(stdout, "%s, IPS_POSITIONSDATEN: %d - OPS: %d\n",
timeStr,
tele.header.equipmentNumber,
tele.opsPosition.opsId
);
break;
}
case BESTAETIGUNG:
case UMGEBUNGS_MELDUNG2:
break;
default:
fprintf(stderr, "Printing telegram with id %d not implemented\n", telId);
break;
}
break;
}
case N_CoPrtCnv::CoPrtCnvLogHeader::e_DestProtocolTetra:
{
N_CoPrtCnv::CoPrtCnvRadioTelegram radioTelegram(telegramData);
gef_telegramm_id_et telId = radioTelegram.getTelID();
if (telId == GEF_UMGEBUNGS_MELDUNG2)
{
const QByteArray tBA = formatTime(lh.m_Time);
const char *timeStr = tBA.constData();
static uint16_t bci = 0xFFFF;
if (bci != radioTelegram.getBroadcastIndex())
switch (telId)
{
if (bci > radioTelegram.getBroadcastIndex() && bci != 0xFFFF)
case Constraints<CreateFunctionalArea>::id():
{
fprintf(stdout, "BCI reset in %s at %s!\n",
qPrintable(telegramFile.fileName()),
timeStr);
const CreateFunctionalArea tele(CreateFunctionalArea::fromJson(objData));
if (!validEqId(tele))
break;
fprintf(stdout, "%s, FUNKTIONSRAUM: '%s', %d, %d\n", timeStr, tele.name.c_str(), tele.aesDdsId, tele.header.equipmentNumber);
break;
}
fprintf(stdout, "BCI: %d\n", radioTelegram.getBroadcastIndex());
bci = radioTelegram.getBroadcastIndex();
case Constraints<DeactivateEffectSimulation>::id():
{
const DeactivateEffectSimulation tele(DeactivateEffectSimulation::fromJson(objData));
fprintf(stdout, "%s, DEAKTIVIERUNG_WIRKFELD: typ: %d - kennung: %d\n", timeStr, int(tele.aesType), tele.aesDdsId);
break;
}
case Constraints<PositionReport>::id():
{
const PositionReport tele(PositionReport::fromJson(objData));
if (!validEqId(tele))
break;
if (tele.opsPosition.opsId == 0)
break;
fprintf(stdout, "%s, IPS_POSITIONSDATEN: %d - OPS: %d\n", timeStr, tele.header.equipmentNumber, tele.opsPosition.opsId);
break;
}
case BESTAETIGUNG:
case UMGEBUNGS_MELDUNG2:
break;
default:
fprintf(stderr, "Printing telegram with id %d not implemented\n", telId);
break;
}
break;
}
break;
}
default:
break;
case N_CoPrtCnv::CoPrtCnvLogHeader::e_DestProtocolTetra:
{
N_CoPrtCnv::CoPrtCnvRadioTelegram radioTelegram(telegramData);
gef_telegramm_id_et telId = radioTelegram.getTelID();
if (telId == GEF_UMGEBUNGS_MELDUNG2)
{
const QByteArray tBA = formatTime(lh.m_Time);
const char *timeStr = tBA.constData();
static uint16_t bci = 0xFFFF;
if (bci != radioTelegram.getBroadcastIndex())
{
if (bci > radioTelegram.getBroadcastIndex() && bci != 0xFFFF)
{
fprintf(stdout, "BCI reset in %s at %s!\n", qPrintable(telegramFile.fileName()), timeStr);
}
fprintf(stdout, "BCI: %d\n", radioTelegram.getBroadcastIndex());
bci = radioTelegram.getBroadcastIndex();
}
}
break;
}
default:
break;
}
}
}
@@ -19,479 +19,492 @@
namespace N_SST
{
IntegerCalculator::IntegerCalculator()
: m_OperationList({{"*", 6},{"/", 6},{"%", 6},{"+", 5},{"-", 5},{"<<", 4},{">>", 4}})
, m_AdditionalErrorText()
, m_ParanthesisCount(0)
, m_Error(IntegerCalculator::e_Ok)
{
}
// ---------------------------------------------------------------
// Converts the expressen in a_calcText into a signed value.
// Returns whether an error happend in the variable a_error.
// If an error happend, the variable a_addErrorText can
// contain more informaition about the error (see E_Error for
// more information about errors).
// ---------------------------------------------------------------
int64_t IntegerCalculator::calc(const std::string& a_calcText, E_Error& a_error, std::string* a_addErrorText)
{
std::string calcText = a_calcText;
// separate operations from variables
for (auto iter = m_OperationList.begin(); iter != m_OperationList.end(); ++iter)
replace(calcText, iter->first, " "+iter->first+" ");
// separate paranthesis from variables
replace(calcText, "(", " ( ");
replace(calcText, ")", " ) ");
// now calculate the expression
m_ParanthesisCount = 0;
m_Error = e_Ok;
m_AdditionalErrorText = "";
size_t pos = 0;
bool dummy;
int64_t value = calc(calcText, pos, dummy, "", 0, "+"); // todo: use member-variable m_CalcText
//M_INFO("calc: " << calcText << " value: " << value);
// check the paranthesis
if (m_Error == e_Ok)
IntegerCalculator::IntegerCalculator()
: m_OperationList({{"*", 6}, {"/", 6}, {"%", 6}, {"+", 5}, {"-", 5}, {"<<", 4}, {">>", 4}})
, m_AdditionalErrorText()
, m_ParanthesisCount(0)
, m_Error(IntegerCalculator::e_Ok)
{
if (m_ParanthesisCount > 0)
{
m_Error = e_MissingRightParanthesis;
}
else if (m_ParanthesisCount < 0)
{
m_Error = e_MissingLeftParanthesis;
}
else if (pos != calcText.length())
{
m_Error = e_UnknownError;
}
}
// actions if a failure happens
a_error = m_Error;
if (a_error != e_Ok)
// ---------------------------------------------------------------
// Converts the expressen in a_calcText into a signed value.
// Returns whether an error happend in the variable a_error.
// If an error happend, the variable a_addErrorText can
// contain more informaition about the error (see E_Error for
// more information about errors).
// ---------------------------------------------------------------
int64_t IntegerCalculator::calc(const std::string &a_calcText, E_Error &a_error, std::string *a_addErrorText)
{
value = 0;
if (a_addErrorText)
std::string calcText = a_calcText;
// separate operations from variables
for (auto iter = m_OperationList.begin(); iter != m_OperationList.end(); ++iter)
replace(calcText, iter->first, " " + iter->first + " ");
// separate paranthesis from variables
replace(calcText, "(", " ( ");
replace(calcText, ")", " ) ");
// now calculate the expression
m_ParanthesisCount = 0;
m_Error = e_Ok;
m_AdditionalErrorText = "";
size_t pos = 0;
bool dummy;
int64_t value = calc(calcText, pos, dummy, "", 0, "+"); // todo: use member-variable m_CalcText
//M_INFO("calc: " << calcText << " value: " << value);
// check the paranthesis
if (m_Error == e_Ok)
{
*a_addErrorText = m_AdditionalErrorText;
}
}
return value;
}
// ---------------------------------------------------------------
// Adds or changes a case-sensitive variable to the calculator.
// ---------------------------------------------------------------
void IntegerCalculator::addVariable(const std::string& a_name, const int64_t a_value)
{
std::map<std::string, int64_t>::iterator iter = m_VariableList.find(a_name);
if (iter != m_VariableList.end())
removeVariable(a_name);
m_VariableList.insert(std::make_pair(a_name, a_value));
}
// ---------------------------------------------------------------
// Removes a case-sensitive variable from the calculator.
// ---------------------------------------------------------------
void IntegerCalculator::removeVariable(const std::string& a_name)
{
std::map<std::string, int64_t>::iterator iter = m_VariableList.find(a_name);
if (iter != m_VariableList.end())
m_VariableList.erase(iter);
}
// ---------------------------------------------------------------
// Calculates the expression (recursive)
// ---------------------------------------------------------------
int64_t IntegerCalculator::calc(const std::string& a_calcText, size_t& a_pos, bool& a_IsEndParanthesis,
const std::string& a_prevOp, const int64_t a_prevValue,
const std::string& a_initOp)
{
std::string operation = a_initOp;
int64_t value1 = a_prevValue;
bool isNegative = false;
std::string calcText = a_calcText;
a_IsEndParanthesis = false;
while (a_pos < calcText.length())
{
if (' ' == calcText[a_pos])
{
a_pos++;
}
else if ('(' == calcText[a_pos])
{
m_ParanthesisCount++;
bool dummy;
int64_t value2 = calcSign(calc(calcText, ++a_pos, dummy), isNegative);
value1 = doOperation(value1, operation, value2);
// get next operation to check priority of operation
size_t tmpPos = a_pos; // do not change the position, we only pre-read
std::string nextOp = getToken(a_calcText, tmpPos);
if (isOperation(nextOp) && isOperation(a_prevOp) && !isOperationPriorityHigher(nextOp, a_prevOp))
if (m_ParanthesisCount > 0)
{
// end of higher priority operation
m_Error = e_MissingRightParanthesis;
}
else if (m_ParanthesisCount < 0)
{
m_Error = e_MissingLeftParanthesis;
}
else if (pos != calcText.length())
{
m_Error = e_UnknownError;
}
}
// actions if a failure happens
a_error = m_Error;
if (a_error != e_Ok)
{
value = 0;
if (a_addErrorText)
{
*a_addErrorText = m_AdditionalErrorText;
}
}
return value;
}
// ---------------------------------------------------------------
// Adds or changes a case-sensitive variable to the calculator.
// ---------------------------------------------------------------
void IntegerCalculator::addVariable(const std::string &a_name, const int64_t a_value)
{
std::map<std::string, int64_t>::iterator iter = m_VariableList.find(a_name);
if (iter != m_VariableList.end())
removeVariable(a_name);
m_VariableList.insert(std::make_pair(a_name, a_value));
}
// ---------------------------------------------------------------
// Removes a case-sensitive variable from the calculator.
// ---------------------------------------------------------------
void IntegerCalculator::removeVariable(const std::string &a_name)
{
std::map<std::string, int64_t>::iterator iter = m_VariableList.find(a_name);
if (iter != m_VariableList.end())
m_VariableList.erase(iter);
}
// ---------------------------------------------------------------
// Calculates the expression (recursive)
// ---------------------------------------------------------------
int64_t IntegerCalculator::calc(const std::string &a_calcText,
size_t &a_pos,
bool &a_IsEndParanthesis,
const std::string &a_prevOp,
const int64_t a_prevValue,
const std::string &a_initOp)
{
std::string operation = a_initOp;
int64_t value1 = a_prevValue;
bool isNegative = false;
std::string calcText = a_calcText;
a_IsEndParanthesis = false;
while (a_pos < calcText.length())
{
if (' ' == calcText[a_pos])
{
a_pos++;
}
else if ('(' == calcText[a_pos])
{
m_ParanthesisCount++;
bool dummy;
int64_t value2 = calcSign(calc(calcText, ++a_pos, dummy), isNegative);
value1 = doOperation(value1, operation, value2);
// get next operation to check priority of operation
size_t tmpPos = a_pos; // do not change the position, we only pre-read
std::string nextOp = getToken(a_calcText, tmpPos);
if (isOperation(nextOp) && isOperation(a_prevOp) && !isOperationPriorityHigher(nextOp, a_prevOp))
{
// end of higher priority operation
return value1;
}
operation = "";
}
else if (')' == calcText[a_pos])
{
m_ParanthesisCount--;
a_pos++;
a_IsEndParanthesis = true;
return value1;
}
operation = "";
}
else if (')' == calcText[a_pos])
{
m_ParanthesisCount--;
a_pos++;
a_IsEndParanthesis = true;
return value1;
}
else if (isDigit(calcText[a_pos]))
{
// value
// -----
int64_t value2 = calcSign(convertValue(calcText, a_pos), isNegative);
if (calcWithPriority(calcText, a_pos, value1, operation, value2, a_prevOp)) return value1;
}
else
{
// operation or variable
// ---------------------
std::string oldOperation = operation;
operation = getToken(calcText, a_pos);
// is it a variable?
if (!isOperation(operation))
else if (isDigit(calcText[a_pos]))
{
int64_t value2 = 0;
if (getVariableValue(operation, value2))
{
value2 = calcSign(value2, isNegative);
if (calcWithPriority(calcText, a_pos, value1, oldOperation, value2, a_prevOp)) return value1;
operation = "";
}
else
{
// error
m_Error = e_UnknownOperationOrVariable;
m_AdditionalErrorText = operation;
}
// value
// -----
int64_t value2 = calcSign(convertValue(calcText, a_pos), isNegative);
if (calcWithPriority(calcText, a_pos, value1, operation, value2, a_prevOp))
return value1;
}
else
{
// do we have a sign?
if (oldOperation != "")
// operation or variable
// ---------------------
std::string oldOperation = operation;
operation = getToken(calcText, a_pos);
// is it a variable?
if (!isOperation(operation))
{
if (operation == "+")
int64_t value2 = 0;
if (getVariableValue(operation, value2))
{
operation = oldOperation;
}
else if (operation == "-")
{
isNegative = !isNegative;
operation = oldOperation;
value2 = calcSign(value2, isNegative);
if (calcWithPriority(calcText, a_pos, value1, oldOperation, value2, a_prevOp))
return value1;
operation = "";
}
else
{
m_Error = e_NoOperandBetweenOperators;
m_AdditionalErrorText = oldOperation + " " + operation;
return 0;
// error
m_Error = e_UnknownOperationOrVariable;
m_AdditionalErrorText = operation;
}
}
else
{
// do we have a sign?
if (oldOperation != "")
{
if (operation == "+")
{
operation = oldOperation;
}
else if (operation == "-")
{
isNegative = !isNegative;
operation = oldOperation;
}
else
{
m_Error = e_NoOperandBetweenOperators;
m_AdditionalErrorText = oldOperation + " " + operation;
return 0;
}
}
}
}
}
return value1;
}
return value1;
}
// ---------------------------------------------------------------
// Calculates an operation with respecting the priority of
// operations. This will be done with recursion.
// ---------------------------------------------------------------
bool IntegerCalculator::calcWithPriority(const std::string& a_calcText, size_t& a_pos, int64_t& a_value1, std::string& a_operation, int64_t a_value2, const std::string& a_prevOp)
{
bool isParaEnd = false;
// get next operation to check priority of operation
size_t tmpPos = a_pos; // only pre-read
std::string nextOp = getToken(a_calcText, tmpPos);
if (isOperation(a_operation) && isOperation(nextOp) && isOperationPriorityHigher(nextOp, a_operation))
// ---------------------------------------------------------------
// Calculates an operation with respecting the priority of
// operations. This will be done with recursion.
// ---------------------------------------------------------------
bool IntegerCalculator::calcWithPriority(const std::string &a_calcText,
size_t &a_pos,
int64_t &a_value1,
std::string &a_operation,
int64_t a_value2,
const std::string &a_prevOp)
{
// next operation has higher priority => calc the next operation first
a_value2 = calc(a_calcText, a_pos, isParaEnd, a_operation, a_value2);
}
a_value1 = doOperation(a_value1, a_operation, a_value2);
if (isParaEnd || (isOperation(nextOp) && isOperation(a_prevOp) && !isOperationPriorityHigher(nextOp, a_prevOp)))
{
// end of higher priority operation
return true;
}
a_operation = "";
return false;
}
// ---------------------------------------------------------------
// Returns the inverted a_value if a_isNegative is true.
// a_isNegative will be false after calling this function.
// If a_isNegative is true, the NOT inverted a_value will be
// returned.
// ---------------------------------------------------------------
int64_t IntegerCalculator::calcSign(const int64_t a_value, bool& a_isNegative)
{
if (a_isNegative)
{
a_isNegative = false;
return -a_value;
}
return a_value;
}
// ---------------------------------------------------------------
// Converts the value in form of text to a number. The Text
// can be decimal, hex (0x) or binary (0b).
// ---------------------------------------------------------------
int64_t IntegerCalculator::convertValue(const std::string &a_valueText, size_t& a_pos)
{
std::string valueText = a_valueText.substr(a_pos);
int base = 10;
size_t startpos = 0;
// hex- and binary-stuff
bool isHex = (0 == valueText.find("0X")) || (0 == valueText.find("0x"));
bool isBin = (0 == valueText.find("0B")) || (0 == valueText.find("0b"));
if (isHex)
{
base = 16;
startpos = 2;
}
else if (isBin)
{
base = 2;
startpos = 2;
}
// search end of value
size_t i;
for (i=startpos; i<valueText.length(); i++)
{
if (!isDigit(valueText[i], isHex, isBin))
bool isParaEnd = false;
// get next operation to check priority of operation
size_t tmpPos = a_pos; // only pre-read
std::string nextOp = getToken(a_calcText, tmpPos);
if (isOperation(a_operation) && isOperation(nextOp) && isOperationPriorityHigher(nextOp, a_operation))
{
break;
// next operation has higher priority => calc the next operation first
a_value2 = calc(a_calcText, a_pos, isParaEnd, a_operation, a_value2);
}
}
// check the next char, it must be a space
if (valueText.length() > i && valueText[i] != ' ')
{
m_Error = e_InvalidOperand;
int spacePos = valueText.find(' ');
m_AdditionalErrorText = valueText.substr(0, spacePos);
}
a_pos += i;
int64_t value = 0;
std::stringstream stream;
stream.str(valueText.substr(startpos, i-startpos));
if (2 == base)
{
// our stl is not able to read in binary-values, therefore we have to implement it ourself
const std::string binValueAsText = stream.str();
for (const char c : binValueAsText)
a_value1 = doOperation(a_value1, a_operation, a_value2);
if (isParaEnd || (isOperation(nextOp) && isOperation(a_prevOp) && !isOperationPriorityHigher(nextOp, a_prevOp)))
{
value = value << 1;
if (c == '1')
value += 1;
// end of higher priority operation
return true;
}
}
else
{
stream << std::setbase(base);
stream >> value;
}
return value;
}
// ---------------------------------------------------------------
// Returns the next token (with space as separator). Heading
// spaces will be ignored.
// ---------------------------------------------------------------
std::string IntegerCalculator::getToken(const std::string &a_calcText, size_t& a_pos)
{
// skip spaces at begin
while (a_pos < a_calcText.length())
{
if (a_calcText[a_pos] == ' ') a_pos++;
else break;
a_operation = "";
return false;
}
// search until next space (or end)
size_t startPos = a_pos;
while (a_pos < a_calcText.length())
{
if (' ' == a_calcText[a_pos]) break;
a_pos++;
}
return a_calcText.substr(startPos, a_pos-startPos);
}
// ---------------------------------------------------------------
// returns true if a_operation is a known operation.
// ---------------------------------------------------------------
bool IntegerCalculator::isOperation(const std::string& a_operation) const
{
std::map<std::string, int>::const_iterator iter = m_OperationList.find(a_operation);
return (iter != m_OperationList.end());
}
// ---------------------------------------------------------------
// Calculates the opeation a_operations with a_value1 as first
// and a_value2 as second operand.
// ---------------------------------------------------------------
int64_t IntegerCalculator::doOperation(const int64_t a_value1, const std::string& a_operation, const int64_t a_value2)
{
// M_INFO("" << a_value1 << " " << a_operation << " " << a_value2);
if (("+" == a_operation) || a_operation.empty())
// ---------------------------------------------------------------
// Returns the inverted a_value if a_isNegative is true.
// a_isNegative will be false after calling this function.
// If a_isNegative is true, the NOT inverted a_value will be
// returned.
// ---------------------------------------------------------------
int64_t IntegerCalculator::calcSign(const int64_t a_value, bool &a_isNegative)
{
return a_value1 + a_value2;
}
else if ("-" == a_operation)
{
return a_value1 - a_value2;
}
else if ("*" == a_operation)
{
return a_value1 * a_value2;
}
else if ("/" == a_operation)
{
if (0 == a_value2)
if (a_isNegative)
{
m_Error = e_DivisionByZero;
a_isNegative = false;
return -a_value;
}
return a_value;
}
// ---------------------------------------------------------------
// Converts the value in form of text to a number. The Text
// can be decimal, hex (0x) or binary (0b).
// ---------------------------------------------------------------
int64_t IntegerCalculator::convertValue(const std::string &a_valueText, size_t &a_pos)
{
std::string valueText = a_valueText.substr(a_pos);
int base = 10;
size_t startpos = 0;
// hex- and binary-stuff
bool isHex = (0 == valueText.find("0X")) || (0 == valueText.find("0x"));
bool isBin = (0 == valueText.find("0B")) || (0 == valueText.find("0b"));
if (isHex)
{
base = 16;
startpos = 2;
}
else if (isBin)
{
base = 2;
startpos = 2;
}
// search end of value
size_t i;
for (i = startpos; i < valueText.length(); i++)
{
if (!isDigit(valueText[i], isHex, isBin))
{
break;
}
}
// check the next char, it must be a space
if (valueText.length() > i && valueText[i] != ' ')
{
m_Error = e_InvalidOperand;
int spacePos = valueText.find(' ');
m_AdditionalErrorText = valueText.substr(0, spacePos);
}
a_pos += i;
int64_t value = 0;
std::stringstream stream;
stream.str(valueText.substr(startpos, i - startpos));
if (2 == base)
{
// our stl is not able to read in binary-values, therefore we have to implement it ourself
const std::string binValueAsText = stream.str();
for (const char c : binValueAsText)
{
value = value << 1;
if (c == '1')
value += 1;
}
}
else
{
return a_value1 / a_value2;
stream << std::setbase(base);
stream >> value;
}
return value;
}
else if ("%" == a_operation)
// ---------------------------------------------------------------
// Returns the next token (with space as separator). Heading
// spaces will be ignored.
// ---------------------------------------------------------------
std::string IntegerCalculator::getToken(const std::string &a_calcText, size_t &a_pos)
{
if (0 == a_value2)
// skip spaces at begin
while (a_pos < a_calcText.length())
{
m_Error = e_DivisionByZero;
if (a_calcText[a_pos] == ' ')
a_pos++;
else
break;
}
// search until next space (or end)
size_t startPos = a_pos;
while (a_pos < a_calcText.length())
{
if (' ' == a_calcText[a_pos])
break;
a_pos++;
}
return a_calcText.substr(startPos, a_pos - startPos);
}
// ---------------------------------------------------------------
// returns true if a_operation is a known operation.
// ---------------------------------------------------------------
bool IntegerCalculator::isOperation(const std::string &a_operation) const
{
std::map<std::string, int>::const_iterator iter = m_OperationList.find(a_operation);
return (iter != m_OperationList.end());
}
// ---------------------------------------------------------------
// Calculates the opeation a_operations with a_value1 as first
// and a_value2 as second operand.
// ---------------------------------------------------------------
int64_t IntegerCalculator::doOperation(const int64_t a_value1, const std::string &a_operation, const int64_t a_value2)
{
// M_INFO("" << a_value1 << " " << a_operation << " " << a_value2);
if (("+" == a_operation) || a_operation.empty())
{
return a_value1 + a_value2;
}
else if ("-" == a_operation)
{
return a_value1 - a_value2;
}
else if ("*" == a_operation)
{
return a_value1 * a_value2;
}
else if ("/" == a_operation)
{
if (0 == a_value2)
{
m_Error = e_DivisionByZero;
}
else
{
return a_value1 / a_value2;
}
}
else if ("%" == a_operation)
{
if (0 == a_value2)
{
m_Error = e_DivisionByZero;
}
else
{
return a_value1 % a_value2;
}
}
else if ("<<" == a_operation)
{
return a_value1 << a_value2;
}
else if (">>" == a_operation)
{
return a_value1 >> a_value2;
}
else
{
return a_value1 % a_value2;
m_Error = e_UnknownOperationOrVariable;
m_AdditionalErrorText = a_operation;
}
return 0;
}
// ---------------------------------------------------------------
// returns true if priority of a_opeation1 is higher than
// priority of a_operation2.
// ---------------------------------------------------------------
bool IntegerCalculator::isOperationPriorityHigher(const std::string &a_operation1, const std::string &a_operation2) const
{
return (getPriority(a_operation1) > getPriority(a_operation2));
}
// ---------------------------------------------------------------
// Returns true if the variable named a_variableName is known
// and a_value will be filled with its value. If the variable
// is not found false will be returned.
// Overload this virtual function if you want to implement
// your own variable-list.
// ---------------------------------------------------------------
bool IntegerCalculator::getVariableValue(const std::string &a_variableName, int64_t &a_value) const
{
auto iter = m_VariableList.find(a_variableName);
if (iter != m_VariableList.end())
{
a_value = iter->second;
return true;
}
// error
return false;
}
// ---------------------------------------------------------------
// Returns true if a_char is a digit. When a_isHex is true,
// also the charactes a-f will be accepted as digits. When
// a_isBin is true, only 0 and 1 will be treated as digit.
// ---------------------------------------------------------------
bool IntegerCalculator::isDigit(const char a_char, const bool a_isHex, const bool a_isBin)
{
if (a_isHex)
{
// for hex-values also A..F are 'digits'
return (a_char >= '0' && a_char <= '9') || (a_char >= 'A' && a_char <= 'F') || (a_char >= 'a' && a_char <= 'f');
}
else if (a_isBin)
{
// for binary-values only 0 and 1 are allowed
return (a_char >= '0' && a_char <= '1');
}
// normal digits
return (a_char >= '0' && a_char <= '9');
}
// ---------------------------------------------------------------
// Returns the priority of the operation. A higher value means
// more priority.
// ---------------------------------------------------------------
int16_t IntegerCalculator::getPriority(const std::string &a_operation) const
{
std::map<std::string, int>::const_iterator iter = m_OperationList.find(a_operation);
if (iter != m_OperationList.end())
return iter->second;
return -1;
}
// ---------------------------------------------------------------
// replaces in a_haystack all a_searchText with a_replaceText
// (not greedy).
// ---------------------------------------------------------------
void IntegerCalculator::replace(std::string &a_haystack, const std::string &a_searchText, const std::string &a_replaceText)
{
std::string::size_type searchSize = a_searchText.length();
std::string::size_type replaceSize = a_replaceText.length();
std::string::size_type pos = a_haystack.find(a_searchText, 0);
while (std::string::npos != pos)
{
a_haystack.replace(pos, searchSize, a_replaceText);
pos += replaceSize;
pos = a_haystack.find(a_searchText, pos);
}
}
else if ("<<" == a_operation)
{
return a_value1 << a_value2;
}
else if (">>" == a_operation)
{
return a_value1 >> a_value2;
}
else
{
m_Error = e_UnknownOperationOrVariable;
m_AdditionalErrorText = a_operation;
}
return 0;
}
// ---------------------------------------------------------------
// returns true if priority of a_opeation1 is higher than
// priority of a_operation2.
// ---------------------------------------------------------------
bool IntegerCalculator::isOperationPriorityHigher(const std::string& a_operation1, const std::string& a_operation2) const
{
return (getPriority(a_operation1) > getPriority(a_operation2));
}
// ---------------------------------------------------------------
// Returns true if the variable named a_variableName is known
// and a_value will be filled with its value. If the variable
// is not found false will be returned.
// Overload this virtual function if you want to implement
// your own variable-list.
// ---------------------------------------------------------------
bool IntegerCalculator::getVariableValue(const std::string& a_variableName, int64_t& a_value) const
{
auto iter = m_VariableList.find(a_variableName);
if (iter != m_VariableList.end())
{
a_value = iter->second;
return true;
}
// error
return false;
}
// ---------------------------------------------------------------
// Returns true if a_char is a digit. When a_isHex is true,
// also the charactes a-f will be accepted as digits. When
// a_isBin is true, only 0 and 1 will be treated as digit.
// ---------------------------------------------------------------
bool IntegerCalculator::isDigit(const char a_char, const bool a_isHex, const bool a_isBin)
{
if (a_isHex)
{
// for hex-values also A..F are 'digits'
return (a_char >= '0' && a_char <= '9') || (a_char >= 'A' && a_char <= 'F') || (a_char >= 'a' && a_char <= 'f');
}
else if (a_isBin)
{
// for binary-values only 0 and 1 are allowed
return (a_char >= '0' && a_char <= '1');
}
// normal digits
return (a_char >= '0' && a_char <= '9');
}
// ---------------------------------------------------------------
// Returns the priority of the operation. A higher value means
// more priority.
// ---------------------------------------------------------------
int16_t IntegerCalculator::getPriority(const std::string& a_operation) const
{
std::map<std::string, int>::const_iterator iter = m_OperationList.find(a_operation);
if (iter != m_OperationList.end())
return iter->second;
return -1;
}
// ---------------------------------------------------------------
// replaces in a_haystack all a_searchText with a_replaceText
// (not greedy).
// ---------------------------------------------------------------
void IntegerCalculator::replace(std::string& a_haystack, const std::string &a_searchText, const std::string &a_replaceText)
{
std::string::size_type searchSize = a_searchText.length();
std::string::size_type replaceSize = a_replaceText.length();
std::string::size_type pos = a_haystack.find(a_searchText, 0);
while (std::string::npos != pos)
{
a_haystack.replace(pos, searchSize, a_replaceText);
pos += replaceSize;
pos = a_haystack.find(a_searchText, pos);
}
}
} // namespace N_SST
@@ -34,7 +34,6 @@ namespace N_SST
class IntegerCalculator
{
public:
/**
* Describes the error happend while calculation of an expression
*
@@ -95,7 +94,7 @@ namespace N_SST
* @param a_error
* @param a_addErrorText
*/
int64_t calc(const std::string& a_calcText, E_Error& a_error, std::string* a_addErrorText = nullptr);
int64_t calc(const std::string &a_calcText, E_Error &a_error, std::string *a_addErrorText = nullptr);
/**
* Adds or changes a case-sensitive variable to the calculator.
@@ -103,17 +102,16 @@ namespace N_SST
* @param a_name
* @param a_value
*/
void addVariable(const std::string& a_name, const int64_t a_value);
void addVariable(const std::string &a_name, const int64_t a_value);
/**
* Removes a case-sensitive variable from the calculator.
*
* @param a_name
*/
void removeVariable(const std::string& a_name);
void removeVariable(const std::string &a_name);
protected:
/**
* Contains all supported operations
*/
@@ -143,9 +141,12 @@ namespace N_SST
* @param a_prevValue
* @param a_initOp
*/
int64_t calc(const std::string& a_calcText, size_t& a_pos, bool& a_IsEndParanthesis,
const std::string& a_prevOp = std::string(), const int64_t a_prevValue = 0,
const std::string& a_initOp = std::string());
int64_t calc(const std::string &a_calcText,
size_t &a_pos,
bool &a_IsEndParanthesis,
const std::string &a_prevOp = std::string(),
const int64_t a_prevValue = 0,
const std::string &a_initOp = std::string());
/**
* Calculates an operation with respecting the priority of operations. This will
@@ -158,8 +159,7 @@ namespace N_SST
* @param a_value2
* @param a_prevOp
*/
bool calcWithPriority(const std::string& a_calcText, size_t& a_pos, int64_t& a_value1,
std::string& a_operation, int64_t a_value2, const std::string& a_prevOp);
bool calcWithPriority(const std::string &a_calcText, size_t &a_pos, int64_t &a_value1, std::string &a_operation, int64_t a_value2, const std::string &a_prevOp);
/**
* Returns the inverted a_value if a_isNegative is true. a_isNegative will be
@@ -169,7 +169,7 @@ namespace N_SST
* @param a_value
* @param a_isNegative
*/
static int64_t calcSign(const int64_t a_value, bool& a_isNegative);
static int64_t calcSign(const int64_t a_value, bool &a_isNegative);
/**
* Converts the value in form of text to a number. The Text can be decimal, hex
@@ -178,7 +178,7 @@ namespace N_SST
* @param a_valueText
* @param a_pos
*/
int64_t convertValue(const std::string& a_valueText, size_t& a_pos);
int64_t convertValue(const std::string &a_valueText, size_t &a_pos);
/**
* Returns the next token (with space as separator). Heading spaces will be
@@ -187,14 +187,14 @@ namespace N_SST
* @param a_calcText
* @param a_pos
*/
static std::string getToken(const std::string& a_calcText, size_t& a_pos);
static std::string getToken(const std::string &a_calcText, size_t &a_pos);
/**
* returns true if a_operation is a known operation.
*
* @param a_operation
*/
bool isOperation(const std::string& a_operation) const;
bool isOperation(const std::string &a_operation) const;
/**
* Calculates the opeation a_operations with a_value1 as first and a_value2 as
@@ -204,7 +204,7 @@ namespace N_SST
* @param a_operation
* @param a_value2
*/
int64_t doOperation(const int64_t a_value1, const std::string& a_operation, const int64_t a_value2);
int64_t doOperation(const int64_t a_value1, const std::string &a_operation, const int64_t a_value2);
/**
* returns true if priority of a_opeation1 is higher than priority of a_operation2.
@@ -213,7 +213,7 @@ namespace N_SST
* @param a_operation1
* @param a_operation2
*/
bool isOperationPriorityHigher(const std::string& a_operation1, const std::string& a_operation2) const;
bool isOperationPriorityHigher(const std::string &a_operation1, const std::string &a_operation2) const;
/**
* Returns true if the variable named a_variableName is known and a_value will be
@@ -223,7 +223,7 @@ namespace N_SST
* @param a_variableName
* @param a_value
*/
virtual bool getVariableValue(const std::string& a_variableName, int64_t& a_value) const;
virtual bool getVariableValue(const std::string &a_variableName, int64_t &a_value) const;
/**
* Returns true if a_char is a digit. When a_isHex is true, also the charactes a-f
@@ -241,7 +241,7 @@ namespace N_SST
*
* @param a_operation
*/
int16_t getPriority(const std::string& a_operation) const;
int16_t getPriority(const std::string &a_operation) const;
/**
* replaces in a_haystack all a_searchText with a_replaceText (not greedy).
@@ -250,8 +250,7 @@ namespace N_SST
* @param a_searchText
* @param a_replaceText
*/
static void replace(std::string& a_haystack, const std::string& a_searchText, const std::string& a_replaceText);
static void replace(std::string &a_haystack, const std::string &a_searchText, const std::string &a_replaceText);
};
}
@@ -13,29 +13,29 @@
namespace N_LogView
{
// ---------------------------------------------------------------
LogViewBooleanEdit::LogViewBooleanEdit(LogViewField* a_field, QWidget* a_parent, const bool a_readonly)
: QCheckBox (a_parent)
, LogViewWidget(a_field, this, a_parent, a_readonly)
{
const QString valueText = a_field->value(0);
setChecked(valueText.toInt() == 1);
setEnabled(!a_readonly);
}
// ---------------------------------------------------------------
bool LogViewBooleanEdit::saveContent(LogViewTelegram* a_telegram)
{
if (m_Valid)
// ---------------------------------------------------------------
LogViewBooleanEdit::LogViewBooleanEdit(LogViewField *a_field, QWidget *a_parent, const bool a_readonly)
: QCheckBox(a_parent)
, LogViewWidget(a_field, this, a_parent, a_readonly)
{
if (a_telegram->isJsonTelegram())
a_telegram->setJsonValue(m_Field->jsonPath(), isChecked());
else
a_telegram->setUIntX(getSize(), isChecked());
return true;
const QString valueText = a_field->value(0);
setChecked(valueText.toInt() == 1);
setEnabled(!a_readonly);
}
// ---------------------------------------------------------------
bool LogViewBooleanEdit::saveContent(LogViewTelegram *a_telegram)
{
if (m_Valid)
{
if (a_telegram->isJsonTelegram())
a_telegram->setJsonValue(m_Field->jsonPath(), isChecked());
else
a_telegram->setUIntX(getSize(), isChecked());
return true;
}
return false;
}
return false;
}
} // namespace N_LogView
@@ -13,12 +13,14 @@
namespace N_LogView
{
class LogViewBooleanEdit : public QCheckBox, public LogViewWidget
class LogViewBooleanEdit
: public QCheckBox
, public LogViewWidget
{
Q_OBJECT
public:
LogViewBooleanEdit(LogViewField* a_field, QWidget* a_parent, const bool a_readonly);
bool saveContent(LogViewTelegram* a_telegram) override;
LogViewBooleanEdit(LogViewField *a_field, QWidget *a_parent, const bool a_readonly);
bool saveContent(LogViewTelegram *a_telegram) override;
};
}
@@ -1,16 +1,16 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
// manual class headers
#include "LogViewDateTimeEdit.hpp"
#include <time.h>
@@ -20,67 +20,65 @@
namespace N_LogView
{
// ---------------------------------------------------------------
LogViewDateTimeEdit::LogViewDateTimeEdit(LogViewField* a_field, QWidget* a_parent, const bool a_readonly)
: QDateTimeEdit(a_parent)
, LogViewWidget(a_field, this, a_parent, a_readonly)
{
if (a_readonly)
// ---------------------------------------------------------------
LogViewDateTimeEdit::LogViewDateTimeEdit(LogViewField *a_field, QWidget *a_parent, const bool a_readonly)
: QDateTimeEdit(a_parent)
, LogViewWidget(a_field, this, a_parent, a_readonly)
{
setReadOnly(true);
setAlignment(a_field->isRightAligned() ? Qt::AlignRight : Qt::AlignLeft);
if (a_readonly)
{
setReadOnly(true);
setAlignment(a_field->isRightAligned() ? Qt::AlignRight : Qt::AlignLeft);
}
// date-time-field
qint64 unixTime = 0;
if (a_field->hasContent())
{
if (a_field->isMSecsField())
unixTime = a_field->value(0, true).toLongLong();
else
unixTime = a_field->value(0, true).toInt() * 1000LL;
}
// take actual date and time if time is 0
if (0 == unixTime && !a_readonly)
unixTime = ::time(nullptr) * 1000LL;
//valueWidget = new QDateTimeEdit(dateTime);
setDateTime(QDateTime::fromMSecsSinceEpoch(unixTime));
setDisplayFormat(QLatin1String("dd MMM yyyy hh:mm:ss"));
setCalendarPopup(true);
updateToolTip(QString::number(unixTime));
//setToolTip(a_field->getToolTipText());
// checkAndOvertakeContent();
connect(this, &LogViewDateTimeEdit::editingFinished, this, &LogViewDateTimeEdit::checkAndOvertakeContent);
}
// date-time-field
qint64 unixTime = 0;
if (a_field->hasContent())
// ---------------------------------------------------------------
void LogViewDateTimeEdit::checkAndOvertakeContent()
{
if (a_field->isMSecsField())
unixTime = a_field->value(0, true).toLongLong();
updateToolTip(QString::number(dateTime().toMSecsSinceEpoch() / 1000));
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewDateTimeEdit::saveContent(LogViewTelegram *a_telegram)
{
if (a_telegram->isJsonTelegram())
{
a_telegram->setJsonValue(m_Field->jsonPath(), dateTime().toMSecsSinceEpoch());
}
else
unixTime = a_field->value(0, true).toInt() * 1000LL;
{
a_telegram->setNextFieldAsGpsTimeField(); // fixme: muss noch der feldname auf GPS Zeit geprüft werden?
a_telegram->setUIntX(getSize(), dateTime().toMSecsSinceEpoch() / 1000);
}
return true;
}
// take actual date and time if time is 0
if (0 == unixTime && !a_readonly)
unixTime = ::time(nullptr) * 1000LL;
//valueWidget = new QDateTimeEdit(dateTime);
setDateTime(QDateTime::fromMSecsSinceEpoch(unixTime));
setDisplayFormat(QLatin1String("dd MMM yyyy hh:mm:ss"));
setCalendarPopup(true);
updateToolTip(QString::number(unixTime));
//setToolTip(a_field->getToolTipText());
// checkAndOvertakeContent();
connect(this, &LogViewDateTimeEdit::editingFinished,
this, &LogViewDateTimeEdit::checkAndOvertakeContent);
}
// ---------------------------------------------------------------
void LogViewDateTimeEdit::checkAndOvertakeContent()
{
updateToolTip(QString::number(dateTime().toMSecsSinceEpoch() / 1000));
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewDateTimeEdit::saveContent(LogViewTelegram* a_telegram)
{
if (a_telegram->isJsonTelegram())
{
a_telegram->setJsonValue(m_Field->jsonPath(), dateTime().toMSecsSinceEpoch());
}
else
{
a_telegram->setNextFieldAsGpsTimeField(); // fixme: muss noch der feldname auf GPS Zeit geprüft werden?
a_telegram->setUIntX(getSize(), dateTime().toMSecsSinceEpoch() / 1000);
}
return true;
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include "LogViewWidget.hpp"
@@ -25,7 +25,9 @@ namespace N_LogView
* @version 1.0
* @created 20-Mai-2010 17:41:28
*/
class LogViewDateTimeEdit : public QDateTimeEdit, public LogViewWidget
class LogViewDateTimeEdit
: public QDateTimeEdit
, public LogViewWidget
{
Q_OBJECT
public:
@@ -35,7 +37,7 @@ namespace N_LogView
* @param a_parent
* @param a_readonly
*/
LogViewDateTimeEdit(LogViewField* a_field, QWidget* a_parent, const bool a_readonly);
LogViewDateTimeEdit(LogViewField *a_field, QWidget *a_parent, const bool a_readonly);
/**
* Writes the content into telegram.
@@ -43,11 +45,10 @@ namespace N_LogView
*
* @param a_telegram
*/
bool saveContent(LogViewTelegram* a_telegram) override;
bool saveContent(LogViewTelegram *a_telegram) override;
public slots:
void checkAndOvertakeContent();
};
}
@@ -1,16 +1,16 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
// manual class headers
#include "LogViewEnumEdit.hpp"
#include "LogViewXdrStruct.hpp"
@@ -23,83 +23,82 @@ namespace N_LogView
{
// ---------------------------------------------------------------
LogViewEnumEdit::LogViewEnumEdit(LogViewField* a_field, QWidget* a_parent, const bool a_readonly, const int a_index)
: QComboBox(a_parent)
, LogViewWidget(a_field, this, a_parent, a_readonly)
{
QString value = a_field->value(a_index);
// show the tool-tip with special-case for TETRA bitfields
setToolTip(a_field->toolTipText());
// fill combobox
bool bCurrentIndexSet = false;
int i = 0;
while (LogViewXdrValue* child = (static_cast<const LogViewXdrStruct*>(a_field->xdrElement()))->getChildAsValue(i++))
// ---------------------------------------------------------------
LogViewEnumEdit::LogViewEnumEdit(LogViewField *a_field, QWidget *a_parent, const bool a_readonly, const int a_index)
: QComboBox(a_parent)
, LogViewWidget(a_field, this, a_parent, a_readonly)
{
QString enumText = LogViewField::makeClean(child->getName());
if (!a_readonly || enumText == value)
QString value = a_field->value(a_index);
// show the tool-tip with special-case for TETRA bitfields
setToolTip(a_field->toolTipText());
// fill combobox
bool bCurrentIndexSet = false;
int i = 0;
while (LogViewXdrValue *child = (static_cast<const LogViewXdrStruct *>(a_field->xdrElement()))->getChildAsValue(i++))
{
addItem(QStringLiteral("%1 (%2)").arg(enumText).arg(child->getValue()), QVariant::fromValue(child->getValue()));
if (a_readonly)
QString enumText = LogViewField::makeClean(child->getName());
if (!a_readonly || enumText == value)
{
addItem(QStringLiteral("%1 (%2)").arg(enumText).arg(child->getValue()), QVariant::fromValue(child->getValue()));
if (a_readonly)
bCurrentIndexSet = true;
}
if (enumText == value)
{
setCurrentIndex(a_readonly ? 0 : i - 1);
bCurrentIndexSet = true;
if (!a_readonly || (0 != a_index))
updateToolTip(itemData(currentIndex()).toString());
}
}
if (enumText == value)
if (!bCurrentIndexSet)
{
setCurrentIndex(a_readonly ? 0 : i - 1);
bCurrentIndexSet = true;
if (!a_readonly || (0 != a_index))
updateToolTip(itemData(currentIndex()).toString());
addItem(value);
setCurrentIndex(findText(value));
}
// connect signals
connect(this, QOverload<int>::of(&LogViewEnumEdit::currentIndexChanged), this, &LogViewEnumEdit::checkAndOvertakeContent);
}
if (!bCurrentIndexSet)
// ---------------------------------------------------------------
uint16_t LogViewEnumEdit::getSize() const
{
addItem(value);
setCurrentIndex(findText(value));
// todo: check ob wirklich ein struct
const LogViewXdrStruct *xdrStruct = static_cast<const LogViewXdrStruct *>(m_Field->xdrElement());
return xdrStruct->getEnumSize();
}
// connect signals
connect(this, QOverload<int>::of(&LogViewEnumEdit::currentIndexChanged),
this, &LogViewEnumEdit::checkAndOvertakeContent);
}
// ---------------------------------------------------------------
uint16_t LogViewEnumEdit::getSize() const
{
// todo: check ob wirklich ein struct
const LogViewXdrStruct* xdrStruct = static_cast<const LogViewXdrStruct*>(m_Field->xdrElement());
return xdrStruct->getEnumSize();
}
// ---------------------------------------------------------------
void LogViewEnumEdit::checkAndOvertakeContent()
{
updateToolTip(itemData(currentIndex()).toString());
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewEnumEdit::saveContent(LogViewTelegram* a_telegram)
{
bool ok;
int value = itemData(currentIndex()).toInt(&ok);
if (ok)
// ---------------------------------------------------------------
void LogViewEnumEdit::checkAndOvertakeContent()
{
if (a_telegram->isJsonTelegram())
a_telegram->setJsonValue(m_Field->jsonPath(), value);
else
a_telegram->setUIntX(getSize(), value);
return true;
updateToolTip(itemData(currentIndex()).toString());
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewEnumEdit::saveContent(LogViewTelegram *a_telegram)
{
bool ok;
int value = itemData(currentIndex()).toInt(&ok);
if (ok)
{
if (a_telegram->isJsonTelegram())
a_telegram->setJsonValue(m_Field->jsonPath(), value);
else
a_telegram->setUIntX(getSize(), value);
return true;
}
return false; // failure while conversion
}
return false; // failure while conversion
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include "LogViewWidget.hpp"
@@ -25,7 +25,9 @@ namespace N_LogView
* @version 1.0
* @created 21-Mai-2010 09:31:16
*/
class LogViewEnumEdit : public QComboBox, public LogViewWidget
class LogViewEnumEdit
: public QComboBox
, public LogViewWidget
{
Q_OBJECT
public:
@@ -36,7 +38,7 @@ namespace N_LogView
* @param a_readonly
* @param a_index the array-index
*/
LogViewEnumEdit(LogViewField* a_field, QWidget* a_parent, const bool a_readonly, const int a_index);
LogViewEnumEdit(LogViewField *a_field, QWidget *a_parent, const bool a_readonly, const int a_index);
uint16_t getSize() const override;
@@ -47,11 +49,10 @@ namespace N_LogView
*
* @param a_telegram
*/
bool saveContent(LogViewTelegram* a_telegram) override;
bool saveContent(LogViewTelegram *a_telegram) override;
protected slots:
void checkAndOvertakeContent();
};
}
@@ -1,16 +1,16 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
#include "LogViewField.hpp"
#include <utility>
#include <QtCore/QDateTime>
@@ -20,257 +20,260 @@
namespace N_LogView
{
// ---------------------------------------------------------------
LogViewField::LogViewField(const QString& a_name, const E_FieldKind a_kind, const LogViewXdrElement* a_xdrElement)
: m_logger(getLogger("LogViewField")),
m_Name(a_name),
m_IsRightAligned(false),
m_Offset(0),
m_Size(0),
m_MaxArraySize(0),
m_IsDynamicArray(false),
m_HasContent(true),
m_bDeleteXdr(false),
m_Kind(a_kind),
m_XdrElement(a_xdrElement)
{
}
// ---------------------------------------------------------------
LogViewField::~LogViewField()
{
for (LogViewField *f : std::as_const(m_Child))
delete f;
if (m_bDeleteXdr)
delete m_XdrElement;
}
LogViewField *LogViewField::clone(int arrayIdx) const
{
LogViewField *f = new LogViewField(*this);
f->m_Child.clear();
f->m_bDeleteXdr = false;
for (auto * c : m_Child)
// ---------------------------------------------------------------
LogViewField::LogViewField(const QString &a_name, const E_FieldKind a_kind, const LogViewXdrElement *a_xdrElement)
: m_logger(getLogger("LogViewField"))
, m_Name(a_name)
, m_IsRightAligned(false)
, m_Offset(0)
, m_Size(0)
, m_MaxArraySize(0)
, m_IsDynamicArray(false)
, m_HasContent(true)
, m_bDeleteXdr(false)
, m_Kind(a_kind)
, m_XdrElement(a_xdrElement)
{
auto *clonedChild = c->clone(-1);
if (arrayIdx >= 0)
}
// ---------------------------------------------------------------
LogViewField::~LogViewField()
{
for (LogViewField *f : std::as_const(m_Child))
delete f;
if (m_bDeleteXdr)
delete m_XdrElement;
}
LogViewField *LogViewField::clone(int arrayIdx) const
{
LogViewField *f = new LogViewField(*this);
f->m_Child.clear();
f->m_bDeleteXdr = false;
for (auto *c : m_Child)
{
QStringList sl = clonedChild->jsonPath();
if (sl.size() > 1 && sl.at(sl.size() - 2).startsWith(QStringLiteral("index: ")))
auto *clonedChild = c->clone(-1);
if (arrayIdx >= 0)
{
sl[sl.size() - 2] = QStringLiteral("index: %1").arg(arrayIdx);
clonedChild->setJsonPath(sl);
QStringList sl = clonedChild->jsonPath();
if (sl.size() > 1 && sl.at(sl.size() - 2).startsWith(QStringLiteral("index: ")))
{
sl[sl.size() - 2] = QStringLiteral("index: %1").arg(arrayIdx);
clonedChild->setJsonPath(sl);
}
}
f->addChild(clonedChild);
}
f->addChild(clonedChild);
for (auto &val : f->m_ValueList)
val.clear();
return f;
}
for (auto &val : f->m_ValueList)
val.clear();
return f;
}
// ---------------------------------------------------------------
void LogViewField::addChild(LogViewField* a_child)
{
if (a_child)
m_Child.push_back(a_child);
}
// ---------------------------------------------------------------
void LogViewField::removeLastChild()
{
if (m_Child.empty())
return;
delete m_Child.takeLast();
}
// ---------------------------------------------------------------
LogViewField* LogViewField::child(int arrayIdx)
{
if (m_Child.size() > arrayIdx)
return m_Child.at(arrayIdx);
return nullptr;
}
// ---------------------------------------------------------------
void LogViewField::addValue(const QString &value)
{
m_ValueList.append(value);
}
// ---------------------------------------------------------------
void LogViewField::addValueBinaryHex(const QString &value)
{
const QByteArray ba = QByteArray::fromHex(value.toLatin1());
for (const char c : ba)
m_ValueList.append(QString::number(static_cast<unsigned char>(c)));
}
// ---------------------------------------------------------------
// Returns the value at position a_index converted to a string.
// If the field is a date-time-field, the returned value is
// converted to a string containing date and time, execpt when
// a_doNotMakeSpecialConversions is set to true, the unix-time
// will be returned as value.
// ---------------------------------------------------------------
QString LogViewField::value(int arrayIdx, const bool a_doNotMakeSpecialConversions) const
{
if (m_ValueList.size() > arrayIdx)
// ---------------------------------------------------------------
void LogViewField::addChild(LogViewField *a_child)
{
const QString &ret = m_ValueList.at(arrayIdx);
if (!a_doNotMakeSpecialConversions)
if (a_child)
m_Child.push_back(a_child);
}
// ---------------------------------------------------------------
void LogViewField::removeLastChild()
{
if (m_Child.empty())
return;
delete m_Child.takeLast();
}
// ---------------------------------------------------------------
LogViewField *LogViewField::child(int arrayIdx)
{
if (m_Child.size() > arrayIdx)
return m_Child.at(arrayIdx);
return nullptr;
}
// ---------------------------------------------------------------
void LogViewField::addValue(const QString &value)
{
m_ValueList.append(value);
}
// ---------------------------------------------------------------
void LogViewField::addValueBinaryHex(const QString &value)
{
const QByteArray ba = QByteArray::fromHex(value.toLatin1());
for (const char c : ba)
m_ValueList.append(QString::number(static_cast<unsigned char>(c)));
}
// ---------------------------------------------------------------
// Returns the value at position a_index converted to a string.
// If the field is a date-time-field, the returned value is
// converted to a string containing date and time, execpt when
// a_doNotMakeSpecialConversions is set to true, the unix-time
// will be returned as value.
// ---------------------------------------------------------------
QString LogViewField::value(int arrayIdx, const bool a_doNotMakeSpecialConversions) const
{
if (m_ValueList.size() > arrayIdx)
{
if (isDateTimeField())
return QDateTime::fromMSecsSinceEpoch(ret.toLongLong() * 1000).toString(QStringLiteral("dd.mm.yy hh:mm:ss.zzz"));
if (isMSecsField())
return QDateTime::fromMSecsSinceEpoch(ret.toLongLong()).toString(QStringLiteral("dd.mm.yy hh:mm:ss.zzz"));
const QString &ret = m_ValueList.at(arrayIdx);
if (!a_doNotMakeSpecialConversions)
{
if (isDateTimeField())
return QDateTime::fromMSecsSinceEpoch(ret.toLongLong() * 1000).toString(QStringLiteral("dd.mm.yy hh:mm:ss.zzz"));
if (isMSecsField())
return QDateTime::fromMSecsSinceEpoch(ret.toLongLong()).toString(QStringLiteral("dd.mm.yy hh:mm:ss.zzz"));
}
return ret;
}
return ret;
return QString();
}
return QString();
}
// ---------------------------------------------------------------
int64_t LogViewField::getHighestValue() const
{
switch (m_XdrElement->getKind())
// ---------------------------------------------------------------
int64_t LogViewField::getHighestValue() const
{
case LogViewXdrElement::e_KindStandardType:
{
int64_t highest = 1;
//const LogViewXdrStandardType* xdrStandardType = static_cast<const LogViewXdrStandardType*>(m_XdrElement);
uint16_t bitSize = 8*static_cast<const LogViewXdrStandardType*>(m_XdrElement)->getEditSize();
// fixme: mache configurierbar
if ((0 == m_Name.compare(QLatin1String("utm nordwert"), Qt::CaseInsensitive)) ||
(0 == m_Name.compare(QLatin1String("utm ostwert"), Qt::CaseInsensitive)))
bitSize -= 8;
switch (m_XdrElement->getKind())
{
case LogViewXdrElement::e_KindStandardType:
{
int64_t highest = 1;
//const LogViewXdrStandardType* xdrStandardType = static_cast<const LogViewXdrStandardType*>(m_XdrElement);
uint16_t bitSize = 8 * static_cast<const LogViewXdrStandardType *>(m_XdrElement)->getEditSize();
// fixme: mache configurierbar
if ((0 == m_Name.compare(QLatin1String("utm nordwert"), Qt::CaseInsensitive)) || (0 == m_Name.compare(QLatin1String("utm ostwert"), Qt::CaseInsensitive)))
bitSize -= 8;
switch (static_cast<const LogViewXdrStandardType*>(m_XdrElement)->getValueKind()) {
case LogViewXdrStandardType::e_Boolean:
return 1;
case LogViewXdrStandardType::e_Signed:
bitSize--;
Q_FALLTHROUGH();
case LogViewXdrStandardType::e_Unsigned:
case LogViewXdrStandardType::e_Data:
highest = highest << bitSize;
highest--;
break;
default:
highest = 0;
break;
switch (static_cast<const LogViewXdrStandardType *>(m_XdrElement)->getValueKind())
{
case LogViewXdrStandardType::e_Boolean:
return 1;
case LogViewXdrStandardType::e_Signed:
bitSize--;
Q_FALLTHROUGH();
case LogViewXdrStandardType::e_Unsigned:
case LogViewXdrStandardType::e_Data:
highest = highest << bitSize;
highest--;
break;
default:
highest = 0;
break;
}
return highest;
}
default:
ERROR_LOG(m_logger) << "Case not implemented";
}
return highest;
return 0;
}
default:
ERROR_LOG(m_logger) << "Case not implemented";
}
return 0;
}
// ---------------------------------------------------------------
int64_t LogViewField::getLowestValue() const
{
switch (m_XdrElement->getKind())
// ---------------------------------------------------------------
int64_t LogViewField::getLowestValue() const
{
case LogViewXdrElement::e_KindStandardType:
{
int64_t lowest = 0;
//const LogViewXdrStandardType* xdrStandardType = static_cast<const LogViewXdrStandardType*>(a_field->getXdrElement());
switch (static_cast<const LogViewXdrStandardType*>(m_XdrElement)->getValueKind()) {
case LogViewXdrStandardType::e_Boolean:
return 0;
case LogViewXdrStandardType::e_Signed:
lowest = getHighestValue() + 1;
lowest = -lowest;
break;
default:
break;
switch (m_XdrElement->getKind())
{
case LogViewXdrElement::e_KindStandardType:
{
int64_t lowest = 0;
//const LogViewXdrStandardType* xdrStandardType = static_cast<const LogViewXdrStandardType*>(a_field->getXdrElement());
switch (static_cast<const LogViewXdrStandardType *>(m_XdrElement)->getValueKind())
{
case LogViewXdrStandardType::e_Boolean:
return 0;
case LogViewXdrStandardType::e_Signed:
lowest = getHighestValue() + 1;
lowest = -lowest;
break;
default:
break;
}
return lowest;
}
default:
ERROR_LOG(m_logger) << "Case not implemented";
break;
}
return lowest;
return 0;
}
default:
ERROR_LOG(m_logger) << "Case not implemented";
break;
}
return 0;
}
// ---------------------------------------------------------------
void LogViewField::dump(const QString &a_indent) const
{
INFO_LOG(m_logger) << a_indent << "[";
INFO_LOG(m_logger) << a_indent << "Field[" << m_Name << "]: m_Kind=" << m_Kind << " m_Offset=" << m_Offset << " m_Size=" << m_Size << " m_MaxArraySize=" << m_MaxArraySize << " m_IsRightAligned=" << m_IsRightAligned << " m_IsDynamicArray=" << m_IsDynamicArray << " m_ToolTipText=" << m_ToolTipText;
// m_XdrElement->dump();
for (int i=0; i<m_ValueList.size(); i++)
INFO_LOG(m_logger) << a_indent << "m_Value[" << i << "]=" << m_ValueList[i];
for (auto *c : m_Child)
c->dump(a_indent + QLatin1Char(' '));
INFO_LOG(m_logger) << a_indent << "]";
}
// ---------------------------------------------------------------
// Makes the text <a_uncleanText> pretty for human readable.
// It does following:
// - generates umlaute (ä, ö, ü)
// - removes _rt at end
// - replaces _ with space
// - uppercase of every word
// ---------------------------------------------------------------
QString LogViewField::makeClean(const QString &text)
{
QString a_uncleanText = text;
// remove _rt at end
if (a_uncleanText.endsWith(QLatin1String("_rt")))
a_uncleanText = a_uncleanText.left(a_uncleanText.length() - 3);
// replace _ with space
a_uncleanText = a_uncleanText.replace(QLatin1Char('_'), QLatin1Char(' '));
// first character of every word must be uppercase
int pos = 0;
while (a_uncleanText.length() > pos)
// ---------------------------------------------------------------
void LogViewField::dump(const QString &a_indent) const
{
a_uncleanText[pos] = a_uncleanText[pos].toUpper();
pos = a_uncleanText.indexOf(QLatin1Char(' '), pos + 1);
if (-1 == pos)
break;
pos++;
INFO_LOG(m_logger) << a_indent << "[";
INFO_LOG(m_logger) << a_indent << "Field[" << m_Name << "]: m_Kind=" << m_Kind << " m_Offset=" << m_Offset << " m_Size=" << m_Size
<< " m_MaxArraySize=" << m_MaxArraySize << " m_IsRightAligned=" << m_IsRightAligned << " m_IsDynamicArray=" << m_IsDynamicArray
<< " m_ToolTipText=" << m_ToolTipText;
// m_XdrElement->dump();
for (int i = 0; i < m_ValueList.size(); i++)
INFO_LOG(m_logger) << a_indent << "m_Value[" << i << "]=" << m_ValueList[i];
for (auto *c : m_Child)
c->dump(a_indent + QLatin1Char(' '));
INFO_LOG(m_logger) << a_indent << "]";
}
return a_uncleanText;
}
// ---------------------------------------------------------------
// Makes the text <a_uncleanText> pretty for human readable.
// It does following:
// - generates umlaute (ä, ö, ü)
// - removes _rt at end
// - replaces _ with space
// - uppercase of every word
// ---------------------------------------------------------------
QString LogViewField::makeClean(const QString &text)
{
QString a_uncleanText = text;
// remove _rt at end
if (a_uncleanText.endsWith(QLatin1String("_rt")))
a_uncleanText = a_uncleanText.left(a_uncleanText.length() - 3);
// replace _ with space
a_uncleanText = a_uncleanText.replace(QLatin1Char('_'), QLatin1Char(' '));
// first character of every word must be uppercase
int pos = 0;
while (a_uncleanText.length() > pos)
{
a_uncleanText[pos] = a_uncleanText[pos].toUpper();
pos = a_uncleanText.indexOf(QLatin1Char(' '), pos + 1);
if (-1 == pos)
break;
pos++;
}
return a_uncleanText;
}
// ---------------------------------------------------------------
// returns true if the field is a date-time
// ---------------------------------------------------------------
bool LogViewField::isDateTimeField() const
{
QString name = m_Name.toLower();
return name == QLatin1String("gps_zeit");
}
// ---------------------------------------------------------------
// returns true if the field is a date-time
// ---------------------------------------------------------------
bool LogViewField::isDateTimeField() const
{
QString name = m_Name.toLower();
return name == QLatin1String("gps_zeit");
}
bool LogViewField::isMSecsField() const
{
QString name = m_Name.toLower();
return (name == QLatin1String("timestamp")) || (name == QLatin1String("effectstart"));
}
bool LogViewField::isMSecsField() const
{
QString name = m_Name.toLower();
return (name == QLatin1String("timestamp")) || (name == QLatin1String("effectstart"));
}
// ---------------------------------------------------------------
void LogViewField::setMaxArraySize(uint16_t newVal, const bool a_isDynamic)
{
m_MaxArraySize = newVal;
m_IsDynamicArray = a_isDynamic;
}
// ---------------------------------------------------------------
void LogViewField::setMaxArraySize(uint16_t newVal, const bool a_isDynamic)
{
m_MaxArraySize = newVal;
m_IsDynamicArray = a_isDynamic;
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include <QtCore/QStringList>
@@ -34,7 +34,7 @@ namespace N_LogView
};
LogViewField(const QString& a_name, const E_FieldKind a_kind, const LogViewXdrElement* a_xdrElement);
LogViewField(const QString &a_name, const E_FieldKind a_kind, const LogViewXdrElement *a_xdrElement);
virtual ~LogViewField();
LogViewField *clone(int arrayIdx) const;
@@ -44,7 +44,7 @@ namespace N_LogView
void setName(const QString &newVal) { m_Name = newVal; }
void addChild(LogViewField* a_child);
void addChild(LogViewField *a_child);
void removeLastChild();
LogViewField *child(int arrayIdx);
int childCount() const { return m_Child.size(); }
@@ -103,7 +103,7 @@ namespace N_LogView
void setSize(int newVal) { m_Size = newVal; }
const LogViewXdrElement* xdrElement() const { return m_XdrElement; }
const LogViewXdrElement *xdrElement() const { return m_XdrElement; }
/**
* returns true if the field is a date-time
@@ -130,7 +130,6 @@ namespace N_LogView
QStringList jsonPath() const { return m_jsonPath; }
protected:
NGL::INGLLogger &m_logger;
QString m_Name;
@@ -148,7 +147,7 @@ namespace N_LogView
bool m_IsDynamicArray;
bool m_HasContent;
bool m_bDeleteXdr;
QVector<LogViewField*> m_Child;
QVector<LogViewField *> m_Child;
E_FieldKind m_Kind;
File diff suppressed because it is too large. Load diff
@@ -23,7 +23,7 @@
namespace N_LogView
{
class LogViewTelegram;
class LogViewTelegram;
}
class QTableView;
@@ -38,164 +38,163 @@ class QToolBox;
namespace N_LogView
{
class LogViewInjectionThread;
class TelegramEdit;
class LogViewInjectionThread;
class TelegramEdit;
/**
/**
* @author alois.wismer
* @version 1.0
* @created 03-Feb-2010 16:44:53
*/
class LogViewGui : public QMainWindow
{
Q_OBJECT
public:
class LogViewGui : public QMainWindow
{
Q_OBJECT
public:
explicit LogViewGui(QWidget *a_parent);
explicit LogViewGui(QWidget* a_parent);
static const QLatin1String WINDOW_GROUP;
static const QLatin1String SCREEN;
static const QLatin1String WINDOW_GROUP;
static const QLatin1String SCREEN;
protected:
const QSize RADIO_BUTTON_ICON_SIZE;
static const QLatin1String SIZE;
static const QLatin1String POS;
static const QLatin1String SPLITTPOS;
static const QLatin1String TOOLBOXINDEX;
// Central
QGroupBox *m_CentralSelectionGroup;
std::set<int> m_CentralTelegramFilterList;
QCheckBox *m_SentCentralTelCheckBox;
QCheckBox *m_ReceivedCentralTelCheckBox;
QCheckBox *m_PosCentralTelCheckBox;
QCheckBox *m_ackCentralTelCheckBox;
// Tetra
QGroupBox *m_TetraSelectionGroup;
std::set<int> m_TetraTelegramFilterList;
QCheckBox *m_SentTetraTelCheckBox;
QCheckBox *m_ReceivedTetraTelCheckBox;
QCheckBox *m_PosTetraTelCheckBox;
QCheckBox *m_LoginTetraTelCheckBox;
QCheckBox *m_RegisterTetraTelCheckBox;
QCheckBox *m_ReportTetraTelCheckBox;
QCheckBox *m_FragmentedTetraTelCheckBox;
QCheckBox *m_AirInterfaceLoadTetraTelCheckBox;
// Wls
QGroupBox *m_WlsSelectionGroup;
std::set<int> m_WlsTelegramFilterList;
QCheckBox *m_SentWlsTelCheckBox;
QCheckBox *m_ReceivedWlsTelCheckBox;
QCheckBox *m_PosWlsTelCheckBox;
QCheckBox *m_ackWlsTelCheckBox;
protected:
QString m_ActualLogfile;
qint64 m_LogfileSize;
bool m_DoReload;
QToolBox *m_ToolBox;
QTableView *m_ParticipantTableView;
ParticipantModel *m_participantModel;
QSortFilterProxyModel *m_participantProxyModel;
const QSize RADIO_BUTTON_ICON_SIZE;
static const QLatin1String SIZE;
static const QLatin1String POS;
static const QLatin1String SPLITTPOS;
static const QLatin1String TOOLBOXINDEX;
// Central
QGroupBox *m_CentralSelectionGroup;
std::set<int> m_CentralTelegramFilterList;
QCheckBox* m_SentCentralTelCheckBox;
QCheckBox* m_ReceivedCentralTelCheckBox;
QCheckBox* m_PosCentralTelCheckBox;
QCheckBox* m_ackCentralTelCheckBox;
// Tetra
QGroupBox *m_TetraSelectionGroup;
std::set<int> m_TetraTelegramFilterList;
QCheckBox* m_SentTetraTelCheckBox;
QCheckBox* m_ReceivedTetraTelCheckBox;
QCheckBox* m_PosTetraTelCheckBox;
QCheckBox* m_LoginTetraTelCheckBox;
QCheckBox* m_RegisterTetraTelCheckBox;
QCheckBox* m_ReportTetraTelCheckBox;
QCheckBox* m_FragmentedTetraTelCheckBox;
QCheckBox* m_AirInterfaceLoadTetraTelCheckBox;
// Wls
QGroupBox *m_WlsSelectionGroup;
std::set<int> m_WlsTelegramFilterList;
QCheckBox* m_SentWlsTelCheckBox;
QCheckBox* m_ReceivedWlsTelCheckBox;
QCheckBox* m_PosWlsTelCheckBox;
QCheckBox* m_ackWlsTelCheckBox;
QTableView *m_logTelegramView;
TelegramModel *m_telegramModel;
TelegramProxyModel *m_telegramProxyModel;
QString m_ActualLogfile;
qint64 m_LogfileSize;
bool m_DoReload;
QToolBox* m_ToolBox;
QTableView *m_ParticipantTableView;
ParticipantModel *m_participantModel;
QSortFilterProxyModel *m_participantProxyModel;
QLabel *m_TelegramStatus;
QTableView *m_logTelegramView;
TelegramModel *m_telegramModel;
TelegramProxyModel *m_telegramProxyModel;
QLabel *m_ParticipantStatus;
QLabel *m_TelegramStatus;
QGroupBox *m_ParticipantSelectionGroup;
QLabel *m_ParticipantStatus;
TelegramEdit *m_EditTelegramController;
QGroupBox *m_ParticipantSelectionGroup;
QTimer *m_TailTimer;
TelegramEdit *m_EditTelegramController;
QSplitter *m_Splitter;
QTimer *m_TailTimer;
LogViewInjectionThread *m_InjectionThread;
QSplitter *m_Splitter;
QLabel *m_InjectionStatus;
LogViewInjectionThread *m_InjectionThread;
// ausstg, telcount
QHash<int, int> m_participantListTelCount;
// ausstg, issi
QHash<int, int> m_participantListIssi;
QLabel *m_InjectionStatus;
QAction *m_reloadAction;
QTimer *m_replayTimer;
int m_currentReplayRow;
// ausstg, telcount
QHash<int, int> m_participantListTelCount;
// ausstg, issi
QHash<int, int> m_participantListIssi;
protected:
void readTelegramsFromLogFile(const QString &a_fileName, const qint64 a_filePos = 0);
QAction *m_reloadAction;
QTimer *m_replayTimer;
int m_currentReplayRow;
protected:
void readTelegramsFromLogFile(const QString& a_fileName, const qint64 a_filePos = 0);
/**
/**
* returns true if the participant was added to the list
*/
void addToParticipantList(const QSharedPointer<LogViewTelegram> &a_telegram);
void syncParticipantList();
QCheckBox* createRadioButton(const QString& a_buttonName, const QString& a_iconName);
void addToParticipantList(const QSharedPointer<LogViewTelegram> &a_telegram);
void syncParticipantList();
QCheckBox *createRadioButton(const QString &a_buttonName, const QString &a_iconName);
/**
/**
* starts the thread, which trys to connect to the injection-server of PrtCnv
*/
void startInjectionThread();
void startInjectionThread();
void closeEvent(QCloseEvent* a_closeEvent) override;
void closeEvent(QCloseEvent *a_closeEvent) override;
void createCentralSelectionWidget();
void createTetraSelectionWidget();
void createWlsSelectionWidget();
void createCentralSelectionWidget();
void createTetraSelectionWidget();
void createWlsSelectionWidget();
protected slots:
void addTelegramToEdit();
void showHexData();
void exportAsCsv();
void exportAsJson();
void onStartLogReplay();
void onReplayTimerTimeout();
protected slots:
void addTelegramToEdit();
void showHexData();
void exportAsCsv();
void exportAsJson();
void onStartLogReplay();
void onReplayTimerTimeout();
void loadSpecificationFiles();
void loadSpecificationFiles();
void newTelegramFile();
void newTelegramFile();
void loadTelegramFile();
void loadTelegramFile();
/**
/**
* Checks whether the size of actual logfile has changed. If yes, the new log-
* entries will be read and shown within table.
*/
void updateLogfile();
void updateLogfile();
void selectedParticipantChanged();
void selectedParticipantChanged();
void showTelegramTable();
void showTelegramTable();
//SLOT for creating the ContextMenu
void customMenuRequested(const QPoint &pos);
//SLOT for creating the ContextMenu
void customMenuRequested(const QPoint &pos);
void changeSettings();
void changeSettings();
/**
/**
* Toggles whether the logfile must be periodically checked for changes
*/
void reloadOnOff();
void reloadOnOff();
/**
/**
*
* @param a_picName
* @param a_toopTipText
*/
void updateInjectionStatus(const QString& a_picName, const QString& a_toopTipText);
void updateInjectionStatus(const QString &a_picName, const QString &a_toopTipText);
void onLogTelegramViewDoubleClicked(const QModelIndex &index);
void onLogTelegramViewDoubleClicked(const QModelIndex &index);
private:
NGL::INGLLogger &m_logger;
private:
NGL::INGLLogger &m_logger;
private slots:
void onSettingsChanged(uint32_t changedFlags);
};
private slots:
void onSettingsChanged(uint32_t changedFlags);
};
}
@@ -1,16 +1,16 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
// manual class headers
#include "LogViewInjectionThread.hpp"
@@ -23,121 +23,118 @@
namespace N_LogView
{
LogViewInjectionThread::LogViewInjectionThread()
: m_logger(getLogger("LogViewInjectionThread"))
, m_DoStartConnection(false)
, m_SendingPossible(false)
, m_Socket(nullptr)
, m_Timer(nullptr)
{
// load the settings (and write default-values if not defined)
QSettings settings;
settings.beginGroup(LogViewOptionDialog::INJECTION_GROUP);
m_Hostname = settings.value(LogViewOptionDialog::INJECTION_HOSTNAME).toString();
if (m_Hostname.isEmpty())
LogViewInjectionThread::LogViewInjectionThread()
: m_logger(getLogger("LogViewInjectionThread"))
, m_DoStartConnection(false)
, m_SendingPossible(false)
, m_Socket(nullptr)
, m_Timer(nullptr)
{
// set default-hostname if nothing was set
m_Hostname = QLatin1String("localhost");
settings.setValue(LogViewOptionDialog::INJECTION_HOSTNAME, m_Hostname);
// load the settings (and write default-values if not defined)
QSettings settings;
settings.beginGroup(LogViewOptionDialog::INJECTION_GROUP);
m_Hostname = settings.value(LogViewOptionDialog::INJECTION_HOSTNAME).toString();
if (m_Hostname.isEmpty())
{
// set default-hostname if nothing was set
m_Hostname = QLatin1String("localhost");
settings.setValue(LogViewOptionDialog::INJECTION_HOSTNAME, m_Hostname);
}
m_Port = settings.value(LogViewOptionDialog::INJECTION_PORT).toInt();
if (0 == m_Port || m_Port > 65535)
{
m_Port = 46666;
settings.setValue(LogViewOptionDialog::INJECTION_PORT, m_Port);
}
}
m_Port = settings.value(LogViewOptionDialog::INJECTION_PORT).toInt();
if (0 == m_Port || m_Port > 65535)
// ---------------------------------------------------------------
void LogViewInjectionThread::run()
{
m_Port = 46666;
emit updateStatus(QLatin1String(":/image/RedLamp.png"), tr("LogView ist nicht mit TETRA-If-Injection-Server (%1:%2) verbunden").arg(m_Hostname).arg(m_Port));
QTimer::singleShot(100, this, &LogViewInjectionThread::tryToConnect);
exec();
}
// ---------------------------------------------------------------
void LogViewInjectionThread::setPort(uint16_t port)
{
m_Port = port;
QSettings settings;
settings.beginGroup(LogViewOptionDialog::INJECTION_GROUP);
settings.setValue(LogViewOptionDialog::INJECTION_PORT, m_Port);
}
}
// ---------------------------------------------------------------
void LogViewInjectionThread::run()
{
emit updateStatus(QLatin1String(":/image/RedLamp.png"),
tr("LogView ist nicht mit TETRA-If-Injection-Server (%1:%2) verbunden").arg(m_Hostname).arg(m_Port));
QTimer::singleShot(100, this, &LogViewInjectionThread::tryToConnect);
exec();
}
// ---------------------------------------------------------------
void LogViewInjectionThread::setPort(uint16_t port)
{
m_Port = port;
QSettings settings;
settings.beginGroup(LogViewOptionDialog::INJECTION_GROUP);
settings.setValue(LogViewOptionDialog::INJECTION_PORT, m_Port);
}
// ---------------------------------------------------------------
bool LogViewInjectionThread::isSendingPossible() const
{
return m_SendingPossible;
}
// ---------------------------------------------------------------
void LogViewInjectionThread::tryToConnect()
{
//m_Timer->setInterval(3000);
if (!m_Socket)
// ---------------------------------------------------------------
bool LogViewInjectionThread::isSendingPossible() const
{
m_Socket = new QTcpSocket(this);
connect(m_Socket, &QTcpSocket::connected, this, &LogViewInjectionThread::doConnect);
connect(m_Socket, &QTcpSocket::disconnected, this, &LogViewInjectionThread::doDisconnect);
return m_SendingPossible;
}
// we need a timer for retrying connection
if (!m_Timer)
// ---------------------------------------------------------------
void LogViewInjectionThread::tryToConnect()
{
m_Timer = new QTimer(this);
connect(m_Timer, &QTimer::timeout, this, &LogViewInjectionThread::tryToConnect);
//m_Timer->setInterval(3000);
if (!m_Socket)
{
m_Socket = new QTcpSocket(this);
connect(m_Socket, &QTcpSocket::connected, this, &LogViewInjectionThread::doConnect);
connect(m_Socket, &QTcpSocket::disconnected, this, &LogViewInjectionThread::doDisconnect);
}
// we need a timer for retrying connection
if (!m_Timer)
{
m_Timer = new QTimer(this);
connect(m_Timer, &QTimer::timeout, this, &LogViewInjectionThread::tryToConnect);
}
m_Timer->setInterval(3000);
m_Timer->start();
INFO_LOG(m_logger) << "Try to connect to injection-server of TETRA-If (" << m_Hostname << ":" << m_Port << ")";
m_Socket->connectToHost(m_Hostname, m_Port);
}
m_Timer->setInterval(3000);
m_Timer->start();
INFO_LOG(m_logger) << "Try to connect to injection-server of TETRA-If (" << m_Hostname << ":" << m_Port << ")";
m_Socket->connectToHost(m_Hostname, m_Port);
}
// ---------------------------------------------------------------
void LogViewInjectionThread::doConnect()
{
INFO_LOG(m_logger) << "LogView has successful connected to injection-server of TETRA-If";
m_SendingPossible = true;
m_Timer->stop();
emit updateStatus(QLatin1String(":/image/GreenLamp.png"),
tr("LogView ist mit TETRA-If-Injection-Server (%1:%2) verbunden").arg(m_Hostname).arg(m_Port));
}
// ---------------------------------------------------------------
void LogViewInjectionThread::doDisconnect()
{
INFO_LOG(m_logger) << "LogView was disconnected from injection-server of TETRA-If";
m_SendingPossible = false;
emit updateStatus(QLatin1String(":/image/RedLamp.png"),
tr("LogView ist nicht mehr mit TETRA-If-Injection-Server (%1:%2) verbunden").arg(m_Hostname).arg(m_Port));
tryToConnect();
}
// ---------------------------------------------------------------
void LogViewInjectionThread::sendTelegram(LogViewTelegram* a_telegram, const bool a_doSendAsCentralTelegram)
{
INFO_LOG(m_logger) << "inject " << (a_doSendAsCentralTelegram ? "central" : "Tetra") << " telegram";
if (!m_Socket || m_Socket->state() != QAbstractSocket::ConnectedState)
// ---------------------------------------------------------------
void LogViewInjectionThread::doConnect()
{
ERROR_LOG(m_logger) << "Try to write a telegramm but we are not connected";
return;
INFO_LOG(m_logger) << "LogView has successful connected to injection-server of TETRA-If";
m_SendingPossible = true;
m_Timer->stop();
emit updateStatus(QLatin1String(":/image/GreenLamp.png"), tr("LogView ist mit TETRA-If-Injection-Server (%1:%2) verbunden").arg(m_Hostname).arg(m_Port));
}
// ---------------------------------------------------------------
void LogViewInjectionThread::doDisconnect()
{
INFO_LOG(m_logger) << "LogView was disconnected from injection-server of TETRA-If";
m_SendingPossible = false;
emit updateStatus(QLatin1String(":/image/RedLamp.png"), tr("LogView ist nicht mehr mit TETRA-If-Injection-Server (%1:%2) verbunden").arg(m_Hostname).arg(m_Port));
tryToConnect();
}
// ---------------------------------------------------------------
void LogViewInjectionThread::sendTelegram(LogViewTelegram *a_telegram, const bool a_doSendAsCentralTelegram)
{
INFO_LOG(m_logger) << "inject " << (a_doSendAsCentralTelegram ? "central" : "Tetra") << " telegram";
if (!m_Socket || m_Socket->state() != QAbstractSocket::ConnectedState)
{
ERROR_LOG(m_logger) << "Try to write a telegramm but we are not connected";
return;
}
N_CoPrtCnv::CoPrtCnvInjectionHeader injectionHeader;
injectionHeader.m_Kind = a_doSendAsCentralTelegram ? N_CoPrtCnv::CoPrtCnvInjectionHeader::eCentral : N_CoPrtCnv::CoPrtCnvInjectionHeader::eRadio;
const QByteArray &data = a_telegram->getData();
injectionHeader.m_Size = data.size();
m_Socket->write((char *)(&injectionHeader), sizeof(injectionHeader));
m_Socket->write(data);
}
N_CoPrtCnv::CoPrtCnvInjectionHeader injectionHeader;
injectionHeader.m_Kind = a_doSendAsCentralTelegram ? N_CoPrtCnv::CoPrtCnvInjectionHeader::eCentral : N_CoPrtCnv::CoPrtCnvInjectionHeader::eRadio;
const QByteArray &data = a_telegram->getData();
injectionHeader.m_Size = data.size();
m_Socket->write((char*)(&injectionHeader), sizeof(injectionHeader));
m_Socket->write(data);
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include <QtCore/QThread>
@@ -33,7 +33,6 @@ namespace N_LogView
{
Q_OBJECT
public:
LogViewInjectionThread();
void run();
@@ -47,10 +46,9 @@ namespace N_LogView
* @param a_telegram
* @param a_doSendAsCentralTelegram
*/
void sendTelegram(LogViewTelegram* a_telegram, const bool a_doSendAsCentralTelegram);
void sendTelegram(LogViewTelegram *a_telegram, const bool a_doSendAsCentralTelegram);
protected:
NGL::INGLLogger &m_logger;
bool m_DoStartConnection;
bool m_SendingPossible;
@@ -78,8 +76,7 @@ namespace N_LogView
* @param a_picName
* @param a_toolTipText
*/
void updateStatus(const QString& a_picName, const QString& a_toolTipText);
void updateStatus(const QString &a_picName, const QString &a_toolTipText);
};
}
@@ -4,7 +4,7 @@
#include <QtCore/QSettings>
#include <QNetworkProxy>
#ifndef WIN32
#include <unistd.h>
#include <unistd.h>
#endif
#include "LogViewGui.hpp"
#include "logger.h"
@@ -21,10 +21,13 @@ int main(int argc, char *argv[])
s << "/proc/" << getpid() << "/exe";
char buf[1024];
ssize_t len = readlink(s.str().c_str(), buf, 1024);
if(len > 0) {
if (len > 0)
{
buf[len] = '\0';
dir = buf;
} else {
}
else
{
// fallback
dir = argv[0];
}
@@ -32,7 +35,8 @@ int main(int argc, char *argv[])
std::string::size_type pos = dir.find_last_of('/');
if (std::string::npos != pos)
logConfigFileName += dir.substr(0, pos + 1);;
logConfigFileName += dir.substr(0, pos + 1);
;
logConfigFileName += "LogView_log4cxx.props";
qputenv("TDS_DEVEL", QByteArray::number(1));
@@ -49,8 +53,9 @@ int main(int argc, char *argv[])
settings.endGroup();
QScreen *screen = QGuiApplication::screens().value(screenNbr, QGuiApplication::primaryScreen());
N_LogView::LogViewGui* logViewGui = new N_LogView::LogViewGui(nullptr);
if (logViewGui->windowHandle()) {
N_LogView::LogViewGui *logViewGui = new N_LogView::LogViewGui(nullptr);
if (logViewGui->windowHandle())
{
logViewGui->windowHandle()->setScreen(screen);
}
logViewGui->show();
@@ -59,4 +64,3 @@ int main(int argc, char *argv[])
delete logViewGui;
return ret;
}
File diff suppressed because it is too large. Load diff
@@ -21,94 +21,95 @@
namespace N_LogView
{
class ParticipantModel final : public QAbstractTableModel
{
Q_OBJECT
public:
using QAbstractTableModel::QAbstractTableModel;
class ParticipantModel final : public QAbstractTableModel
{
Q_OBJECT
public:
using QAbstractTableModel::QAbstractTableModel;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
void clearParticipants();
bool addUpdateParticipants(const QVector<int> &eqIds,
const QVector<int> &issis,
const QVector<int> &numberOfTelegrams);
protected:
void updateHeatMap() const;
protected:
// eqId , issi
QVector<QPair<int, int> > m_particpants;
// eqid, count telegrams
QHash<int, int> m_particpantMap;
// eqId, QColor for heatmap
mutable QHash<int, QColor> m_participantHeatmap;
};
void clearParticipants();
bool addUpdateParticipants(const QVector<int> &eqIds, const QVector<int> &issis, const QVector<int> &numberOfTelegrams);
class TelegramModel final : public QAbstractTableModel
{
Q_OBJECT
public:
using QAbstractTableModel::QAbstractTableModel;
protected:
void updateHeatMap() const;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
protected:
// eqId , issi
QVector<QPair<int, int>> m_particpants;
// eqid, count telegrams
QHash<int, int> m_particpantMap;
// eqId, QColor for heatmap
mutable QHash<int, QColor> m_participantHeatmap;
};
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
class TelegramModel final : public QAbstractTableModel
{
Q_OBJECT
public:
using QAbstractTableModel::QAbstractTableModel;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
void clearTelegrams();
void appendTelegrams(const QVector<QSharedPointer<LogViewTelegram> > &telegrams);
void appendTelegram(const QSharedPointer<LogViewTelegram> &telegram);
QSharedPointer<LogViewTelegram> telegram(int row) const;
protected:
QVector<QSharedPointer<LogViewTelegram> > m_telegrams;
};
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
class TelegramProxyModel final : public QSortFilterProxyModel
{
Q_OBJECT
public:
using QSortFilterProxyModel::QSortFilterProxyModel;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
void setFilterByEquipmentIds(bool bFilterByEquipmentIds);
void setAllowedEquipmentIds(const std::set<int> &allowedEquipmentIds);
void clearTelegrams();
void appendTelegrams(const QVector<QSharedPointer<LogViewTelegram>> &telegrams);
void appendTelegram(const QSharedPointer<LogViewTelegram> &telegram);
QSharedPointer<LogViewTelegram> telegram(int row) const;
void setFilteredCentralTelegramIds(const std::set<int> &filteredCentralTelegramIds);
void setFilteredTetraTelegramIds(const std::set<int> &filteredTetraTelegramIds);
void setFilteredWlsTelegramIds(const std::set<int> &filteredWlsTelegramIds);
protected:
QVector<QSharedPointer<LogViewTelegram>> m_telegrams;
};
void setFilterCentralTelegrams(N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol direction, bool bFilter);
void setFilterTetraTelegrams(N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol direction, bool bFilter);
void setFilterTetraPDU(N_CoPrtCnv::CoPrtCnvRadioTelegram::E_PDU_Type pduType, bool bFilter);
void setFilterWlsTelegrams(N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol direction, bool bFilter);
class TelegramProxyModel final : public QSortFilterProxyModel
{
Q_OBJECT
public:
using QSortFilterProxyModel::QSortFilterProxyModel;
void setFilterTetraLogin(bool bFilter);
void setFilterTetraFragmented(bool bFilter);
void setFilterByEquipmentIds(bool bFilterByEquipmentIds);
void setAllowedEquipmentIds(const std::set<int> &allowedEquipmentIds);
QSharedPointer<LogViewTelegram> telegram(int row) const;
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
protected:
std::set<int> m_allowedEquipmentIds;
std::set<int> m_filteredCentralTelegramIds;
std::set<int> m_filteredTetraTelegramIds;
std::set<int> m_filteredWlsTelegramIds;
bool m_bFilterByEquipmentIds = false;
bool m_bFilterLoginTelegrams = false;
bool m_bFilterFragmentedTelegrams = false;
std::set<N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol> m_filterCentralTelegrams;
std::set<N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol> m_filterTetraTelegrams;
std::set<N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol> m_filterWlsTelegrams;
std::set<N_CoPrtCnv::CoPrtCnvRadioTelegram::E_PDU_Type> m_filterTetraPDU;
};
void setFilteredCentralTelegramIds(const std::set<int> &filteredCentralTelegramIds);
void setFilteredTetraTelegramIds(const std::set<int> &filteredTetraTelegramIds);
void setFilteredWlsTelegramIds(const std::set<int> &filteredWlsTelegramIds);
void setFilterCentralTelegrams(N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol direction, bool bFilter);
void setFilterTetraTelegrams(N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol direction, bool bFilter);
void setFilterTetraPDU(N_CoPrtCnv::CoPrtCnvRadioTelegram::E_PDU_Type pduType, bool bFilter);
void setFilterWlsTelegrams(N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol direction, bool bFilter);
void setFilterTetraLogin(bool bFilter);
void setFilterTetraFragmented(bool bFilter);
QSharedPointer<LogViewTelegram> telegram(int row) const;
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
protected:
std::set<int> m_allowedEquipmentIds;
std::set<int> m_filteredCentralTelegramIds;
std::set<int> m_filteredTetraTelegramIds;
std::set<int> m_filteredWlsTelegramIds;
bool m_bFilterByEquipmentIds = false;
bool m_bFilterLoginTelegrams = false;
bool m_bFilterFragmentedTelegrams = false;
std::set<N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol> m_filterCentralTelegrams;
std::set<N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol> m_filterTetraTelegrams;
std::set<N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol> m_filterWlsTelegrams;
std::set<N_CoPrtCnv::CoPrtCnvRadioTelegram::E_PDU_Type> m_filterTetraPDU;
};
} // namespace N_LogView
@@ -1,14 +1,14 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
#include "LogViewOptionDialog.hpp"
@@ -28,155 +28,153 @@
namespace N_LogView
{
// static member initialization
const QString LogViewOptionDialog::SPEC_FILES = tr("Spezifikations-Dateien (*.x)");
const QString LogViewOptionDialog::KRLOG_FILES = tr("Log-Dateien (*.krlog)");
const QLatin1String LogViewOptionDialog::SPEC_FILES_GROUP("SpecFiles");
const QLatin1String LogViewOptionDialog::DIR("Dir");
const QLatin1String LogViewOptionDialog::P0_FILENAME("Central2PrtCnv");
const QLatin1String LogViewOptionDialog::P5_FILENAME("PrtCnv2TETRA");
const QLatin1String LogViewOptionDialog::SERVER_GROUP("ServerPorts");
const QLatin1String LogViewOptionDialog::CENTRAL_PORT("Central");
const QLatin1String LogViewOptionDialog::TETRA_PORT("Tetra");
const QLatin1String LogViewOptionDialog::LOG_FILENAME("LogFilename");
const QLatin1String LogViewOptionDialog::INJECTION_GROUP("InjectionServer");
const QLatin1String LogViewOptionDialog::INJECTION_HOSTNAME("InjectionHostname");
const QLatin1String LogViewOptionDialog::INJECTION_PORT("InjectionPort");
// static member initialization
const QString LogViewOptionDialog::SPEC_FILES = tr("Spezifikations-Dateien (*.x)");
const QString LogViewOptionDialog::KRLOG_FILES = tr("Log-Dateien (*.krlog)");
const QLatin1String LogViewOptionDialog::SPEC_FILES_GROUP("SpecFiles");
const QLatin1String LogViewOptionDialog::DIR("Dir");
const QLatin1String LogViewOptionDialog::P0_FILENAME("Central2PrtCnv");
const QLatin1String LogViewOptionDialog::P5_FILENAME("PrtCnv2TETRA");
const QLatin1String LogViewOptionDialog::SERVER_GROUP("ServerPorts");
const QLatin1String LogViewOptionDialog::CENTRAL_PORT("Central");
const QLatin1String LogViewOptionDialog::TETRA_PORT("Tetra");
const QLatin1String LogViewOptionDialog::LOG_FILENAME("LogFilename");
const QLatin1String LogViewOptionDialog::INJECTION_GROUP("InjectionServer");
const QLatin1String LogViewOptionDialog::INJECTION_HOSTNAME("InjectionHostname");
const QLatin1String LogViewOptionDialog::INJECTION_PORT("InjectionPort");
// ---------------------------------------------------------------
LogViewOptionDialog::LogViewOptionDialog(QWidget* a_parent)
: QDialog(a_parent)
{
QVBoxLayout* layout = new QVBoxLayout(this);
// telegram specification files
m_Settings.beginGroup(LogViewOptionDialog::SPEC_FILES_GROUP);
QGroupBox* groupBox = new QGroupBox(tr("Telegramm-Spezifikations-Dateien"), this);
layout->addWidget(groupBox);
QGridLayout* groupLayout = new QGridLayout();
QLabel* p0Label = new QLabel(tr("&Zentrale - Protokollkonverter"), this);
groupLayout->addWidget(p0Label, 0, 0, 1, 2);
QString defString = QCoreApplication::applicationDirPath() + QLatin1String("/training_area_telegrams.h");
m_P0Edit = new QLineEdit(m_Settings.value(P0_FILENAME, defString).toString(), this);
m_P0Edit->setMinimumWidth(400);
groupLayout->addWidget(m_P0Edit);
QPushButton* p0Browse = new QPushButton(tr("Browse"), this);
p0Label->setBuddy(p0Browse);
connect(p0Browse, &QPushButton::clicked, this, &LogViewOptionDialog::browseP0File);
groupLayout->addWidget(p0Browse, 1, 1);
QLabel* p5Label = new QLabel(tr("Protokollkonverter - &TETRA"), this);
groupLayout->addWidget(p5Label, 2, 0, 1, 2);
defString = QCoreApplication::applicationDirPath() + QLatin1String("/zsksxd_tetraForLogView.x");
m_P5Edit = new QLineEdit(m_Settings.value(P5_FILENAME, defString).toString(), this);
groupLayout->addWidget(m_P5Edit);
QPushButton* p5Browse = new QPushButton(tr("Browse"), this);
p5Label->setBuddy(p5Browse);
connect(p5Browse, &QPushButton::clicked, this, &LogViewOptionDialog::browseP5File);
groupLayout->addWidget(p5Browse, 3, 1);
groupBox->setLayout(groupLayout);
m_Settings.endGroup();
// injection
m_Settings.beginGroup(LogViewOptionDialog::INJECTION_GROUP);
groupBox = new QGroupBox(tr("Telegram Injection Server"), this);
layout->addWidget(groupBox);
QGridLayout* injectLayout = new QGridLayout();
QLabel* injectPortLabel = new QLabel(tr("Port"), this);
injectLayout->addWidget(injectPortLabel, 1, 0);
m_InjectPortEdit = new QLineEdit(m_Settings.value(INJECTION_PORT).toString(), this);
QIntValidator* validator = new QIntValidator(1024, 65535, this);
m_InjectPortEdit->setValidator(validator);
injectLayout->addWidget(m_InjectPortEdit, 1, 1);
QLabel* injectHostnameLabel = new QLabel(tr("Hostname"), this);
injectLayout->addWidget(injectHostnameLabel, 0, 0);
m_InjectHostnameEdit = new QLineEdit(m_Settings.value(INJECTION_HOSTNAME).toString(), this);
injectLayout->addWidget(m_InjectHostnameEdit, 0, 1);
groupBox->setLayout(injectLayout);
m_Settings.endGroup();
// buttons
layout->addStretch();
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &LogViewOptionDialog::save);
connect(buttonBox, &QDialogButtonBox::rejected, this, &LogViewOptionDialog::reject);
layout->addWidget(buttonBox);
//setLayout(layout);
}
// ---------------------------------------------------------------
void LogViewOptionDialog::browseP0File()
{
QString newFilename = QFileDialog::getOpenFileName(this,
tr("Zentrale - Protokollkonverter Spezifikations-Datei"),
m_Settings.value(DIR).toString(),
tr("TrainingArea Telegram Headerdatei (training_area_telegrams.h)"));
if (!newFilename.isEmpty())
// ---------------------------------------------------------------
LogViewOptionDialog::LogViewOptionDialog(QWidget *a_parent)
: QDialog(a_parent)
{
m_P0Edit->setText(newFilename);
QDir dir;
QVBoxLayout *layout = new QVBoxLayout(this);
// telegram specification files
m_Settings.beginGroup(LogViewOptionDialog::SPEC_FILES_GROUP);
m_Settings.setValue(DIR, dir.filePath(newFilename));
QGroupBox *groupBox = new QGroupBox(tr("Telegramm-Spezifikations-Dateien"), this);
layout->addWidget(groupBox);
QGridLayout *groupLayout = new QGridLayout();
QLabel *p0Label = new QLabel(tr("&Zentrale - Protokollkonverter"), this);
groupLayout->addWidget(p0Label, 0, 0, 1, 2);
QString defString = QCoreApplication::applicationDirPath() + QLatin1String("/training_area_telegrams.h");
m_P0Edit = new QLineEdit(m_Settings.value(P0_FILENAME, defString).toString(), this);
m_P0Edit->setMinimumWidth(400);
groupLayout->addWidget(m_P0Edit);
QPushButton *p0Browse = new QPushButton(tr("Browse"), this);
p0Label->setBuddy(p0Browse);
connect(p0Browse, &QPushButton::clicked, this, &LogViewOptionDialog::browseP0File);
groupLayout->addWidget(p0Browse, 1, 1);
QLabel *p5Label = new QLabel(tr("Protokollkonverter - &TETRA"), this);
groupLayout->addWidget(p5Label, 2, 0, 1, 2);
defString = QCoreApplication::applicationDirPath() + QLatin1String("/zsksxd_tetraForLogView.x");
m_P5Edit = new QLineEdit(m_Settings.value(P5_FILENAME, defString).toString(), this);
groupLayout->addWidget(m_P5Edit);
QPushButton *p5Browse = new QPushButton(tr("Browse"), this);
p5Label->setBuddy(p5Browse);
connect(p5Browse, &QPushButton::clicked, this, &LogViewOptionDialog::browseP5File);
groupLayout->addWidget(p5Browse, 3, 1);
groupBox->setLayout(groupLayout);
m_Settings.endGroup();
// injection
m_Settings.beginGroup(LogViewOptionDialog::INJECTION_GROUP);
groupBox = new QGroupBox(tr("Telegram Injection Server"), this);
layout->addWidget(groupBox);
QGridLayout *injectLayout = new QGridLayout();
QLabel *injectPortLabel = new QLabel(tr("Port"), this);
injectLayout->addWidget(injectPortLabel, 1, 0);
m_InjectPortEdit = new QLineEdit(m_Settings.value(INJECTION_PORT).toString(), this);
QIntValidator *validator = new QIntValidator(1024, 65535, this);
m_InjectPortEdit->setValidator(validator);
injectLayout->addWidget(m_InjectPortEdit, 1, 1);
QLabel *injectHostnameLabel = new QLabel(tr("Hostname"), this);
injectLayout->addWidget(injectHostnameLabel, 0, 0);
m_InjectHostnameEdit = new QLineEdit(m_Settings.value(INJECTION_HOSTNAME).toString(), this);
injectLayout->addWidget(m_InjectHostnameEdit, 0, 1);
groupBox->setLayout(injectLayout);
m_Settings.endGroup();
// buttons
layout->addStretch();
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &LogViewOptionDialog::save);
connect(buttonBox, &QDialogButtonBox::rejected, this, &LogViewOptionDialog::reject);
layout->addWidget(buttonBox);
//setLayout(layout);
}
}
// ---------------------------------------------------------------
void LogViewOptionDialog::browseP5File()
{
QString newFilename = QFileDialog::getOpenFileName(this, tr("Protokollkonverter - TETRA Spezifikations-Datei"), m_Settings.value(DIR).toString(), SPEC_FILES);
if (!newFilename.isEmpty())
// ---------------------------------------------------------------
void LogViewOptionDialog::browseP0File()
{
m_P5Edit->setText(newFilename);
QDir dir;
QString newFilename = QFileDialog::getOpenFileName(this,
tr("Zentrale - Protokollkonverter Spezifikations-Datei"),
m_Settings.value(DIR).toString(),
tr("TrainingArea Telegram Headerdatei (training_area_telegrams.h)"));
if (!newFilename.isEmpty())
{
m_P0Edit->setText(newFilename);
QDir dir;
m_Settings.beginGroup(LogViewOptionDialog::SPEC_FILES_GROUP);
m_Settings.setValue(DIR, dir.filePath(newFilename));
m_Settings.endGroup();
}
}
// ---------------------------------------------------------------
void LogViewOptionDialog::browseP5File()
{
QString newFilename = QFileDialog::getOpenFileName(this, tr("Protokollkonverter - TETRA Spezifikations-Datei"), m_Settings.value(DIR).toString(), SPEC_FILES);
if (!newFilename.isEmpty())
{
m_P5Edit->setText(newFilename);
QDir dir;
m_Settings.beginGroup(LogViewOptionDialog::SPEC_FILES_GROUP);
m_Settings.setValue(DIR, dir.filePath(newFilename));
m_Settings.endGroup();
}
}
// ---------------------------------------------------------------
void LogViewOptionDialog::save()
{
uint32_t changedFlags = 0;
// check group wise for changes
// specification files
m_Settings.beginGroup(LogViewOptionDialog::SPEC_FILES_GROUP);
m_Settings.setValue(DIR, dir.filePath(newFilename));
QString string = m_Settings.value(P0_FILENAME).toString();
if ((string != m_P0Edit->text()) || (m_Settings.value(P5_FILENAME).toString() != m_P5Edit->text()))
{
m_Settings.setValue(P0_FILENAME, m_P0Edit->text());
m_Settings.setValue(P5_FILENAME, m_P5Edit->text());
changedFlags |= SpecFilesGroup;
}
m_Settings.endGroup();
// injection settings
m_Settings.beginGroup(LogViewOptionDialog::INJECTION_GROUP);
if ((m_Settings.value(INJECTION_HOSTNAME).toString() != m_InjectHostnameEdit->text()) || (m_Settings.value(INJECTION_PORT).toString() != m_InjectPortEdit->text()))
{
m_Settings.setValue(INJECTION_HOSTNAME, m_InjectHostnameEdit->text());
m_Settings.setValue(INJECTION_PORT, m_InjectPortEdit->text());
changedFlags |= InjectionGroup;
}
m_Settings.endGroup();
emit settingsChanged(changedFlags);
accept();
}
}
// ---------------------------------------------------------------
void LogViewOptionDialog::save()
{
uint32_t changedFlags = 0;
// check group wise for changes
// specification files
m_Settings.beginGroup(LogViewOptionDialog::SPEC_FILES_GROUP);
QString string = m_Settings.value(P0_FILENAME).toString();
if ((string != m_P0Edit->text()) ||
(m_Settings.value(P5_FILENAME).toString() != m_P5Edit->text()))
{
m_Settings.setValue(P0_FILENAME, m_P0Edit->text());
m_Settings.setValue(P5_FILENAME, m_P5Edit->text());
changedFlags |= SpecFilesGroup;
}
m_Settings.endGroup();
// injection settings
m_Settings.beginGroup(LogViewOptionDialog::INJECTION_GROUP);
if ((m_Settings.value(INJECTION_HOSTNAME).toString() != m_InjectHostnameEdit->text()) ||
(m_Settings.value(INJECTION_PORT).toString() != m_InjectPortEdit->text()))
{
m_Settings.setValue(INJECTION_HOSTNAME, m_InjectHostnameEdit->text());
m_Settings.setValue(INJECTION_PORT, m_InjectPortEdit->text());
changedFlags |= InjectionGroup;
}
m_Settings.endGroup();
emit settingsChanged(changedFlags);
accept();
}
} // namespace N_LogView
@@ -20,65 +20,64 @@ class QLineEdit;
namespace N_LogView
{
/**
/**
* This class lets the user view and change the settings of the application
*
* @author alois.wismer
* @version 1.0
* @created 09-Mrz-2010 14:49:40
*/
class LogViewOptionDialog : public QDialog
{
Q_OBJECT
public:
class LogViewOptionDialog : public QDialog
{
Q_OBJECT
public:
enum SettingsChangedFlag
{
SpecFilesGroup = 0x01,
ServerGroup = 0x02,
InjectionGroup = 0x04
};
enum SettingsChangedFlag {
SpecFilesGroup = 0x01,
ServerGroup = 0x02,
InjectionGroup = 0x04
};
static const QString KRLOG_FILES;
static const QLatin1String SPEC_FILES_GROUP;
static const QLatin1String P0_FILENAME;
static const QLatin1String P5_FILENAME;
static const QLatin1String SERVER_GROUP;
static const QLatin1String CENTRAL_PORT;
static const QLatin1String TETRA_PORT;
static const QLatin1String SIZE;
static const QLatin1String POS;
static const QLatin1String CENTRAL_IS_SERVER;
static const QLatin1String CENTRAL_HOSTNAME;
static const QLatin1String LOG_FILENAME;
static const QLatin1String INJECTION_GROUP;
static const QLatin1String INJECTION_HOSTNAME;
static const QLatin1String INJECTION_PORT;
static const QString KRLOG_FILES;
static const QLatin1String SPEC_FILES_GROUP;
static const QLatin1String P0_FILENAME;
static const QLatin1String P5_FILENAME;
static const QLatin1String SERVER_GROUP;
static const QLatin1String CENTRAL_PORT;
static const QLatin1String TETRA_PORT;
static const QLatin1String SIZE;
static const QLatin1String POS;
static const QLatin1String CENTRAL_IS_SERVER;
static const QLatin1String CENTRAL_HOSTNAME;
static const QLatin1String LOG_FILENAME;
static const QLatin1String INJECTION_GROUP;
static const QLatin1String INJECTION_HOSTNAME;
static const QLatin1String INJECTION_PORT;
/**
/**
*
* @param a_parent a_parent
*/
explicit LogViewOptionDialog(QWidget* a_parent);
explicit LogViewOptionDialog(QWidget *a_parent);
signals:
void settingsChanged(uint32_t changed); // bitfield of SettingsChangedFlag enum
signals:
void settingsChanged(uint32_t changed); // bitfield of SettingsChangedFlag enum
protected:
protected:
static const QString SPEC_FILES;
static const QLatin1String DIR;
bool m_IsServer;
QLineEdit *m_P0Edit;
QLineEdit *m_P5Edit;
QSettings m_Settings;
QLineEdit *m_InjectHostnameEdit;
QLineEdit *m_InjectPortEdit;
static const QString SPEC_FILES;
static const QLatin1String DIR;
bool m_IsServer;
QLineEdit *m_P0Edit;
QLineEdit *m_P5Edit;
QSettings m_Settings;
QLineEdit *m_InjectHostnameEdit;
QLineEdit *m_InjectPortEdit;
protected slots:
void browseP0File();
void browseP5File();
void save();
};
protected slots:
void browseP0File();
void browseP5File();
void save();
};
}
@@ -1,59 +1,58 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
#include "LogViewSpinBox.hpp"
#include "LogViewField.hpp"
namespace N_LogView
{
// ---------------------------------------------------------------
LogViewSpinBox::LogViewSpinBox(LogViewField* a_field, QWidget* a_parent, const int a_value)
: QSpinBox(a_parent)
, LogViewWidget(a_field, this, a_parent, false)
{
// set range
uint16_t maxArraySize = a_field->maxArraySize();
setRange(0, maxArraySize);
// ---------------------------------------------------------------
LogViewSpinBox::LogViewSpinBox(LogViewField *a_field, QWidget *a_parent, const int a_value)
: QSpinBox(a_parent)
, LogViewWidget(a_field, this, a_parent, false)
{
// set range
uint16_t maxArraySize = a_field->maxArraySize();
setRange(0, maxArraySize);
// set the actual value
setValue(a_value);
// set the actual value
setValue(a_value);
// set tooltip-text
setToolTip(tr("<nobr>Wertebereich: 0..%1</nobr>").arg(maxArraySize));
// set tooltip-text
setToolTip(tr("<nobr>Wertebereich: 0..%1</nobr>").arg(maxArraySize));
// connect
connect(this, &LogViewSpinBox::editingFinished,
this, &LogViewSpinBox::finishEditing);
}
// connect
connect(this, &LogViewSpinBox::editingFinished, this, &LogViewSpinBox::finishEditing);
}
// ---------------------------------------------------------------
void LogViewSpinBox::finishEditing()
{
emit valueEditingFinished(text().toInt());
}
// ---------------------------------------------------------------
void LogViewSpinBox::finishEditing()
{
emit valueEditingFinished(text().toInt());
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewSpinBox::saveContent(LogViewTelegram* a_telegram)
{
Q_UNUSED(a_telegram);
// not yet implemented
return false;
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewSpinBox::saveContent(LogViewTelegram *a_telegram)
{
Q_UNUSED(a_telegram);
// not yet implemented
return false;
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include <QtWidgets/QSpinBox>
@@ -25,7 +25,9 @@ namespace N_LogView
* @version 1.0
* @created 25-Mai-2010 10:39:45
*/
class LogViewSpinBox : public QSpinBox, public LogViewWidget
class LogViewSpinBox
: public QSpinBox
, public LogViewWidget
{
Q_OBJECT
public:
@@ -35,7 +37,7 @@ namespace N_LogView
* @param a_parent
* @param a_value
*/
LogViewSpinBox(LogViewField* a_field, QWidget* a_parent, const int a_value);
LogViewSpinBox(LogViewField *a_field, QWidget *a_parent, const int a_value);
/**
* Writes the content into telegram.
@@ -43,7 +45,7 @@ namespace N_LogView
*
* @param a_telegram
*/
bool saveContent(LogViewTelegram* a_telegram) override;
bool saveContent(LogViewTelegram *a_telegram) override;
protected slots:
void finishEditing();
@@ -54,7 +56,6 @@ namespace N_LogView
* @param a_newValue
*/
void valueEditingFinished(int a_newValue);
};
}
@@ -1,14 +1,14 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
#include "LogViewTabWidget.hpp"
@@ -25,116 +25,116 @@ namespace N_LogView
{
LogViewTabWidget::LogViewTabWidget(LogViewField* a_field, LogViewTelegramDialog* a_parent, LogViewSpinBox* a_spinBox, NGL::INGLLogger& logger)
: QTabWidget(a_parent)
, LogViewWidget(a_field, this, a_parent, false)
, m_TelegramDialog(a_parent)
, m_SpinBox(a_spinBox)
, m_logger(logger)
{
setVisible(false);
}
// ---------------------------------------------------------------
void LogViewTabWidget::changeSize(const int a_newSize)
{
// add new tabs
for (int i = count(); i < a_newSize; i++)
addTab(m_Field, true, i);
// remove old tabs
while (count() > a_newSize)
LogViewTabWidget::LogViewTabWidget(LogViewField *a_field, LogViewTelegramDialog *a_parent, LogViewSpinBox *a_spinBox, NGL::INGLLogger &logger)
: QTabWidget(a_parent)
, LogViewWidget(a_field, this, a_parent, false)
, m_TelegramDialog(a_parent)
, m_SpinBox(a_spinBox)
, m_logger(logger)
{
QStringList path = m_Field->jsonPath();
path += QStringLiteral("index: %1").arg(count() - 1);
m_TelegramDialog->removeItemsFromEditInfoList(path);
removeTab(count() - 1);
setVisible(false);
}
while (m_Field->childCount() > a_newSize)
m_Field->removeLastChild();
setVisible(a_newSize > 0);
m_TelegramDialog->makePretty(); // fixme: funktioniert so nicht, muss als signal realisiert werden
}
// ---------------------------------------------------------------
void LogViewTabWidget::changeSize(const int a_newSize)
{
// add new tabs
for (int i = count(); i < a_newSize; i++)
addTab(m_Field, true, i);
// remove old tabs
while (count() > a_newSize)
{
QStringList path = m_Field->jsonPath();
path += QStringLiteral("index: %1").arg(count() - 1);
m_TelegramDialog->removeItemsFromEditInfoList(path);
removeTab(count() - 1);
}
while (m_Field->childCount() > a_newSize)
m_Field->removeLastChild();
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewTabWidget::saveContent(LogViewTelegram* a_telegram)
{
if (a_telegram->isJsonTelegram())
setVisible(a_newSize > 0);
m_TelegramDialog->makePretty(); // fixme: funktioniert so nicht, muss als signal realisiert werden
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewTabWidget::saveContent(LogViewTelegram *a_telegram)
{
if (a_telegram->isJsonTelegram())
return true;
// if m_SpinBox is NULL, we have a static array => no size has to be stored
if (m_SpinBox)
{
if (!isValid())
return false;
a_telegram->setUIntX(LogViewTelegram::SIZE_CENTRAL_DYN_ARRAY_SIZE, count());
}
return true;
// if m_SpinBox is NULL, we have a static array => no size has to be stored
if (m_SpinBox)
{
if (!isValid())
return false;
a_telegram->setUIntX(LogViewTelegram::SIZE_CENTRAL_DYN_ARRAY_SIZE, count());
}
return true;
}
// ---------------------------------------------------------------
void LogViewTabWidget::addTab(LogViewField* a_field, const bool a_isEmpty, int arrayIdx)
{
if (arrayIdx < 0)
{
WARNING_LOG(m_logger) << "Invalid array index given: " << arrayIdx;
return;
}
QFrame *frame = new QFrame;
QGridLayout *box = new QGridLayout(frame);
QTabWidget::addTab(frame, QStringLiteral("%1 %2").arg(a_field->cleanName()).arg(count()+1));
if (a_isEmpty)
a_field->setHasContent(false);
auto *childTree = a_field->child(arrayIdx);
while (!childTree)
// ---------------------------------------------------------------
void LogViewTabWidget::addTab(LogViewField *a_field, const bool a_isEmpty, int arrayIdx)
{
const auto *first = a_field->child(0);
if (first)
if (arrayIdx < 0)
{
LogViewField *fNew = first->clone(arrayIdx);
a_field->addChild(fNew);
childTree = a_field->child(arrayIdx);
WARNING_LOG(m_logger) << "Invalid array index given: " << arrayIdx;
return;
}
else
QFrame *frame = new QFrame;
QGridLayout *box = new QGridLayout(frame);
QTabWidget::addTab(frame, QStringLiteral("%1 %2").arg(a_field->cleanName()).arg(count() + 1));
if (a_isEmpty)
a_field->setHasContent(false);
auto *childTree = a_field->child(arrayIdx);
while (!childTree)
{
LogViewTetraTelegramsParser *p = LogViewTelegram::jsonParser();
const StructInformation si = p->structFromType(a_field->type());
if (si.type != a_field->type())
const auto *first = a_field->child(0);
if (first)
{
WARNING_LOG(m_logger) << "Could not find type '" << a_field->type() << "' - can not add substructure";
return;
LogViewField *fNew = first->clone(arrayIdx);
a_field->addChild(fNew);
childTree = a_field->child(arrayIdx);
}
else
{
LogViewTetraTelegramsParser *p = LogViewTelegram::jsonParser();
const StructInformation si = p->structFromType(a_field->type());
if (si.type != a_field->type())
{
WARNING_LOG(m_logger) << "Could not find type '" << a_field->type() << "' - can not add substructure";
return;
}
LogViewField *tc = new LogViewField(a_field->name() + QStringLiteral("TabChild"), LogViewField::e_FieldKindTabChild, a_field->xdrElement());
tc->setJsonPath(a_field->jsonPath());
a_field->addChild(tc);
const QString path(QStringLiteral("index: %1"));
LogViewTelegram::addFieldTreeStruct(QJsonObject(), tc, si, path.arg(arrayIdx), m_logger);
childTree = a_field->child(arrayIdx);
}
LogViewField *tc = new LogViewField(a_field->name() + QStringLiteral("TabChild"), LogViewField::e_FieldKindTabChild, a_field->xdrElement());
tc->setJsonPath(a_field->jsonPath());
a_field->addChild(tc);
const QString path(QStringLiteral("index: %1"));
LogViewTelegram::addFieldTreeStruct(QJsonObject(), tc, si, path.arg(arrayIdx), m_logger);
childTree = a_field->child(arrayIdx);
}
m_TelegramDialog->showTree(childTree, box);
// todo: sind nach dem dyn. array noch weitere Felder, so wird addTab nicht richtig funktionieren, weil die
// neuen Felder des Tabs am Ende von m_EditInfoList hinzugefügt werden => diese müssen mittendrin (an der richtigen
// position) eingefügt werden.
// update spinbox
if (m_SpinBox)
{
int spinValue = m_SpinBox->value();
if (spinValue < count())
m_SpinBox->setValue(count());
}
setVisible(true);
}
m_TelegramDialog->showTree(childTree, box);
// todo: sind nach dem dyn. array noch weitere Felder, so wird addTab nicht richtig funktionieren, weil die
// neuen Felder des Tabs am Ende von m_EditInfoList hinzugefügt werden => diese müssen mittendrin (an der richtigen
// position) eingefügt werden.
// update spinbox
if (m_SpinBox)
{
int spinValue = m_SpinBox->value();
if (spinValue < count())
m_SpinBox->setValue(count());
}
setVisible(true);
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include <QtWidgets/QTabWidget>
@@ -30,15 +30,16 @@ namespace N_LogView
* @version 1.0
* @created 26-Mai-2010 17:12:30
*/
class LogViewTabWidget : public QTabWidget, public LogViewWidget
class LogViewTabWidget
: public QTabWidget
, public LogViewWidget
{
Q_OBJECT
public:
LogViewTabWidget(LogViewField *a_field, LogViewTelegramDialog *a_parent, LogViewSpinBox *a_spinBox, NGL::INGLLogger &logger);
LogViewTabWidget(LogViewField* a_field, LogViewTelegramDialog* a_parent, LogViewSpinBox* a_spinBox, NGL::INGLLogger& logger);
bool saveContent(LogViewTelegram* a_telegram) override;
void addTab(LogViewField* a_field, const bool a_isEmpty, int arrayIdx);
bool saveContent(LogViewTelegram *a_telegram) override;
void addTab(LogViewField *a_field, const bool a_isEmpty, int arrayIdx);
public slots:
/**
@@ -48,11 +49,9 @@ namespace N_LogView
void changeSize(const int a_newSize);
protected:
LogViewTelegramDialog* m_TelegramDialog;
LogViewSpinBox* m_SpinBox;
NGL::INGLLogger& m_logger;
LogViewTelegramDialog *m_TelegramDialog;
LogViewSpinBox *m_SpinBox;
NGL::INGLLogger &m_logger;
};
}
@@ -1,16 +1,16 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
// manual class headers
#include "LogViewTableWidget.hpp"
#include "LogViewField.hpp"
@@ -24,289 +24,290 @@ namespace N_LogView
{
LogViewTableWidget::LogViewTableWidget(LogViewField* a_field, QWidget* a_parent, const bool a_readonly, NGL::INGLLogger& logger)
: QTableWidget(0, 2, a_parent)
, LogViewWidget(a_field, this, a_parent, a_readonly)
, m_IsFloat(false)
, m_IsEnum(false)
, m_logger(logger)
{
switch (m_Field->xdrElement()->getKind())
LogViewTableWidget::LogViewTableWidget(LogViewField *a_field, QWidget *a_parent, const bool a_readonly, NGL::INGLLogger &logger)
: QTableWidget(0, 2, a_parent)
, LogViewWidget(a_field, this, a_parent, a_readonly)
, m_IsFloat(false)
, m_IsEnum(false)
, m_logger(logger)
{
case LogViewXdrElement::e_KindEnum:
m_IsEnum = true;
break;
default:
m_IsFloat = LogViewXdrStandardType::e_Float == static_cast<const LogViewXdrStandardType*>(m_Field->xdrElement())->getValueKind();
}
if (!m_IsFloat)
setColumnCount(3);
if (m_IsEnum)
setColumnCount(1);
setHorizontalHeaderItem(0, new QTableWidgetItem(m_IsEnum ? tr("Enum") : tr("Dez")));
if (!m_IsEnum)
{
setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Hex")));
switch (m_Field->xdrElement()->getKind())
{
case LogViewXdrElement::e_KindEnum:
m_IsEnum = true;
break;
default:
m_IsFloat = LogViewXdrStandardType::e_Float == static_cast<const LogViewXdrStandardType *>(m_Field->xdrElement())->getValueKind();
}
if (!m_IsFloat)
{
setHorizontalHeaderItem(2, new QTableWidgetItem(tr("Bin")));
}
}
setAlternatingRowColors(true);
// make pretty
// horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
updateToolTip();
// for debugging only
// INFO_LOG(m_logger) << "type=" << static_cast<const LogViewXdrStandardType*>(a_field->getXdrElement())->getValueKind();
// INFO_LOG(m_logger) << "name=" << static_cast<const LogViewXdrStandardType*>(a_field->getXdrElement())->getName().toStdString();
// a_field->getXdrElement()->dump();
// fill in the values
// fixme: implementiere den Fall isHasContent() false
int nbrOfRows = a_field->valueListSize();
setRowCount(nbrOfRows);
for (int i = 0; i < nbrOfRows; i++)
changeRow(i, a_field->value(i));
makePretty();
// connect signals
connect(this, &LogViewTableWidget::itemChanged,
this, &LogViewTableWidget::checkAndOvertakeContent);
}
// ---------------------------------------------------------------
void LogViewTableWidget::changeSize(const int a_newSize)
{
setRowCount(a_newSize);
disconnect(this, &LogViewTableWidget::itemChanged,
this, &LogViewTableWidget::checkAndOvertakeContent);
// check and set the new fields
for (int i = 0; i < a_newSize; i++)
changeRow(i, QLatin1String("0"));
connect(this, &LogViewTableWidget::itemChanged,
this, &LogViewTableWidget::checkAndOvertakeContent);
makePretty();
m_Valid = true;
}
// ---------------------------------------------------------------
void LogViewTableWidget::changeRow(const int a_rowIndex, const QString& a_value)
{
// INFO_LOG(m_logger) << "a_rowIndex=" << a_rowIndex << " a_value=" << a_value.toStdString();
if (m_IsEnum)
{
// enum
QWidget* enumItem = cellWidget(a_rowIndex, 0);
if (!enumItem)
setCellWidget(a_rowIndex, 0, new LogViewEnumEdit(m_Field, this, m_Readonly, a_rowIndex));
}
else
{
QFont font;
font.setStyleHint(QFont::TypeWriter);
font.setFamily(QString());
// decimal
QTableWidgetItem* decItem = item(a_rowIndex, 0);
if (!decItem)
{
decItem = new QTableWidgetItem();
//decItem->setData(Qt::DisplayRole, 0);
decItem->setText(a_value);
decItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
if (!m_Readonly)
{
decItem->setFlags(decItem->flags() | Qt::ItemIsEditable);
}
decItem->setFont(font);
decItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
setItem(a_rowIndex, 0, decItem);
}
// hexadecimal
QTableWidgetItem* hexItem = item(a_rowIndex, 1);
if (!hexItem)
{
hexItem = new QTableWidgetItem();
hexItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
hexItem->setFont(font);
hexItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
setItem(a_rowIndex, 1, hexItem);
}
// binary
if (!m_IsFloat)
{
QTableWidgetItem* binItem = item(a_rowIndex, 2);
if (!binItem)
{
binItem = new QTableWidgetItem();
binItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
binItem->setFont(font);
binItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
setItem(a_rowIndex, 2, binItem);
}
}
// set the values
checkAndOvertakeContent(decItem);
makePretty();
}
}
// ---------------------------------------------------------------
void LogViewTableWidget::checkAndOvertakeContent(QTableWidgetItem* a_changedItem)
{
if (a_changedItem->column() != 0) return;
int row = a_changedItem->row();
QString text = a_changedItem->text();
bool ok;
int64_t intValue = 0;
double floatValue = 0.0;
// get the calculated and checked value
if (m_IsFloat)
floatValue = getFloat(text, (uint64_t&)intValue, ok, true);
else
intValue = getInteger(text, ok);
// handle errors
if (!ok)
{
setFocus();
// selectAll();
setCurrentCell(row, 0); // todo: funktioniert nicht
return;
}
// set the decimal value
QTableWidgetItem* decField = item(row, 0);
if (decField) decField->setText(QString::number(m_IsFloat ? floatValue : intValue));
// set the hex value
QTableWidgetItem* hexField = item(row, 1);
if (hexField) hexField->setText(toHex(intValue));
// set the binary value
if (!m_IsFloat)
{
QTableWidgetItem* binField = item(row, 2);
if (binField) binField->setText(toBin(intValue));
}
}
// ---------------------------------------------------------------
void LogViewTableWidget::makePretty()
{
//horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
resizeColumnsToContents();
resizeRowsToContents();
// set the height of table-widget
//// QWidget* cellWdg = tableWidget->cellWidget(0, 0);
// int showRows = 7;
// if (m_Field->getValueListSize() < (showRows-1))
// {
// showRows = m_Field->getValueListSize()+1;
// setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// }
// else
// {
// setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
// }
// setFixedHeight(showRows*tableWidget->rowHeight(0));
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewTableWidget::saveContent(LogViewTelegram* a_telegram)
{
if (!isValid())
return false;
if (a_telegram->isJsonTelegram())
{
if (m_Field->kind() == LogViewField::e_FieldKindPodArray)
{
QJsonArray arr;
for (int i = 0; i < rowCount(); ++i)
arr += item(i, 0)->text().toInt();
a_telegram->setJsonValue(m_Field->jsonPath(), arr);
}
else
{
QString value;
value.reserve(rowCount() * 2);
for (int i = 0; i < rowCount(); ++i)
{
int val = item(i, 0)->text().toInt();
value += QStringLiteral("%1").arg(val, 2, 16, QLatin1Char('0'));
}
a_telegram->setJsonValue(m_Field->jsonPath(), value);
}
return true;
}
uint16_t arraySize;
if (m_Field->isDynamicArray())
{
arraySize = rowCount();
a_telegram->setUIntX(LogViewTelegram::SIZE_CENTRAL_DYN_ARRAY_SIZE, arraySize);
// fixme: bei vielen Telegrammen muss Länge auf die Länge des Textes gesetzt werden. Dies kann nicht automatisch gemacht werden. Aber vielleicht kann man schauen, ob vor dem dyn. Array ein Feld Länge vorkommt, oder hartcodieren, oder konfigurierbaren
}
else
{
// todo: teste mit opaque[]
arraySize = m_Field->maxArraySize();
}
// copy the data
INFO_LOG(m_logger) << "arraySize=" << arraySize;
for (int i = 0; i < arraySize; i++)
{
setColumnCount(3);
if (m_IsEnum)
setColumnCount(1);
setHorizontalHeaderItem(0, new QTableWidgetItem(m_IsEnum ? tr("Enum") : tr("Dez")));
if (!m_IsEnum)
{
LogViewEnumEdit *enumEdit = dynamic_cast<LogViewEnumEdit*>(cellWidget(i,0));
enumEdit->saveContent(a_telegram);
}
else
{
uint16_t size = getSize();
QString text = item(i, 0)->text();
setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Hex")));
if (!m_IsFloat)
{
a_telegram->setUIntX(size, text.toULong());
setHorizontalHeaderItem(2, new QTableWidgetItem(tr("Bin")));
}
}
setAlternatingRowColors(true);
// make pretty
// horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
updateToolTip();
// for debugging only
// INFO_LOG(m_logger) << "type=" << static_cast<const LogViewXdrStandardType*>(a_field->getXdrElement())->getValueKind();
// INFO_LOG(m_logger) << "name=" << static_cast<const LogViewXdrStandardType*>(a_field->getXdrElement())->getName().toStdString();
// a_field->getXdrElement()->dump();
// fill in the values
// fixme: implementiere den Fall isHasContent() false
int nbrOfRows = a_field->valueListSize();
setRowCount(nbrOfRows);
for (int i = 0; i < nbrOfRows; i++)
changeRow(i, a_field->value(i));
makePretty();
// connect signals
connect(this, &LogViewTableWidget::itemChanged, this, &LogViewTableWidget::checkAndOvertakeContent);
}
// ---------------------------------------------------------------
void LogViewTableWidget::changeSize(const int a_newSize)
{
setRowCount(a_newSize);
disconnect(this, &LogViewTableWidget::itemChanged, this, &LogViewTableWidget::checkAndOvertakeContent);
// check and set the new fields
for (int i = 0; i < a_newSize; i++)
changeRow(i, QLatin1String("0"));
connect(this, &LogViewTableWidget::itemChanged, this, &LogViewTableWidget::checkAndOvertakeContent);
makePretty();
m_Valid = true;
}
// ---------------------------------------------------------------
void LogViewTableWidget::changeRow(const int a_rowIndex, const QString &a_value)
{
// INFO_LOG(m_logger) << "a_rowIndex=" << a_rowIndex << " a_value=" << a_value.toStdString();
if (m_IsEnum)
{
// enum
QWidget *enumItem = cellWidget(a_rowIndex, 0);
if (!enumItem)
setCellWidget(a_rowIndex, 0, new LogViewEnumEdit(m_Field, this, m_Readonly, a_rowIndex));
}
else
{
QFont font;
font.setStyleHint(QFont::TypeWriter);
font.setFamily(QString());
// decimal
QTableWidgetItem *decItem = item(a_rowIndex, 0);
if (!decItem)
{
decItem = new QTableWidgetItem();
//decItem->setData(Qt::DisplayRole, 0);
decItem->setText(a_value);
decItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
if (!m_Readonly)
{
decItem->setFlags(decItem->flags() | Qt::ItemIsEditable);
}
decItem->setFont(font);
decItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
setItem(a_rowIndex, 0, decItem);
}
// hexadecimal
QTableWidgetItem *hexItem = item(a_rowIndex, 1);
if (!hexItem)
{
hexItem = new QTableWidgetItem();
hexItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
hexItem->setFont(font);
hexItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
setItem(a_rowIndex, 1, hexItem);
}
// binary
if (!m_IsFloat)
{
QTableWidgetItem *binItem = item(a_rowIndex, 2);
if (!binItem)
{
binItem = new QTableWidgetItem();
binItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
binItem->setFont(font);
binItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
setItem(a_rowIndex, 2, binItem);
}
}
// set the values
checkAndOvertakeContent(decItem);
makePretty();
}
}
// ---------------------------------------------------------------
void LogViewTableWidget::checkAndOvertakeContent(QTableWidgetItem *a_changedItem)
{
if (a_changedItem->column() != 0)
return;
int row = a_changedItem->row();
QString text = a_changedItem->text();
bool ok;
int64_t intValue = 0;
double floatValue = 0.0;
// get the calculated and checked value
if (m_IsFloat)
floatValue = getFloat(text, (uint64_t &)intValue, ok, true);
else
intValue = getInteger(text, ok);
// handle errors
if (!ok)
{
setFocus();
// selectAll();
setCurrentCell(row, 0); // todo: funktioniert nicht
return;
}
// set the decimal value
QTableWidgetItem *decField = item(row, 0);
if (decField)
decField->setText(QString::number(m_IsFloat ? floatValue : intValue));
// set the hex value
QTableWidgetItem *hexField = item(row, 1);
if (hexField)
hexField->setText(toHex(intValue));
// set the binary value
if (!m_IsFloat)
{
QTableWidgetItem *binField = item(row, 2);
if (binField)
binField->setText(toBin(intValue));
}
}
// ---------------------------------------------------------------
void LogViewTableWidget::makePretty()
{
//horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
resizeColumnsToContents();
resizeRowsToContents();
// set the height of table-widget
//// QWidget* cellWdg = tableWidget->cellWidget(0, 0);
// int showRows = 7;
// if (m_Field->getValueListSize() < (showRows-1))
// {
// showRows = m_Field->getValueListSize()+1;
// setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// }
// else
// {
// setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
// }
// setFixedHeight(showRows*tableWidget->rowHeight(0));
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewTableWidget::saveContent(LogViewTelegram *a_telegram)
{
if (!isValid())
return false;
if (a_telegram->isJsonTelegram())
{
if (m_Field->kind() == LogViewField::e_FieldKindPodArray)
{
QJsonArray arr;
for (int i = 0; i < rowCount(); ++i)
arr += item(i, 0)->text().toInt();
a_telegram->setJsonValue(m_Field->jsonPath(), arr);
}
else
{
const LogViewXdrStandardType *stdType = static_cast<const LogViewXdrStandardType*>(m_Field->xdrElement());
LogViewXdrStandardType::E_ByteOrder byteOrder = stdType->getByteOrder();
uint64_t hex;
getFloat(text, hex, m_Valid);
a_telegram->setUIntX(size, hex, byteOrder);
QString value;
value.reserve(rowCount() * 2);
for (int i = 0; i < rowCount(); ++i)
{
int val = item(i, 0)->text().toInt();
value += QStringLiteral("%1").arg(val, 2, 16, QLatin1Char('0'));
}
a_telegram->setJsonValue(m_Field->jsonPath(), value);
}
return true;
}
uint16_t arraySize;
if (m_Field->isDynamicArray())
{
arraySize = rowCount();
a_telegram->setUIntX(LogViewTelegram::SIZE_CENTRAL_DYN_ARRAY_SIZE, arraySize);
// fixme: bei vielen Telegrammen muss Länge auf die Länge des Textes gesetzt werden. Dies kann nicht automatisch gemacht werden. Aber vielleicht kann man schauen, ob vor dem dyn. Array ein Feld Länge vorkommt, oder hartcodieren, oder konfigurierbaren
}
else
{
// todo: teste mit opaque[]
arraySize = m_Field->maxArraySize();
}
// copy the data
INFO_LOG(m_logger) << "arraySize=" << arraySize;
for (int i = 0; i < arraySize; i++)
{
if (m_IsEnum)
{
LogViewEnumEdit *enumEdit = dynamic_cast<LogViewEnumEdit *>(cellWidget(i, 0));
enumEdit->saveContent(a_telegram);
}
else
{
uint16_t size = getSize();
QString text = item(i, 0)->text();
if (!m_IsFloat)
{
a_telegram->setUIntX(size, text.toULong());
}
else
{
const LogViewXdrStandardType *stdType = static_cast<const LogViewXdrStandardType *>(m_Field->xdrElement());
LogViewXdrStandardType::E_ByteOrder byteOrder = stdType->getByteOrder();
uint64_t hex;
getFloat(text, hex, m_Valid);
a_telegram->setUIntX(size, hex, byteOrder);
}
}
}
return true;
}
return true;
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include <QTableWidget>
@@ -26,11 +26,13 @@ namespace N_LogView
* @version 1.0
* @created 25-Mai-2010 09:34:24
*/
class LogViewTableWidget : public QTableWidget, public LogViewWidget
class LogViewTableWidget
: public QTableWidget
, public LogViewWidget
{
Q_OBJECT
public:
LogViewTableWidget(LogViewField* a_field, QWidget* a_parent, const bool a_readonly, NGL::INGLLogger& logger);
LogViewTableWidget(LogViewField *a_field, QWidget *a_parent, const bool a_readonly, NGL::INGLLogger &logger);
/**
* Writes the content into telegram.
@@ -38,20 +40,20 @@ namespace N_LogView
*
* @param a_telegram
*/
bool saveContent(LogViewTelegram* a_telegram) override;
bool saveContent(LogViewTelegram *a_telegram) override;
public slots:
void changeSize(const int a_newSize);
protected:
void changeRow(const int a_rowIndex, const QString& a_value);
void changeRow(const int a_rowIndex, const QString &a_value);
void makePretty();
protected slots:
void checkAndOvertakeContent(QTableWidgetItem* a_changedItem);
void checkAndOvertakeContent(QTableWidgetItem *a_changedItem);
private:
bool m_IsFloat;
bool m_IsEnum;
NGL::INGLLogger& m_logger;
NGL::INGLLogger &m_logger;
};
}
File diff suppressed because it is too large. Load diff
@@ -49,7 +49,6 @@ namespace N_LogView
class LogViewTelegram final
{
public:
/**
* @author alois.wismer
* @version 1.0
@@ -99,8 +98,7 @@ namespace N_LogView
* @param a_destination
* @param a_telId
*/
LogViewTelegram(const N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol a_destination,
int telegramId);
LogViewTelegram(const N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol a_destination, int telegramId);
/**
* Constructor for existing telegrams
@@ -110,9 +108,7 @@ namespace N_LogView
* @param a_telegramData
* @param a_telegramSize
*/
LogViewTelegram(const N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol a_destination,
const quint64 a_unixTime,
const QByteArray &a_telegramData);
LogViewTelegram(const N_CoPrtCnv::CoPrtCnvLogHeader::E_CoPrtCnvProtocol a_destination, const quint64 a_unixTime, const QByteArray &a_telegramData);
/**
* Writes a_value with size a_size at actual position of m_Data (given with
@@ -123,9 +119,7 @@ namespace N_LogView
* @param a_value
* @param a_byteOrder
*/
void setUIntX(const uint8_t a_size,
quint64 a_value,
const LogViewXdrStandardType::E_ByteOrder a_byteOrder = LogViewXdrStandardType::e_ByteOrderBigEndian);
void setUIntX(const uint8_t a_size, quint64 a_value, const LogViewXdrStandardType::E_ByteOrder a_byteOrder = LogViewXdrStandardType::e_ByteOrderBigEndian);
/**
* Returns true if a_data could be written.
@@ -188,7 +182,7 @@ namespace N_LogView
void resetOffset();
LogViewField* getFieldTree();
LogViewField *getFieldTree();
void dump() const;
@@ -216,14 +210,18 @@ namespace N_LogView
bool isJsonTelegram() const { return N_CoPrtCnv::CoPrtCnvLogHeader::e_DestProtocolCentral == m_Protocol; }
void clearJsonData() { m_json.remove(QStringLiteral("data")); }
void rebuildJsonString() { if (!m_json.isEmpty()) m_data.clear(); }
void rebuildJsonString()
{
if (!m_json.isEmpty())
m_data.clear();
}
void setJsonValue(const QStringList &path, const QJsonValue &val);
QJsonObject jsonData() const { return m_json; }
void updateJsonValue(const QStringList &path, const QJsonValue &newVal, QJsonObject &obj);
void updateJsonValue(const QStringList &path, const QJsonValue &newVal, QJsonArray &arr);
const N_CoPrtCnv::CoPrtCnvRadioTelegram* getTetraTelegram() const;
const N_CoPrtCnv::CoPrtCnvRadioTelegram *getTetraTelegram() const;
static LogViewTetraTelegramsParser *jsonParser();
static LogViewXdrParser *tetraParser();
@@ -275,7 +273,6 @@ namespace N_LogView
static uint32_t floatToXdr(float in);
protected:
/**
* The name of the telegram, shown in edit-list
*/
@@ -297,7 +294,7 @@ namespace N_LogView
* The allocated size of m_Data. (Used for optimizing of speed)
*/
int m_AllocatedSize;
static const LogViewXdrParser* m_Parser;
static const LogViewXdrParser *m_Parser;
uint16_t m_ActOffset;
QVector<uint16_t> m_GpsFieldOffset;
int m_TelId;
@@ -338,15 +335,14 @@ namespace N_LogView
QJsonObject m_json;
N_CoPrtCnv::CoPrtCnvRadioTelegram *m_TetraTelegram;
NGL::INGLLogger& m_logger;
NGL::INGLLogger &m_logger;
LogViewField *getFieldTree(const QString& a_type, const QString& a_name,
uint16_t a_arraySize, const LogViewXdrType* a_parentElement = nullptr,
LogViewField *getFieldTree(const QString &a_type,
const QString &a_name,
uint16_t a_arraySize,
const LogViewXdrType *a_parentElement = nullptr,
const bool a_hasContent = true);
LogViewField *getFieldTreeJson(const QJsonValue &data,
const QString &name,
const StructInformation &si,
const QStringList &objectPathBase);
LogViewField *getFieldTreeJson(const QJsonValue &data, const QString &name, const StructInformation &si, const QStringList &objectPathBase);
static void addFieldTreeStruct(const QJsonObject &parentObject,
LogViewField *parent,
@@ -402,7 +398,9 @@ namespace N_LogView
* @param a_size
* @param a_byteOrder
*/
quint64 getUIntX(const uint16_t a_offset, const uint8_t a_size, const LogViewXdrStandardType::E_ByteOrder a_byteOrder = LogViewXdrStandardType::e_ByteOrderBigEndian) const;
quint64 getUIntX(const uint16_t a_offset,
const uint8_t a_size,
const LogViewXdrStandardType::E_ByteOrder a_byteOrder = LogViewXdrStandardType::e_ByteOrderBigEndian) const;
/**
*
@@ -410,7 +408,9 @@ namespace N_LogView
* @param a_size
* @param a_byteOrder
*/
int32_t getSIntX(const uint16_t a_offset, const uint8_t a_size, const LogViewXdrStandardType::E_ByteOrder a_byteOrder = LogViewXdrStandardType::e_ByteOrderBigEndian) const;
int32_t getSIntX(const uint16_t a_offset,
const uint8_t a_size,
const LogViewXdrStandardType::E_ByteOrder a_byteOrder = LogViewXdrStandardType::e_ByteOrderBigEndian) const;
/**
*
@@ -425,36 +425,33 @@ namespace N_LogView
* @param a_offset
* @param a_arraySize
*/
LogViewField* getContent(const LogViewXdrStandardType* a_standardType, uint16_t& a_offset, const uint16_t a_arraySize);
LogViewField *getContent(const LogViewXdrStandardType *a_standardType, uint16_t &a_offset, const uint16_t a_arraySize);
/**
*
* @param a_xdrType
*/
bool isScalar(const LogViewXdrType* a_xdrType) const;
bool isScalar(const LogViewXdrType *a_xdrType) const;
/**
*
* @param a_errorText
* @param a_title
*/
void showMessageBox(const QString& a_errorText, const QString& a_title = QObject::tr("Invalid telegram")) const;
void showMessageBox(const QString &a_errorText, const QString &a_title = QObject::tr("Invalid telegram")) const;
/**
*
* @param a_offset
*/
uint16_t getDynArraySize(uint16_t& a_offset) const;
uint16_t getDynArraySize(uint16_t &a_offset) const;
/**
*
* @param a_name
* @param a_value
*/
static QString formatToolTipLine(const QString& a_name, const uint32_t a_value)
{
return formatToolTipLine(a_name, QString::number(a_value), a_value);
}
static QString formatToolTipLine(const QString &a_name, const uint32_t a_value) { return formatToolTipLine(a_name, QString::number(a_value), a_value); }
/**
*
@@ -462,9 +459,9 @@ namespace N_LogView
* @param a_text
* @param a_value
*/
static QString formatToolTipLine(const QString& a_name, const QString& a_text, const uint32_t a_value);
static QString formatToolTipLine(const QString &a_name, const QString &a_text, const uint32_t a_value);
static QString formatToolTipLine(const QString& a_name, const std::string& a_text, const uint32_t a_value)
static QString formatToolTipLine(const QString &a_name, const std::string &a_text, const uint32_t a_value)
{
return formatToolTipLine(a_name, QString::fromStdString(a_text), a_value);
}
@@ -478,6 +475,5 @@ namespace N_LogView
private:
friend class LogViewTabWidget;
};
}
@@ -42,461 +42,454 @@
namespace N_LogView
{
// todo:
// - feld einfärben wenn geändert, wenn falsch
// - mache hartcodierte oder konfigurierbare ranges für spezielle Werte wie GPS-Position: signed 24-bit
// todo:
// - feld einfärben wenn geändert, wenn falsch
// - mache hartcodierte oder konfigurierbare ranges für spezielle Werte wie GPS-Position: signed 24-bit
LogViewTelegramDialog::LogViewTelegramDialog(QWidget *a_parent, const bool a_readonly, NGL::INGLLogger& logger)
: QDialog(a_parent)
, m_ReadOnly(a_readonly)
, m_logger(logger)
{
setAttribute(Qt::WA_DeleteOnClose);
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::showDialog(const QSharedPointer<LogViewTelegram> &a_telegram)
{
delete layout();
hide();
m_Telegram = a_telegram;
a_telegram->dump();
m_fieldTree.reset(a_telegram->getFieldTree());
if (m_fieldTree)
LogViewTelegramDialog::LogViewTelegramDialog(QWidget *a_parent, const bool a_readonly, NGL::INGLLogger &logger)
: QDialog(a_parent)
, m_ReadOnly(a_readonly)
, m_logger(logger)
{
QGridLayout *dialogLayout = new QGridLayout;
if (!m_ReadOnly)
setAttribute(Qt::WA_DeleteOnClose);
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::showDialog(const QSharedPointer<LogViewTelegram> &a_telegram)
{
delete layout();
hide();
m_Telegram = a_telegram;
a_telegram->dump();
m_fieldTree.reset(a_telegram->getFieldTree());
if (m_fieldTree)
{
// edit wait-time
QLabel *waitTimeLabel = new QLabel(tr("Wartezeit [ms]"), this);
dialogLayout->addWidget(waitTimeLabel, dialogLayout->rowCount(), 0);
m_WaitTimeEdit = new QLineEdit(QString::number(a_telegram->getWaitTime()), this);
dialogLayout->addWidget(m_WaitTimeEdit, dialogLayout->rowCount() - 1, 1);
QGridLayout *dialogLayout = new QGridLayout;
if (!m_ReadOnly)
{
// edit wait-time
QLabel *waitTimeLabel = new QLabel(tr("Wartezeit [ms]"), this);
dialogLayout->addWidget(waitTimeLabel, dialogLayout->rowCount(), 0);
m_WaitTimeEdit = new QLineEdit(QString::number(a_telegram->getWaitTime()), this);
dialogLayout->addWidget(m_WaitTimeEdit, dialogLayout->rowCount() - 1, 1);
// edit name
QLabel *nameLabel = new QLabel(tr("Name"), this);
dialogLayout->addWidget(nameLabel, dialogLayout->rowCount(), 0);
m_NameEdit = new QLineEdit(a_telegram->getName(), this);
dialogLayout->addWidget(m_NameEdit, dialogLayout->rowCount() - 1, 1);
// edit name
QLabel *nameLabel = new QLabel(tr("Name"), this);
dialogLayout->addWidget(nameLabel, dialogLayout->rowCount(), 0);
m_NameEdit = new QLineEdit(a_telegram->getName(), this);
dialogLayout->addWidget(m_NameEdit, dialogLayout->rowCount() - 1, 1);
QFrame *f = new QFrame(this);
f->setFrameShape(QFrame::HLine);
f->setFrameShadow(QFrame::Sunken);
dialogLayout->addWidget(f, dialogLayout->rowCount(), 0, 1, 2);
QFrame *f = new QFrame(this);
f->setFrameShape(QFrame::HLine);
f->setFrameShadow(QFrame::Sunken);
dialogLayout->addWidget(f, dialogLayout->rowCount(), 0, 1, 2);
}
//INFO_LOG(m_logger) << "--------------- create dialog " << fieldTree->getName().toStdString() << "--------------";
//m_fieldTree->dump();
showTree(m_fieldTree.data(), dialogLayout);
if (this->findChild<LogViewTableWidget *>() == nullptr)
dialogLayout->setRowStretch(dialogLayout->rowCount(), 1);
// build the dialog
QVBoxLayout *mainLayout = new QVBoxLayout(this);
// make dialog scrollable
m_contentsWidget = new QWidget;
m_contentsWidget->setLayout(dialogLayout);
m_ScrollArea = new QScrollArea(this);
m_ScrollArea->setWidget(m_contentsWidget);
m_ScrollArea->setWidgetResizable(true);
mainLayout->addWidget(m_ScrollArea);
// buttons
QHBoxLayout *btnLayout = new QHBoxLayout;
btnLayout->addStretch();
showButtons(btnLayout);
mainLayout->addLayout(btnLayout);
setWindowTitle(m_fieldTree->cleanName() + QStringLiteral(" (%1)").arg(a_telegram->getTelId()));
setModal(true);
show();
makePretty();
}
else
showDataDump(a_telegram, true);
}
//INFO_LOG(m_logger) << "--------------- create dialog " << fieldTree->getName().toStdString() << "--------------";
//m_fieldTree->dump();
showTree(m_fieldTree.data(), dialogLayout);
if (this->findChild<LogViewTableWidget *>() == nullptr)
dialogLayout->setRowStretch(dialogLayout->rowCount(), 1);
// build the dialog
QVBoxLayout *mainLayout = new QVBoxLayout(this);
// ---------------------------------------------------------------
void LogViewTelegramDialog::showDataDump(const QSharedPointer<LogViewTelegram> &a_telegram, bool showErrorMessage)
{
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(new QLabel(tr("Telegramm-Dump")));
// make dialog scrollable
m_contentsWidget = new QWidget;
m_contentsWidget->setLayout(dialogLayout);
if (showErrorMessage)
// show error-message in dialog
layout->addWidget(new QLabel(tr("Konnte Dialog basierend auf Struktur \'%1\' nicht generieren!").arg(a_telegram->getStructName())));
else
layout->addWidget(new QLabel(tr("HexData from \'%1\' - telegram:").arg(a_telegram->getName())));
m_ScrollArea = new QScrollArea(this);
m_ScrollArea->setWidget(m_contentsWidget);
m_ScrollArea->setWidgetResizable(true);
// generate the telegram-dump
QString theDump = QLatin1String("<code>");
const QByteArray &data = a_telegram->getData();
for (int i = 0; i < data.size(); i++)
{
if (0 == (i % 8))
theDump += QStringLiteral("%1:").arg(i, 4, 16, QLatin1Char('0'));
mainLayout->addWidget(m_ScrollArea);
theDump += QStringLiteral(" %1").arg(static_cast<unsigned char>(data[i]), 2, 16, QLatin1Char('0'));
if (7 == (i % 8))
theDump += QLatin1String("<br>");
}
theDump += QLatin1String("</code>");
// buttons
QTextEdit *telegramDump = new QTextEdit(theDump);
layout->addWidget(telegramDump);
QPushButton *btnClose = new QPushButton(QIcon(QLatin1String(":icons/16x16/edit-delete.png")), tr("&Schliessen"));
QHBoxLayout *btnLayout = new QHBoxLayout;
btnLayout->addStretch();
showButtons(btnLayout);
mainLayout->addLayout(btnLayout);
setWindowTitle(m_fieldTree->cleanName() + QStringLiteral(" (%1)").arg(a_telegram->getTelId()));
setModal(true);
btnLayout->addWidget(btnClose);
layout->addLayout(btnLayout);
connect(btnClose, &QPushButton::clicked, this, &LogViewTelegramDialog::reject);
setLayout(layout);
show();
makePretty();
}
else
showDataDump(a_telegram, true);
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::showDataDump(const QSharedPointer<LogViewTelegram> &a_telegram, bool showErrorMessage)
{
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(new QLabel(tr("Telegramm-Dump")));
if (showErrorMessage)
// show error-message in dialog
layout->addWidget(new QLabel(tr("Konnte Dialog basierend auf Struktur \'%1\' nicht generieren!").arg(a_telegram->getStructName())));
else
layout->addWidget(new QLabel(tr("HexData from \'%1\' - telegram:").arg(a_telegram->getName())));
// generate the telegram-dump
QString theDump = QLatin1String("<code>");
const QByteArray &data = a_telegram->getData();
for (int i = 0; i < data.size(); i++)
// ---------------------------------------------------------------
void LogViewTelegramDialog::makePretty()
{
if (0 == (i % 8))
theDump += QStringLiteral("%1:").arg(i, 4, 16, QLatin1Char('0'));
return;
// set the size and position of dialog
int sbWidth = m_ScrollArea->width() - m_ScrollArea->viewport()->width();
int wDiff = m_contentsWidget->width() - m_ScrollArea->width();
int hDiff = m_contentsWidget->height() - m_ScrollArea->viewport()->height();
const QRect screenSize = QGuiApplication::primaryScreen()->geometry();
theDump += QStringLiteral(" %1").arg(static_cast<unsigned char>(data[i]), 2, 16, QLatin1Char('0'));
if (7 == (i % 8))
theDump += QLatin1String("<br>");
int newWidth = std::min(width() + wDiff + sbWidth, screenSize.width() * 9 / 10);
int newHeight = std::min(height() + hDiff, screenSize.height() * 9 / 10);
//setGeometry(winGeo);
//QSize size = settings.value(SIZE, sizeHint()).toSize();
resize(QSize(newWidth, newHeight));
//move(settings.value(POS, QPoint(0, 0)).toPoint());
// --------------------------------------------------------------------
}
theDump += QLatin1String("</code>");
QTextEdit *telegramDump = new QTextEdit(theDump);
layout->addWidget(telegramDump);
QPushButton *btnClose = new QPushButton(QIcon(QLatin1String(":icons/16x16/edit-delete.png")), tr("&Schliessen"));
QHBoxLayout *btnLayout = new QHBoxLayout;
btnLayout->addStretch();
btnLayout->addWidget(btnClose);
layout->addLayout(btnLayout);
connect(btnClose, &QPushButton::clicked,
this, &LogViewTelegramDialog::reject);
setLayout(layout);
show();
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::makePretty()
{
return;
// set the size and position of dialog
int sbWidth = m_ScrollArea->width() - m_ScrollArea->viewport()->width();
int wDiff = m_contentsWidget->width() - m_ScrollArea->width();
int hDiff = m_contentsWidget->height() - m_ScrollArea->viewport()->height();
const QRect screenSize = QGuiApplication::primaryScreen()->geometry();
int newWidth = std::min(width() + wDiff + sbWidth, screenSize.width() * 9 / 10);
int newHeight = std::min(height() + hDiff, screenSize.height() * 9 / 10);
//setGeometry(winGeo);
//QSize size = settings.value(SIZE, sizeHint()).toSize();
resize(QSize(newWidth, newHeight));
//move(settings.value(POS, QPoint(0, 0)).toPoint());
// --------------------------------------------------------------------
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::showTree(LogViewField *a_fieldTree, QGridLayout *a_box)
{
int i = 0;
while (LogViewField *child = a_fieldTree->child(i++))
// ---------------------------------------------------------------
void LogViewTelegramDialog::showTree(LogViewField *a_fieldTree, QGridLayout *a_box)
{
if (!a_fieldTree->hasContent())
child->setHasContent(false);
switch (child->kind())
int i = 0;
while (LogViewField *child = a_fieldTree->child(i++))
{
case LogViewField::e_FieldKindBorder:
{
QGroupBox *groupBox = new QGroupBox(child->cleanName());
QGridLayout *actBox = new QGridLayout(groupBox);
a_box->addWidget(groupBox, a_box->rowCount(), 0, 1, 2);
showTree(child, actBox);
break;
}
case LogViewField::e_FieldKindTab:
showTab(child, a_box);
break;
case LogViewField::e_FieldKindTabChild:
{
QWidget *widget = new QWidget;
widget->setContentsMargins(QMargins());
QGridLayout *actBox = new QGridLayout(widget);
a_box->addWidget(widget, a_box->rowCount(), 0, 1, 2);
showTree(child, actBox);
break;
}
case LogViewField::e_FieldKindEdit:
case LogViewField::e_FieldKindPodArray:
case LogViewField::e_FieldKindPodArrayChild:
showEditField(child, a_box);
break;
}
}
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::fillTelegram(LogViewTelegram *a_telegram)
{
INFO_LOG(m_logger) << "******************************************";
for (const auto ptr : std::as_const(m_EditInfoList))
{
if (!ptr->isValid())
{
INFO_LOG(m_logger) << ptr->field()->name() << " is invalid";
return; // abort when a value is not vaild
}
}
// now save the values
// -------------------
a_telegram->resetOffset();
a_telegram->clearJsonData();
for (auto ptr : std::as_const(m_EditInfoList))
{
if (!ptr->saveContent(a_telegram))
{
QMessageBox::warning(this, tr("Error while saving telegram"),
tr("Found an invalid value - the telegram may be not saved correctly"));
}
}
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::saveTelegram()
{
fillTelegram(m_Telegram.data());
// save wait-time and name
N_SST::IntegerCalculator calculator;
N_SST::IntegerCalculator::E_Error error;
m_Telegram->setWaitTime(calculator.calc(m_WaitTimeEdit->text().toStdString(), error));
m_Telegram->setName(m_NameEdit->text());
accept();
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::sendCurrentTelegram()
{
emit sendTelegram(m_Telegram);
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::showButtons(QLayout *a_layout)
{
if (N_CoPrtCnv::CoPrtCnvLogHeader::e_DestProtocolCentral == m_Telegram->getProtocol())
{
QPushButton *btnSend = new QPushButton(QIcon(QLatin1String(":icons/16x16/mail-send.png")), tr("&Send"));
btnSend->setEnabled(true); // TODO: Status ob wirklich möglich ggf. überprüfen
connect(btnSend, &QPushButton::clicked, this, &LogViewTelegramDialog::sendCurrentTelegram);
a_layout->addWidget(btnSend);
}
if (m_ReadOnly)
{
QPushButton *btnClose = new QPushButton(QIcon(QLatin1String(":icons/16x16/edit-delete.png")), tr("&Schliessen"));
connect(btnClose, &QPushButton::clicked, this, &LogViewTelegramDialog::reject);
a_layout->addWidget(btnClose);
}
else
{
QPushButton *btnClose = new QPushButton(QIcon(QLatin1String(":icons/16x16/edit-delete.png")), tr("&Abbrechen"));
connect(btnClose, &QPushButton::clicked, this, &LogViewTelegramDialog::reject);
a_layout->addWidget(btnClose);
QPushButton *btnOk = new QPushButton(QIcon(QLatin1String(":icons/16x16/dialog-ok-apply.png")), tr("&OK"));
btnOk->setDefault(true);
// fixme: absturz, wenn feld ungültiger wert enthält und ok gedrückt wird
connect(btnOk, &QPushButton::clicked, this, &LogViewTelegramDialog::saveTelegram);
a_layout->addWidget(btnOk);
}
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::showEditField(LogViewField *a_logViewField, QGridLayout *a_box)
{
// INFO_LOG(m_logger) << a_logViewField->getName() <<
// << " a_logViewField->getValueListSize()=" << a_logViewField->getValueListSize()
// << " a_logViewField->isIsDynamicArray()=" << a_logViewField->isIsDynamicArray()
// << " a_logViewField->getValue(0)=" << a_logViewField->getValue(0).toStdString()
// << " a_logViewField->getXdrElement())->getValueKind()=" << (int)(static_cast<const LogViewXdrStandardType*>(a_logViewField->getXdrElement())->getValueKind())
// ;
switch (a_logViewField->valueListSize())
{
case 1:
// 1 field (single or multi-line)
if (m_ReadOnly || !a_logViewField->isDynamicArray() || (LogViewXdrStandardType::e_Character == static_cast<const LogViewXdrStandardType *>(a_logViewField->xdrElement())->getValueKind()))
{
QLabel *label = new QLabel(a_logViewField->cleanName());
a_box->addWidget(label, a_box->rowCount(), 0);
LogViewWidget *valueWidget = nullptr;
//QString value = a_logViewField->getValue(0);
// if (-1 == value.indexOf("<br>") && value.length() < 80)
if (!a_fieldTree->hasContent())
child->setHasContent(false);
switch (child->kind())
{
// single line
// -----------
if (LogViewXdrElement::e_KindEnum == a_logViewField->xdrElement()->getKind())
case LogViewField::e_FieldKindBorder:
{
// enum => combobox
// ----------------
valueWidget = new LogViewEnumEdit(a_logViewField, this, m_ReadOnly, 0);
QGroupBox *groupBox = new QGroupBox(child->cleanName());
QGridLayout *actBox = new QGridLayout(groupBox);
a_box->addWidget(groupBox, a_box->rowCount(), 0, 1, 2);
showTree(child, actBox);
break;
}
else
case LogViewField::e_FieldKindTab:
showTab(child, a_box);
break;
case LogViewField::e_FieldKindTabChild:
{
if (a_logViewField->isDateTimeField() || a_logViewField->isMSecsField())
{
// date-time-field
// ---------------
valueWidget = new LogViewDateTimeEdit(a_logViewField, this, m_ReadOnly);
}
else
{
switch (static_cast<const LogViewXdrStandardType *>(a_logViewField->xdrElement())->getValueKind())
{
case LogViewXdrStandardType::e_Boolean:
valueWidget = new LogViewBooleanEdit(a_logViewField, this, m_ReadOnly);
break;
case LogViewXdrStandardType::e_Signed:
case LogViewXdrStandardType::e_Unsigned:
case LogViewXdrStandardType::e_Float:
case LogViewXdrStandardType::e_Data:
valueWidget = new LogViewValueEdit(a_logViewField, this, m_ReadOnly);
break;
case LogViewXdrStandardType::e_Character: // Text
valueWidget = new LogViewTextEdit(a_logViewField, this, m_ReadOnly);
break;
}
}
QWidget *widget = new QWidget;
widget->setContentsMargins(QMargins());
QGridLayout *actBox = new QGridLayout(widget);
a_box->addWidget(widget, a_box->rowCount(), 0, 1, 2);
showTree(child, actBox);
break;
}
if (valueWidget)
m_EditInfoList.push_back(valueWidget);
case LogViewField::e_FieldKindEdit:
case LogViewField::e_FieldKindPodArray:
case LogViewField::e_FieldKindPodArrayChild:
showEditField(child, a_box);
break;
}
// else
// {
// // ----------------------------------------------------------------
// // fixme: not used => take away
// // multi-line
// valueWidget = new QTextEdit(value);
// static_cast<QTextEdit*>(valueWidget)->setReadOnly(true);
// // make proper width of widget
// QFontMetrics fm(valueWidget->font());
// // the 0 (at end) are here, because QFontMetrics does not understand the <code> and <b> tags.
// // So not the correct font will be used for calculating the width.
// // The solution here is suboptimal, but will hopefully work with a lot of fonts...
// valueWidget->setMinimumWidth(fm.width("0000: 00 00 00 00 00 00 00")*1.7);
// // ----------------------------------------------------------------
// }
QWidget *w = dynamic_cast<QWidget *>(valueWidget);
if (w)
a_box->addWidget(w, a_box->rowCount() - 1, 1);
else
WARNING_LOG(m_logger) << "Internal error - LogViewWidget is not derived from QWidget... !?";
break;
}
// fall through for not read-only and dyn. array
Q_FALLTHROUGH();
case 0:
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::fillTelegram(LogViewTelegram *a_telegram)
{
INFO_LOG(m_logger) << "******************************************";
for (const auto ptr : std::as_const(m_EditInfoList))
{
if (!ptr->isValid())
{
INFO_LOG(m_logger) << ptr->field()->name() << " is invalid";
return; // abort when a value is not vaild
}
}
// now save the values
// -------------------
a_telegram->resetOffset();
a_telegram->clearJsonData();
for (auto ptr : std::as_const(m_EditInfoList))
{
if (!ptr->saveContent(a_telegram))
{
QMessageBox::warning(this, tr("Error while saving telegram"), tr("Found an invalid value - the telegram may be not saved correctly"));
}
}
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::saveTelegram()
{
fillTelegram(m_Telegram.data());
// save wait-time and name
N_SST::IntegerCalculator calculator;
N_SST::IntegerCalculator::E_Error error;
m_Telegram->setWaitTime(calculator.calc(m_WaitTimeEdit->text().toStdString(), error));
m_Telegram->setName(m_NameEdit->text());
accept();
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::sendCurrentTelegram()
{
emit sendTelegram(m_Telegram);
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::showButtons(QLayout *a_layout)
{
if (N_CoPrtCnv::CoPrtCnvLogHeader::e_DestProtocolCentral == m_Telegram->getProtocol())
{
QPushButton *btnSend = new QPushButton(QIcon(QLatin1String(":icons/16x16/mail-send.png")), tr("&Send"));
btnSend->setEnabled(true); // TODO: Status ob wirklich möglich ggf. überprüfen
connect(btnSend, &QPushButton::clicked, this, &LogViewTelegramDialog::sendCurrentTelegram);
a_layout->addWidget(btnSend);
}
if (m_ReadOnly)
{
// no field
a_box->addWidget(new QLabel(tr("Keine %1").arg(a_logViewField->cleanName())));
QPushButton *btnClose = new QPushButton(QIcon(QLatin1String(":icons/16x16/edit-delete.png")), tr("&Schliessen"));
connect(btnClose, &QPushButton::clicked, this, &LogViewTelegramDialog::reject);
a_layout->addWidget(btnClose);
}
else
{
QPushButton *btnClose = new QPushButton(QIcon(QLatin1String(":icons/16x16/edit-delete.png")), tr("&Abbrechen"));
connect(btnClose, &QPushButton::clicked, this, &LogViewTelegramDialog::reject);
a_layout->addWidget(btnClose);
QPushButton *btnOk = new QPushButton(QIcon(QLatin1String(":icons/16x16/dialog-ok-apply.png")), tr("&OK"));
btnOk->setDefault(true);
// fixme: absturz, wenn feld ungültiger wert enthält und ok gedrückt wird
connect(btnOk, &QPushButton::clicked, this, &LogViewTelegramDialog::saveTelegram);
a_layout->addWidget(btnOk);
}
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::showEditField(LogViewField *a_logViewField, QGridLayout *a_box)
{
// INFO_LOG(m_logger) << a_logViewField->getName() <<
// << " a_logViewField->getValueListSize()=" << a_logViewField->getValueListSize()
// << " a_logViewField->isIsDynamicArray()=" << a_logViewField->isIsDynamicArray()
// << " a_logViewField->getValue(0)=" << a_logViewField->getValue(0).toStdString()
// << " a_logViewField->getXdrElement())->getValueKind()=" << (int)(static_cast<const LogViewXdrStandardType*>(a_logViewField->getXdrElement())->getValueKind())
// ;
switch (a_logViewField->valueListSize())
{
case 1:
// 1 field (single or multi-line)
if (m_ReadOnly || !a_logViewField->isDynamicArray() ||
(LogViewXdrStandardType::e_Character == static_cast<const LogViewXdrStandardType *>(a_logViewField->xdrElement())->getValueKind()))
{
QLabel *label = new QLabel(a_logViewField->cleanName());
a_box->addWidget(label, a_box->rowCount(), 0);
LogViewWidget *valueWidget = nullptr;
//QString value = a_logViewField->getValue(0);
// if (-1 == value.indexOf("<br>") && value.length() < 80)
{
// single line
// -----------
if (LogViewXdrElement::e_KindEnum == a_logViewField->xdrElement()->getKind())
{
// enum => combobox
// ----------------
valueWidget = new LogViewEnumEdit(a_logViewField, this, m_ReadOnly, 0);
}
else
{
if (a_logViewField->isDateTimeField() || a_logViewField->isMSecsField())
{
// date-time-field
// ---------------
valueWidget = new LogViewDateTimeEdit(a_logViewField, this, m_ReadOnly);
}
else
{
switch (static_cast<const LogViewXdrStandardType *>(a_logViewField->xdrElement())->getValueKind())
{
case LogViewXdrStandardType::e_Boolean:
valueWidget = new LogViewBooleanEdit(a_logViewField, this, m_ReadOnly);
break;
case LogViewXdrStandardType::e_Signed:
case LogViewXdrStandardType::e_Unsigned:
case LogViewXdrStandardType::e_Float:
case LogViewXdrStandardType::e_Data:
valueWidget = new LogViewValueEdit(a_logViewField, this, m_ReadOnly);
break;
case LogViewXdrStandardType::e_Character: // Text
valueWidget = new LogViewTextEdit(a_logViewField, this, m_ReadOnly);
break;
}
}
}
if (valueWidget)
m_EditInfoList.push_back(valueWidget);
}
// else
// {
// // ----------------------------------------------------------------
// // fixme: not used => take away
// // multi-line
// valueWidget = new QTextEdit(value);
// static_cast<QTextEdit*>(valueWidget)->setReadOnly(true);
// // make proper width of widget
// QFontMetrics fm(valueWidget->font());
// // the 0 (at end) are here, because QFontMetrics does not understand the <code> and <b> tags.
// // So not the correct font will be used for calculating the width.
// // The solution here is suboptimal, but will hopefully work with a lot of fonts...
// valueWidget->setMinimumWidth(fm.width("0000: 00 00 00 00 00 00 00")*1.7);
// // ----------------------------------------------------------------
// }
QWidget *w = dynamic_cast<QWidget *>(valueWidget);
if (w)
a_box->addWidget(w, a_box->rowCount() - 1, 1);
else
WARNING_LOG(m_logger) << "Internal error - LogViewWidget is not derived from QWidget... !?";
break;
}
// fall through for not read-only and dyn. array
Q_FALLTHROUGH();
case 0:
if (m_ReadOnly)
{
// no field
a_box->addWidget(new QLabel(tr("Keine %1").arg(a_logViewField->cleanName())));
break;
}
// fall through for not read-only
Q_FALLTHROUGH();
default:
{
// show the title of table
QLabel *label = new QLabel(a_logViewField->cleanName());
a_box->addWidget(label, a_box->rowCount(), 0);
// show the spin-box for changing the dyn. array-size
LogViewSpinBox *spinBox = nullptr;
if (!m_ReadOnly && a_logViewField->isDynamicArray())
{
spinBox = new LogViewSpinBox(a_logViewField, this, a_logViewField->valueListSize());
a_box->addWidget(spinBox, a_box->rowCount() - 1, 1);
}
LogViewTableWidget *tableWidget = new LogViewTableWidget(a_logViewField, this, m_ReadOnly, m_logger);
m_EditInfoList.push_back(tableWidget);
a_box->addWidget(tableWidget, a_box->rowCount(), 0, 1, 2);
// connect signals
if (spinBox)
{
connect(spinBox, &LogViewSpinBox::valueEditingFinished, tableWidget, &LogViewTableWidget::changeSize);
}
}
break;
}
// fall through for not read-only
Q_FALLTHROUGH();
default:
{
// show the title of table
QLabel *label = new QLabel(a_logViewField->cleanName());
a_box->addWidget(label, a_box->rowCount(), 0);
}
// show the spin-box for changing the dyn. array-size
// ---------------------------------------------------------------
void LogViewTelegramDialog::showTab(LogViewField *a_logViewField, QGridLayout *a_box)
{
LogViewSpinBox *spinBox = nullptr;
if (!m_ReadOnly && a_logViewField->isDynamicArray())
{
spinBox = new LogViewSpinBox(a_logViewField, this, a_logViewField->valueListSize());
// show the spin-box for changing the dyn. array-size
QLabel *label = new QLabel(a_logViewField->cleanName());
a_box->addWidget(label, a_box->rowCount(), 0);
spinBox = new LogViewSpinBox(a_logViewField, this, 0);
a_box->addWidget(spinBox, a_box->rowCount() - 1, 1);
}
LogViewTableWidget *tableWidget = new LogViewTableWidget(a_logViewField, this, m_ReadOnly, m_logger);
m_EditInfoList.push_back(tableWidget);
a_box->addWidget(tableWidget, a_box->rowCount(), 0, 1, 2);
LogViewTabWidget *a_tabWidget = new LogViewTabWidget(a_logViewField, this, spinBox, m_logger);
m_EditInfoList.push_back(dynamic_cast<LogViewWidget *>(a_tabWidget));
a_box->addWidget(a_tabWidget, a_box->rowCount(), 0, 1, 2);
// connect signals
if (spinBox)
{
connect(spinBox, &LogViewSpinBox::valueEditingFinished,
tableWidget, &LogViewTableWidget::changeSize);
connect(spinBox, &LogViewSpinBox::valueEditingFinished, a_tabWidget, &LogViewTabWidget::changeSize);
}
}
break;
}
}
// ---------------------------------------------------------------
void LogViewTelegramDialog::showTab(LogViewField *a_logViewField, QGridLayout *a_box)
{
LogViewSpinBox *spinBox = nullptr;
if (!m_ReadOnly && a_logViewField->isDynamicArray())
{
// show the spin-box for changing the dyn. array-size
QLabel *label = new QLabel(a_logViewField->cleanName());
a_box->addWidget(label, a_box->rowCount(), 0);
spinBox = new LogViewSpinBox(a_logViewField, this, 0);
a_box->addWidget(spinBox, a_box->rowCount() - 1, 1);
}
LogViewTabWidget *a_tabWidget = new LogViewTabWidget(a_logViewField, this, spinBox, m_logger);
m_EditInfoList.push_back(dynamic_cast<LogViewWidget *>(a_tabWidget));
a_box->addWidget(a_tabWidget, a_box->rowCount(), 0, 1, 2);
// connect signals
if (spinBox)
{
connect(spinBox, &LogViewSpinBox::valueEditingFinished,
a_tabWidget, &LogViewTabWidget::changeSize);
}
// add the tab
if (a_logViewField->hasContent())
{
for (int i = 0; i < a_logViewField->childCount(); ++i)
a_tabWidget->addTab(a_logViewField, false, i);
}
}
// ---------------------------------------------------------------
bool LogViewTelegramDialog::removeItemsFromEditInfoList(const QStringList &jsonPath)
{
if (m_EditInfoList.empty())
return false;
for (int i = m_EditInfoList.size() - 1; i >= 0; --i)
{
LogViewWidget *lvw = m_EditInfoList.at(i);
const QStringList jsonPathChild = lvw->field()->jsonPath();
if (jsonPathChild.size() < jsonPath.size())
continue;
bool bIsChild = true;
for (int j = 0; j < jsonPath.size(); ++j)
// add the tab
if (a_logViewField->hasContent())
{
if (jsonPath.at(j) != jsonPathChild.at(j))
{
bIsChild = false;
break;
}
for (int i = 0; i < a_logViewField->childCount(); ++i)
a_tabWidget->addTab(a_logViewField, false, i);
}
if (!bIsChild)
continue;
delete m_EditInfoList.at(i);
m_EditInfoList.removeAt(i);
}
m_EditInfoList.resize(m_EditInfoList.size() - 1);
return true;
}
// ---------------------------------------------------------------
bool LogViewTelegramDialog::removeItemsFromEditInfoList(const QStringList &jsonPath)
{
if (m_EditInfoList.empty())
return false;
for (int i = m_EditInfoList.size() - 1; i >= 0; --i)
{
LogViewWidget *lvw = m_EditInfoList.at(i);
const QStringList jsonPathChild = lvw->field()->jsonPath();
if (jsonPathChild.size() < jsonPath.size())
continue;
bool bIsChild = true;
for (int j = 0; j < jsonPath.size(); ++j)
{
if (jsonPath.at(j) != jsonPathChild.at(j))
{
bIsChild = false;
break;
}
}
if (!bIsChild)
continue;
delete m_EditInfoList.at(i);
m_EditInfoList.removeAt(i);
}
m_EditInfoList.resize(m_EditInfoList.size() - 1);
return true;
}
} // namespace N_LogView
@@ -25,55 +25,54 @@ class QLineEdit;
namespace N_LogView
{
class LogViewWidget;
class LogViewTelegram;
class LogViewField;
class LogViewWidget;
class LogViewTelegram;
class LogViewField;
/**
/**
* @author alois.wismer
* @version 1.0
* @created 09-Feb-2010 15:05:05
*/
class LogViewTelegramDialog : public QDialog
{
Q_OBJECT
public:
explicit LogViewTelegramDialog(QWidget *a_parent = nullptr, const bool a_readonly = true, NGL::INGLLogger& logger = N_LogView::getLogger("LogViewTelegramDialog"));
class LogViewTelegramDialog : public QDialog
{
Q_OBJECT
public:
explicit LogViewTelegramDialog(QWidget *a_parent = nullptr, const bool a_readonly = true, NGL::INGLLogger &logger = N_LogView::getLogger("LogViewTelegramDialog"));
void showDialog(const QSharedPointer<LogViewTelegram> &a_telegram);
void showDataDump(const QSharedPointer<LogViewTelegram> &a_telegram, bool showErrorMessage);
void makePretty();
void showTree(LogViewField *a_fieldTree, QGridLayout *a_box);
void showDialog(const QSharedPointer<LogViewTelegram> &a_telegram);
void showDataDump(const QSharedPointer<LogViewTelegram> &a_telegram, bool showErrorMessage);
void makePretty();
void showTree(LogViewField *a_fieldTree, QGridLayout *a_box);
/**
/**
* Removes the elements from m_EditInfoList matching the path
*/
bool removeItemsFromEditInfoList(const QStringList &jsonPath);
bool removeItemsFromEditInfoList(const QStringList &jsonPath);
Q_SIGNALS:
void sendTelegram(const QSharedPointer<LogViewTelegram> &telegramToSend);
protected slots:
void saveTelegram();
Q_SIGNALS:
void sendTelegram(const QSharedPointer<LogViewTelegram> &telegramToSend);
protected slots:
void saveTelegram();
void sendCurrentTelegram();
void sendCurrentTelegram();
protected:
protected:
void fillTelegram(LogViewTelegram *a_telegram);
void showButtons(QLayout *a_layout);
void showEditField(LogViewField *a_logViewField, QGridLayout *a_box);
void showTab(LogViewField *a_logViewField, QGridLayout *a_box);
void fillTelegram(LogViewTelegram *a_telegram);
void showButtons(QLayout *a_layout);
void showEditField(LogViewField *a_logViewField, QGridLayout *a_box);
void showTab(LogViewField *a_logViewField, QGridLayout *a_box);
private:
QSharedPointer<LogViewTelegram> m_Telegram;
QVector<LogViewWidget *> m_EditInfoList;
QScopedPointer<LogViewField> m_fieldTree;
QWidget *m_contentsWidget = nullptr;
QScrollArea *m_ScrollArea = nullptr;
QLineEdit *m_NameEdit = nullptr;
QLineEdit *m_WaitTimeEdit = nullptr;
bool m_ReadOnly = false;
NGL::INGLLogger& m_logger;
};
private:
QSharedPointer<LogViewTelegram> m_Telegram;
QVector<LogViewWidget *> m_EditInfoList;
QScopedPointer<LogViewField> m_fieldTree;
QWidget *m_contentsWidget = nullptr;
QScrollArea *m_ScrollArea = nullptr;
QLineEdit *m_NameEdit = nullptr;
QLineEdit *m_WaitTimeEdit = nullptr;
bool m_ReadOnly = false;
NGL::INGLLogger &m_logger;
};
}
File diff suppressed because it is too large. Load diff
@@ -17,110 +17,110 @@ class QTableView;
namespace N_LogView
{
class LogViewInjectionThread;
class TelegramEditModel;
class LogViewInjectionThread;
class TelegramEditModel;
class TelegramEdit :public QObject
{
Q_OBJECT
public:
explicit TelegramEdit(QWidget *parent = nullptr);
class TelegramEdit : public QObject
{
Q_OBJECT
public:
explicit TelegramEdit(QWidget *parent = nullptr);
QTableView *tableView() { return m_tableView; }
QTableView *tableView() { return m_tableView; }
void appendTelegram(const QSharedPointer<LogViewTelegram> &telegram);
void appendTelegram(const QSharedPointer<LogViewTelegram> &telegram);
void setInjectionThread(LogViewInjectionThread* a_injectionThread);
void setInjectionThread(LogViewInjectionThread *a_injectionThread);
bool isInjectionPossible() const;
bool isInjectionPossible() const;
protected:
QSharedPointer<LogViewTelegram> m_copyTelegram;
protected:
QSharedPointer<LogViewTelegram> m_copyTelegram;
QSharedPointer<LogViewTelegram> currentSelectedTelegram() const;
QSharedPointer<LogViewTelegram> currentSelectedTelegram() const;
QModelIndex currentSelectedIndex() const;
QModelIndex currentSelectedIndex() const;
QSharedPointer<LogViewTelegram> telegramAtRow(int row);
QSharedPointer<LogViewTelegram> telegramAtRow(int row);
void loadTelegramList(bool checkAppend);
void loadTelegramList(bool checkAppend);
protected:
QAction *m_addTeleAction;
QAction *m_editTeleAction;
QAction *m_copyTeleAction;
QAction *m_pasteTeleAction;
QAction *m_deleteTeleAction;
QAction *m_moveTeleUpAction;
QAction *m_moveTeleDownAction;
QAction *m_teleListLoad;
QAction *m_teleListAppend;
QAction *m_teleListSave;
QTableView *m_tableView;
bool m_DoLoop;
protected:
QAction *m_addTeleAction;
QAction *m_editTeleAction;
QAction *m_copyTeleAction;
QAction *m_pasteTeleAction;
QAction *m_deleteTeleAction;
QAction *m_moveTeleUpAction;
QAction *m_moveTeleDownAction;
QAction *m_teleListLoad;
QAction *m_teleListAppend;
QAction *m_teleListSave;
QTableView *m_tableView;
bool m_DoLoop;
LogViewInjectionThread *m_InjectionThread;
LogViewInjectionThread *m_InjectionThread;
int m_currentRowToSend;
int m_currentRowToSend;
int m_curEditTelegramRow;
int m_curEditTelegramRow;
TelegramEditModel *m_EditModel;
TelegramEditModel *m_EditModel;
NGL::INGLLogger &m_logger;
static QString s_DIR();
static QString s_EDIT_TELEGRAM_GROUP();
static QString s_TELEGRAMLIST_FILE_ID();
static QString s_TELEGRAMLIST_FILES();
NGL::INGLLogger &m_logger;
static QString s_DIR();
static QString s_EDIT_TELEGRAM_GROUP();
static QString s_TELEGRAMLIST_FILE_ID();
static QString s_TELEGRAMLIST_FILES();
protected Q_SLOTS:
protected Q_SLOTS:
void addTelegram();
void addTelegram();
void injectTelegram(bool a_bAsCentralTelegram);
void injectTelegram(bool a_bAsCentralTelegram);
void injectTelegram(const QSharedPointer<LogViewTelegram> &a_telegram, bool a_bAsCentralTelegram);
void injectTelegram(const QSharedPointer<LogViewTelegram> &a_telegram, bool a_bAsCentralTelegram);
void sendTelegram(const QSharedPointer<LogViewTelegram> &a_telegram);
void sendTelegram(const QSharedPointer<LogViewTelegram> &a_telegram);
void sendCurrentTelegram();
void sendCurrentTelegram();
void tableViewCustomContextMenu(const QPoint &pos);
void tableViewCustomContextMenu(const QPoint &pos);
void editTelegram();
void editTelegram();
void showTelegram();
void showTelegram();
void deleteTelegram();
void deleteTelegram();
void injectCentralTelegram();
void injectCentralTelegram();
void injectTetraTelegram();
void injectTetraTelegram();
void loopTelegrams();
void loopTelegrams();
void loopNextTelegram();
void loopNextTelegram();
void sequenceTelegrams();
void sequenceTelegrams();
void sequenceNextTelegram();
void sequenceNextTelegram();
void copy();
void copy();
void paste();
void paste();
void moveUp();
void moveUp();
void moveDown();
void moveDown();
void saveTelegramList();
void saveTelegramList();
void loadTelegramListAppend();
void loadTelegramListAppend();
void loadTelegramListReplace();
void loadTelegramListReplace();
void editTelegramDialogFinished();
void editTelegramDialogFinished();
void onSelectionChanged();
};
void onSelectionChanged();
};
}
@@ -12,157 +12,155 @@
namespace N_LogView
{
// ---------------------------------------------------------------
int TelegramEditModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_telegrams.size();
}
// ---------------------------------------------------------------
int TelegramEditModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : 3;
}
// ---------------------------------------------------------------
QVariant TelegramEditModel::data(const QModelIndex &index, int role) const
{
if (index.isValid() && index.row() < m_telegrams.size())
// ---------------------------------------------------------------
int TelegramEditModel::rowCount(const QModelIndex &parent) const
{
if (role == Qt::DisplayRole)
return parent.isValid() ? 0 : m_telegrams.size();
}
// ---------------------------------------------------------------
int TelegramEditModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : 3;
}
// ---------------------------------------------------------------
QVariant TelegramEditModel::data(const QModelIndex &index, int role) const
{
if (index.isValid() && index.row() < m_telegrams.size())
{
const QSharedPointer<LogViewTelegram> telegram = m_telegrams.at(index.row());
switch (index.column())
if (role == Qt::DisplayRole)
{
case 0:
return telegram->getName();
case 1:
return telegram->getParticipantId();
case 2:
return telegram->getWaitTime();
const QSharedPointer<LogViewTelegram> telegram = m_telegrams.at(index.row());
switch (index.column())
{
case 0:
return telegram->getName();
case 1:
return telegram->getParticipantId();
case 2:
return telegram->getWaitTime();
}
}
else if (role == Qt::ToolTipRole)
{
const QSharedPointer<LogViewTelegram> telegram = m_telegrams.at(index.row());
if (telegram->isJsonTelegram())
return telegram->getData(QJsonDocument::JsonFormat::Indented);
}
}
else if (role == Qt::ToolTipRole)
return QVariant();
}
// ---------------------------------------------------------------
QVariant TelegramEditModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
const QSharedPointer<LogViewTelegram> telegram = m_telegrams.at(index.row());
if (telegram->isJsonTelegram())
return telegram->getData(QJsonDocument::JsonFormat::Indented);
switch (section)
{
case 0:
return tr("Description");
case 1:
return tr("Equip. No.");
case 2:
return tr("Wait Time");
default:
break;
}
}
return QAbstractTableModel::headerData(section, orientation, role);
}
// ---------------------------------------------------------------
void TelegramEditModel::clearTelegrams()
{
beginResetModel();
m_telegrams.clear();
endResetModel();
}
// ---------------------------------------------------------------
void TelegramEditModel::appendTelegrams(const QVector<QSharedPointer<LogViewTelegram>> &telegrams)
{
if (telegrams.isEmpty())
return;
beginInsertRows(QModelIndex(), m_telegrams.size(), m_telegrams.size() + telegrams.size() - 1);
m_telegrams += telegrams;
endInsertRows();
}
// ---------------------------------------------------------------
int TelegramEditModel::appendTelegram(const QSharedPointer<LogViewTelegram> &telegram)
{
beginInsertRows(QModelIndex(), m_telegrams.size(), m_telegrams.size());
m_telegrams.push_back(telegram);
telegram->rebuildJsonString();
endInsertRows();
return m_telegrams.size() - 1; // row
}
// ---------------------------------------------------------------
QSharedPointer<LogViewTelegram> TelegramEditModel::telegram(int row) const
{
if (row >= 0 && row < m_telegrams.size())
return m_telegrams.at(row);
return QSharedPointer<LogViewTelegram>();
}
// ---------------------------------------------------------------
bool TelegramEditModel::moveUp(int row)
{
if (row <= 0 || row >= m_telegrams.size())
return false;
beginMoveRows(QModelIndex(), row, row, QModelIndex(), row - 1);
std::swap(m_telegrams[row], m_telegrams[row - 1]);
endMoveRows();
return true;
}
// ---------------------------------------------------------------
bool TelegramEditModel::moveDown(int row)
{
if (row >= (m_telegrams.size() - 1))
return false;
beginMoveRows(QModelIndex(), row, row, QModelIndex(), row + 1);
std::swap(m_telegrams[row], m_telegrams[row + 1]);
endMoveRows();
return true;
}
// ---------------------------------------------------------------
void TelegramEditModel::emitDataChanged(int row)
{
QModelIndex top = createIndex(row, 0);
QModelIndex bottom = createIndex(row, columnCount() - 1);
emit dataChanged(top, bottom, {Qt::DisplayRole, Qt::ToolTipRole});
}
// ---------------------------------------------------------------
void TelegramEditModel::removeTelegrams(const QSet<int> &rows)
{
QList<int> rowList = rows.values();
std::sort(rowList.begin(), rowList.end());
// von oben her löschen um ein Verschieben der Indizes zu vermeiden
for (int i = rowList.size() - 1; i >= 0; --i)
{
int row = rowList.at(i);
beginRemoveRows(QModelIndex(), row, row);
m_telegrams.remove(row);
endRemoveRows();
}
}
return QVariant();
}
// ---------------------------------------------------------------
QVariant TelegramEditModel::headerData(int section,
Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
// ---------------------------------------------------------------
void TelegramEditModel::pasteRows(int row, const QSharedPointer<LogViewTelegram> &tele)
{
switch (section)
{
case 0:
return tr("Description");
case 1:
return tr("Equip. No.");
case 2:
return tr("Wait Time");
default:
break;
}
if (row < 0 || row > m_telegrams.size())
return;
beginInsertRows(QModelIndex(), row, row);
m_telegrams.insert(row, QSharedPointer<LogViewTelegram>(new LogViewTelegram(*tele.data())));
endInsertRows();
}
return QAbstractTableModel::headerData(section, orientation, role);
}
// ---------------------------------------------------------------
void TelegramEditModel::clearTelegrams()
{
beginResetModel();
m_telegrams.clear();
endResetModel();
}
// ---------------------------------------------------------------
void TelegramEditModel::appendTelegrams(const QVector<QSharedPointer<LogViewTelegram> > &telegrams)
{
if (telegrams.isEmpty())
return;
beginInsertRows(QModelIndex(), m_telegrams.size(), m_telegrams.size() + telegrams.size() - 1);
m_telegrams += telegrams;
endInsertRows();
}
// ---------------------------------------------------------------
int TelegramEditModel::appendTelegram(const QSharedPointer<LogViewTelegram> &telegram)
{
beginInsertRows(QModelIndex(), m_telegrams.size(), m_telegrams.size());
m_telegrams.push_back(telegram);
telegram->rebuildJsonString();
endInsertRows();
return m_telegrams.size() - 1; // row
}
// ---------------------------------------------------------------
QSharedPointer<LogViewTelegram> TelegramEditModel::telegram(int row) const
{
if (row >= 0 && row < m_telegrams.size())
return m_telegrams.at(row);
return QSharedPointer<LogViewTelegram>();
}
// ---------------------------------------------------------------
bool TelegramEditModel::moveUp(int row)
{
if (row <= 0 || row >= m_telegrams.size())
return false;
beginMoveRows(QModelIndex(), row, row, QModelIndex(), row - 1);
std::swap(m_telegrams[row], m_telegrams[row - 1]);
endMoveRows();
return true;
}
// ---------------------------------------------------------------
bool TelegramEditModel::moveDown(int row)
{
if (row >= (m_telegrams.size() - 1))
return false;
beginMoveRows(QModelIndex(), row, row, QModelIndex(), row + 1);
std::swap(m_telegrams[row], m_telegrams[row + 1]);
endMoveRows();
return true;
}
// ---------------------------------------------------------------
void TelegramEditModel::emitDataChanged(int row)
{
QModelIndex top = createIndex(row, 0);
QModelIndex bottom = createIndex(row, columnCount() - 1);
emit dataChanged(top, bottom, {Qt::DisplayRole, Qt::ToolTipRole});
}
// ---------------------------------------------------------------
void TelegramEditModel::removeTelegrams(const QSet<int> &rows)
{
QList<int> rowList = rows.values();
std::sort(rowList.begin(), rowList.end());
// von oben her löschen um ein Verschieben der Indizes zu vermeiden
for (int i = rowList.size() - 1 ; i >= 0; --i)
{
int row = rowList.at(i);
beginRemoveRows(QModelIndex(), row, row);
m_telegrams.remove(row);
endRemoveRows();
}
}
// ---------------------------------------------------------------
void TelegramEditModel::pasteRows(int row, const QSharedPointer<LogViewTelegram> &tele)
{
if (row < 0 || row > m_telegrams.size())
return;
beginInsertRows(QModelIndex(), row, row);
m_telegrams.insert(row, QSharedPointer<LogViewTelegram>(new LogViewTelegram(*tele.data())));
endInsertRows();
}
} // namespace N_LogView
@@ -15,35 +15,34 @@
namespace N_LogView
{
class TelegramEditModel final : public QAbstractTableModel
{
Q_OBJECT
public:
using QAbstractTableModel::QAbstractTableModel;
class TelegramEditModel final : public QAbstractTableModel
{
Q_OBJECT
public:
using QAbstractTableModel::QAbstractTableModel;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
void clearTelegrams();
void appendTelegrams(const QVector<QSharedPointer<LogViewTelegram> > &telegrams);
int appendTelegram(const QSharedPointer<LogViewTelegram> &telegram);
QSharedPointer<LogViewTelegram> telegram(int row) const;
void clearTelegrams();
void appendTelegrams(const QVector<QSharedPointer<LogViewTelegram>> &telegrams);
int appendTelegram(const QSharedPointer<LogViewTelegram> &telegram);
QSharedPointer<LogViewTelegram> telegram(int row) const;
bool moveUp(int row);
bool moveDown(int row);
bool moveUp(int row);
bool moveDown(int row);
void emitDataChanged(int row);
void emitDataChanged(int row);
void removeTelegrams(const QSet<int> &rows);
void removeTelegrams(const QSet<int> &rows);
void pasteRows(int row, const QSharedPointer<LogViewTelegram> &tele);
protected:
QVector<QSharedPointer<LogViewTelegram> > m_telegrams;
void pasteRows(int row, const QSharedPointer<LogViewTelegram> &tele);
};
protected:
QVector<QSharedPointer<LogViewTelegram>> m_telegrams;
};
}
@@ -1,16 +1,16 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
#include "LogViewTelegramSelectionDialog.hpp"
#include <QtWidgets/QLabel>
#include <QtWidgets/QListWidget>
@@ -22,41 +22,40 @@
namespace N_LogView
{
static int s_currentRow = 0;
// ---------------------------------------------------------------
LogViewTelegramSelectionDialog::LogViewTelegramSelectionDialog(QWidget* a_parent)
: QDialog(a_parent)
{
setMinimumSize(QSize(600, 500));
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(new QLabel(tr("Select a telegram:")));
m_TelegramList = new QListWidget(this);
const auto telegramMap = LogViewTelegram::jsonParser()->telegramsToCreate();
for (auto it = telegramMap.cbegin(); it != telegramMap.cend(); ++it)
static int s_currentRow = 0;
// ---------------------------------------------------------------
LogViewTelegramSelectionDialog::LogViewTelegramSelectionDialog(QWidget *a_parent)
: QDialog(a_parent)
{
if (it.key() == 0) // ACK
continue;
auto lwi = new QListWidgetItem(it.value() + QStringLiteral(" (%1)").arg(it.key()));
lwi->setData(Qt::UserRole, it.key());
m_TelegramList->addItem(lwi);
setMinimumSize(QSize(600, 500));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(new QLabel(tr("Select a telegram:")));
m_TelegramList = new QListWidget(this);
const auto telegramMap = LogViewTelegram::jsonParser()->telegramsToCreate();
for (auto it = telegramMap.cbegin(); it != telegramMap.cend(); ++it)
{
if (it.key() == 0) // ACK
continue;
auto lwi = new QListWidgetItem(it.value() + QStringLiteral(" (%1)").arg(it.key()));
lwi->setData(Qt::UserRole, it.key());
m_TelegramList->addItem(lwi);
}
m_TelegramList->sortItems();
m_TelegramList->setCurrentRow(s_currentRow);
connect(m_TelegramList, &QListWidget::itemActivated, this, &LogViewTelegramSelectionDialog::selectTelegram);
layout->addWidget(m_TelegramList);
setLayout(layout);
}
m_TelegramList->sortItems();
m_TelegramList->setCurrentRow(s_currentRow);
connect(m_TelegramList, &QListWidget::itemActivated,
this, &LogViewTelegramSelectionDialog::selectTelegram);
layout->addWidget(m_TelegramList);
setLayout(layout);
}
// ---------------------------------------------------------------
void LogViewTelegramSelectionDialog::selectTelegram(QListWidgetItem* a_telegramItem)
{
s_currentRow = m_TelegramList->currentRow();
m_SelectedTelegramId = a_telegramItem->data(Qt::UserRole).toInt();
accept();
}
// ---------------------------------------------------------------
void LogViewTelegramSelectionDialog::selectTelegram(QListWidgetItem *a_telegramItem)
{
s_currentRow = m_TelegramList->currentRow();
m_SelectedTelegramId = a_telegramItem->data(Qt::UserRole).toInt();
accept();
}
} // namespace N_LogView
@@ -32,7 +32,7 @@ namespace N_LogView
*
* @param a_parent
*/
explicit LogViewTelegramSelectionDialog(QWidget* a_parent);
explicit LogViewTelegramSelectionDialog(QWidget *a_parent);
int getSelectedTelegramId() const { return m_SelectedTelegramId; }
@@ -42,12 +42,11 @@ namespace N_LogView
*
* @param a_telegramItem
*/
void selectTelegram(QListWidgetItem* a_telegramItem);
void selectTelegram(QListWidgetItem *a_telegramItem);
protected:
QListWidget *m_TelegramList;
int m_SelectedTelegramId;
};
};
}
@@ -16,528 +16,518 @@
namespace N_LogView
{
LogViewTetraTelegramsParser::LogViewTetraTelegramsParser()
: m_logger(getLogger("LogViewTetraTelegramsParser"))
{
insertPod(QStringLiteral("bool"), 1, true, true, true);
insertPod(QStringLiteral("int"), 4, true, true);
insertPod(QStringLiteral("int32_t"), 4, true, true);
insertPod(QStringLiteral("qint64"), 8, true, true);
insertPod(QStringLiteral("float"), 4, true, false);
insertPod(QStringLiteral("double"), 8, true, false);
}
EnumInformation LogViewTetraTelegramsParser::enumFromType(const QString &type) const
{
for (const auto &ei : m_enums)
LogViewTetraTelegramsParser::LogViewTetraTelegramsParser()
: m_logger(getLogger("LogViewTetraTelegramsParser"))
{
const QString fqType = ei.ns.isEmpty() ? ei.type : (ei.ns + QStringLiteral("::") + ei.type);
if (fqType == type)
return ei;
insertPod(QStringLiteral("bool"), 1, true, true, true);
insertPod(QStringLiteral("int"), 4, true, true);
insertPod(QStringLiteral("int32_t"), 4, true, true);
insertPod(QStringLiteral("qint64"), 8, true, true);
insertPod(QStringLiteral("float"), 4, true, false);
insertPod(QStringLiteral("double"), 8, true, false);
}
return EnumInformation();
}
StructInformation LogViewTetraTelegramsParser::structFromType(const QString &type) const
{
return m_structs.value(type);
}
PodInformation LogViewTetraTelegramsParser::podFromType(const QString &type) const
{
return m_pods.value(type);
}
bool LogViewTetraTelegramsParser::isEnum(const QString &type) const
{
for (const auto &ei : m_enums)
if (ei.type == type)
return true;
return false;
}
bool LogViewTetraTelegramsParser::isStruct(const QString &type) const
{
return m_structs.contains(type);
}
bool LogViewTetraTelegramsParser::isPod(const QString &type) const
{
return m_pods.contains(type);
}
static void fillBasemembers(StructInformation &si, const QHash<QString, StructInformation> &structs)
{
if (si.baseStruct.isEmpty())
return;
StructInformation base = structs.value(si.baseStruct);
fillBasemembers(base, structs);
si.member = (base.member + si.member); // base first
}
bool LogViewTetraTelegramsParser::parse(const QString &filename)
{
m_telegramIdEnum = EnumInformation();
m_enums.clear();
m_structs.clear();
//m_pods.clear(); // only set once
m_visibleTelegrams.clear();
QFile f(filename);
if (!f.open(QIODevice::ReadOnly))
EnumInformation LogViewTetraTelegramsParser::enumFromType(const QString &type) const
{
WARNING_LOG(m_logger) << "Can not open file " << filename << " for reading: " << f.errorString();
for (const auto &ei : m_enums)
{
const QString fqType = ei.ns.isEmpty() ? ei.type : (ei.ns + QStringLiteral("::") + ei.type);
if (fqType == type)
return ei;
}
return EnumInformation();
}
StructInformation LogViewTetraTelegramsParser::structFromType(const QString &type) const
{
return m_structs.value(type);
}
PodInformation LogViewTetraTelegramsParser::podFromType(const QString &type) const
{
return m_pods.value(type);
}
bool LogViewTetraTelegramsParser::isEnum(const QString &type) const
{
for (const auto &ei : m_enums)
if (ei.type == type)
return true;
return false;
}
const QString content = QString::fromUtf8(f.readAll());
f.close();
const QStringList linesList = content.split(QLatin1Char('\n'));
QVector<QStringView> lines;
lines.reserve(linesList.size());
for (const QString &line : linesList)
lines += line;
QVector<QStringView> linesTrimmed;
linesTrimmed.reserve(lines.size());
for (const QStringView &line : lines)
linesTrimmed += line.trimmed();
int i = 0;
while (i < linesTrimmed.size())
bool LogViewTetraTelegramsParser::isStruct(const QString &type) const
{
const QStringView &line = linesTrimmed.at(i);
if (line.startsWith(QLatin1String("struct")))
{
i = parseStruct(linesTrimmed, i);
if (i < 0)
return false;
}
else if (line.startsWith(QLatin1String("enum")))
{
i = parseEnum(linesTrimmed, i, QString());
if (i < 0)
return false;
}
else if (line.startsWith(QLatin1String("template <> struct Constraints")))
{
i = parseConstraint(linesTrimmed, i);
if (i < 0)
return false;
}
++i;
return m_structs.contains(type);
}
const auto completeStructs = m_structs;
for (StructInformation &si : m_structs)
fillBasemembers(si, completeStructs);
return true;
}
void LogViewTetraTelegramsParser::insertPod(const QString &type, int byteLen, bool isSigned, bool isIntegral, bool isBoolean)
{
PodInformation pod;
pod.type = type;
pod.byteLen = byteLen;
pod.isBoolean = isBoolean;
pod.isIntegral = isIntegral;
pod.isSigned = isSigned;
m_pods[type] = pod;
}
int LogViewTetraTelegramsParser::parseStruct(const QVector<QStringView> &lines, int iStartPos)
{
const QVector<QStringView> tokens = tokenize(lines.at(iStartPos));
if (tokens.size() < 2)
return -1;
const QStringView &structType = tokens.at(1);
if (structType.endsWith(QLatin1Char(';')))
return iStartPos;
StructInformation si;
si.type = structType.toString();
if (tokens.size() > 2)
bool LogViewTetraTelegramsParser::isPod(const QString &type) const
{
if (tokens.at(2) != QLatin1String(":"))
return m_pods.contains(type);
}
static void fillBasemembers(StructInformation &si, const QHash<QString, StructInformation> &structs)
{
if (si.baseStruct.isEmpty())
return;
StructInformation base = structs.value(si.baseStruct);
fillBasemembers(base, structs);
si.member = (base.member + si.member); // base first
}
bool LogViewTetraTelegramsParser::parse(const QString &filename)
{
m_telegramIdEnum = EnumInformation();
m_enums.clear();
m_structs.clear();
//m_pods.clear(); // only set once
m_visibleTelegrams.clear();
QFile f(filename);
if (!f.open(QIODevice::ReadOnly))
{
WARNING_LOG(m_logger) << "Could not parse struct: '" << lines.at(iStartPos).toString() << "', line: " << iStartPos + 1;
return -1;
WARNING_LOG(m_logger) << "Can not open file " << filename << " for reading: " << f.errorString();
return false;
}
for (int i = 3; i < tokens.size(); ++i)
const QString content = QString::fromUtf8(f.readAll());
f.close();
const QStringList linesList = content.split(QLatin1Char('\n'));
QVector<QStringView> lines;
lines.reserve(linesList.size());
for (const QString &line : linesList)
lines += line;
QVector<QStringView> linesTrimmed;
linesTrimmed.reserve(lines.size());
for (const QStringView &line : lines)
linesTrimmed += line.trimmed();
int i = 0;
while (i < linesTrimmed.size())
{
if (!si.baseStruct.isEmpty())
const QStringView &line = linesTrimmed.at(i);
if (line.startsWith(QLatin1String("struct")))
{
i = parseStruct(linesTrimmed, i);
if (i < 0)
return false;
}
else if (line.startsWith(QLatin1String("enum")))
{
i = parseEnum(linesTrimmed, i, QString());
if (i < 0)
return false;
}
else if (line.startsWith(QLatin1String("template <> struct Constraints")))
{
i = parseConstraint(linesTrimmed, i);
if (i < 0)
return false;
}
++i;
}
const auto completeStructs = m_structs;
for (StructInformation &si : m_structs)
fillBasemembers(si, completeStructs);
return true;
}
void LogViewTetraTelegramsParser::insertPod(const QString &type, int byteLen, bool isSigned, bool isIntegral, bool isBoolean)
{
PodInformation pod;
pod.type = type;
pod.byteLen = byteLen;
pod.isBoolean = isBoolean;
pod.isIntegral = isIntegral;
pod.isSigned = isSigned;
m_pods[type] = pod;
}
int LogViewTetraTelegramsParser::parseStruct(const QVector<QStringView> &lines, int iStartPos)
{
const QVector<QStringView> tokens = tokenize(lines.at(iStartPos));
if (tokens.size() < 2)
return -1;
const QStringView &structType = tokens.at(1);
if (structType.endsWith(QLatin1Char(';')))
return iStartPos;
StructInformation si;
si.type = structType.toString();
if (tokens.size() > 2)
{
if (tokens.at(2) != QLatin1String(":"))
{
WARNING_LOG(m_logger) << "Could not parse struct: '" << lines.at(iStartPos).toString() << "', line: " << iStartPos + 1;
return -1;
}
QStringView base = tokens.at(i);
if (base == QLatin1String("public") ||
base == QLatin1String("protected") ||
base == QLatin1String("private"))
continue;
if (base.endsWith(QLatin1Char(',')))
base.chop(1);
if (base.endsWith(QLatin1Char('>'))) // helper template - ignore
for (int i = 3; i < tokens.size(); ++i)
{
si.isVisible = true;
if (!si.baseStruct.isEmpty())
{
WARNING_LOG(m_logger) << "Could not parse struct: '" << lines.at(iStartPos).toString() << "', line: " << iStartPos + 1;
return -1;
}
QStringView base = tokens.at(i);
if (base == QLatin1String("public") || base == QLatin1String("protected") || base == QLatin1String("private"))
continue;
if (base.endsWith(QLatin1Char(',')))
base.chop(1);
if (base.endsWith(QLatin1Char('>'))) // helper template - ignore
{
si.isVisible = true;
continue;
}
si.baseStruct = tokens.at(i).toString();
}
}
int i = iStartPos + 1;
while (i < lines.size())
{
const QVector<QStringView> tokens = tokenize(lines.at(i));
if (!validStructTokens(tokens))
{
++i;
continue;
}
si.baseStruct = tokens.at(i).toString();
if (tokens.at(0) == QLatin1String("};"))
break;
if (tokens.at(0) == QLatin1String("enum"))
{
i = parseEnum(lines, i, si.type, &si);
if (i < 0)
return -1;
++i;
continue;
}
MemberInformation mi;
if (tokens.size() > 2)
{
const int parserCommentPos = tokens.at(2) == QLatin1String("=") ? 4 : 2;
if (tokens.size() > parserCommentPos)
{
const QStringView &comment = tokens.at(parserCommentPos);
DEBUG_LOG(m_logger) << "comment: " << comment.toString();
if (comment.startsWith(QLatin1String("//@array: ")))
{
const QStringView hint = comment.mid(QLatin1String("//@array: ").size());
QString structStr = QLatin1String("struct ") + si.type + QLatin1String("::") + tokens.at(0).toString() + QLatin1Char('\n') + hint.toString();
structStr.replace(QLatin1Char(';'), QLatin1String(";\n"));
DEBUG_LOG(m_logger) << "structStr: " << structStr;
const QStringList structLines = structStr.split(QLatin1Char('\n'));
QVector<QStringView> structLinesView;
structLinesView.reserve(structLines.size());
for (const QString &line : structLines)
structLinesView += line;
parseStruct(structLinesView, 0);
mi.type = si.type + QLatin1String("::") + tokens.at(0).toString();
mi.isArray = true;
}
if (comment == QLatin1String("//@invisible"))
mi.isVisible = false;
}
}
QStringView name = tokens.at(1);
if (name.endsWith(QLatin1Char(';')))
name.chop(1);
if (mi.type.isEmpty())
mi.type += tokens.at(0).toString();
categorizeMember(mi);
mi.name = name.toString();
if (mi.isEnum && !mi.type.contains(QLatin1String("::")))
{
for (const auto &ei : std::as_const(m_enums))
{
if (ei.type == mi.type)
{
if (!ei.ns.isEmpty())
mi.type = ei.ns + QLatin1String("::") + mi.type;
break;
}
}
}
si.member.push_back(std::move(mi));
++i;
}
if (m_logger.isDebugEnabled())
{
if (si.baseStruct.isEmpty())
DEBUG_LOG(m_logger) << "Found Struct: " << si.type;
else
DEBUG_LOG(m_logger) << "Found Struct: " << si.type << ", base: " << si.baseStruct;
for (int j = 0; j < si.member.size(); ++j)
{
const MemberInformation &mi = si.member.at(j);
DEBUG_LOG(m_logger) << "Member[" << j << "]: " << mi.type << " - " << mi.name;
}
}
m_structs[si.type] = si;
return i;
}
int i = iStartPos + 1;
while (i < lines.size())
int LogViewTetraTelegramsParser::parseEnum(const QVector<QStringView> &lines, int iStartPos, const QString &ns, StructInformation *si)
{
const QVector<QStringView> tokens = tokenize(lines.at(i));
if (!validStructTokens(tokens))
const QVector<QStringView> tokens = tokenize(lines.at(iStartPos));
if (tokens.size() < 2)
return -1;
QStringView enumName = tokens.at(1);
if (enumName == QLatin1String("class"))
{
++i;
continue;
}
if (tokens.at(0) == QLatin1String("};"))
break;
if (tokens.at(0) == QLatin1String("enum"))
{
i = parseEnum(lines, i, si.type, &si);
if (i < 0)
if (tokens.size() < 3)
return -1;
++i;
continue;
enumName = tokens.at(2);
}
if (enumName.endsWith(QLatin1Char(';'))) // forward decl
return iStartPos; // move to next line
MemberInformation mi;
if (tokens.size() > 2)
EnumInformation ei;
ei.type = enumName.toString();
ei.ns = ns;
int i = iStartPos + 1;
while (i < lines.size())
{
const int parserCommentPos = tokens.at(2) == QLatin1String("=") ? 4 : 2;
if (tokens.size() > parserCommentPos)
const QVector<QStringView> tokens = tokenize(lines.at(i).split(QStringLiteral("//")).first());
if (tokens.isEmpty() || (tokens.at(0) == QLatin1String("{")))
{
const QStringView &comment = tokens.at(parserCommentPos);
DEBUG_LOG(m_logger) << "comment: " << comment.toString();
if (comment.startsWith(QLatin1String("//@array: ")))
{
const QStringView hint = comment.mid(QLatin1String("//@array: ").size());
QString structStr = QLatin1String("struct ") + si.type + QLatin1String("::") + tokens.at(0).toString() + QLatin1Char('\n') + hint.toString();
structStr.replace(QLatin1Char(';'), QLatin1String(";\n"));
DEBUG_LOG(m_logger) << "structStr: " << structStr;
const QStringList structLines = structStr.split(QLatin1Char('\n'));
QVector<QStringView> structLinesView;
structLinesView.reserve(structLines.size());
for (const QString &line : structLines)
structLinesView += line;
parseStruct(structLinesView, 0);
mi.type = si.type + QLatin1String("::") + tokens.at(0).toString();
mi.isArray = true;
}
if (comment == QLatin1String("//@invisible"))
mi.isVisible = false;
++i;
continue;
}
if (tokens.at(0) == QLatin1String("};"))
break;
if ((tokens.size() != 1 && tokens.size() != 3) || (tokens.size() == 3 && tokens.at(1) != QLatin1String("=")))
{
if (tokens.size() == 4 && tokens.at(0) == QLatin1String("}") && tokens.at(3).endsWith(QLatin1Char(';')) && si)
{
// enum in struct with direct decl of member
MemberInformation mi;
if (ns.isEmpty())
mi.type = ei.type;
else
mi.type = ns + QStringLiteral("::") + ei.type;
mi.isEnum = true;
mi.name = tokens.at(1).toString();
si->member.push_back(std::move(mi));
break;
}
WARNING_LOG(m_logger) << "Could not parse enum: '" << lines.at(i).toString() << "', line: " << i + 1;
return -1;
}
EnumValue ev;
ev.key = tokens.at(0).toString();
if (tokens.size() == 3)
{
QStringView value = tokens.at(2);
if (value.endsWith(QLatin1Char(',')))
value.chop(1);
ev.value = value.toInt();
}
else
{
int val = ei.values.isEmpty() ? 0 : (ei.values.last().value + 1);
ev.value = val;
}
ei.values.push_back(std::move(ev));
++i;
}
QStringView name = tokens.at(1);
if (name.endsWith(QLatin1Char(';')))
name.chop(1);
if (mi.type.isEmpty())
mi.type += tokens.at(0).toString();
categorizeMember(mi);
mi.name = name.toString();
if (mi.isEnum && !mi.type.contains(QLatin1String("::")))
DEBUG_LOG(m_logger) << "Found Enum: " << ei.type;
for (const EnumValue &ev : std::as_const(ei.values))
DEBUG_LOG(m_logger) << "Member[" << i << "]: " << ev.key << " = " << ev.value;
if (ei.type == QLatin1String("TelegramId"))
m_telegramIdEnum = ei;
m_enums.push_back(std::move(ei));
return i;
}
int LogViewTetraTelegramsParser::parseConstraint(const QVector<QStringView> &lines, int iStartPos)
{
const QVector<QStringView> tokens = tokenize(lines.at(iStartPos));
if (tokens.size() != 4)
{
for (const auto &ei : std::as_const(m_enums))
WARNING_LOG(m_logger) << "Could not parse constraint: '" << lines.at(iStartPos).toString() << "'";
return -1;
}
const QStringView &cs = tokens.at(3);
if (!cs.startsWith(QLatin1String("Constraints<")) || !cs.endsWith(QLatin1Char('>')))
{
WARNING_LOG(m_logger) << "Could not parse constraint: '" << lines.at(iStartPos).toString() << "'";
return -1;
}
QStringView structName = cs.mid(QLatin1String("Constraints<").size());
structName.chop(1);
DEBUG_LOG(m_logger) << "Constraint: " << structName.toString();
int i = iStartPos + 1;
while (i < lines.size())
{
const QVector<QStringView> tokens = tokenize(lines.at(i));
if (tokens.isEmpty() || (tokens.at(0) == QLatin1String("{")))
{
if (ei.type == mi.type)
++i;
continue;
}
if (tokens.at(0) == QLatin1String("};"))
break;
if (tokens.size() != 8 || tokens.at(2) != QLatin1String("TelegramId")) // static constexpr TelegramId id() { return TelegramId::INIT; }
{
++i;
continue;
}
const QVector<QStringView> parts = tokens.at(6).split(u"::");
if (parts.size() != 2)
{
WARNING_LOG(m_logger) << "Could not parse constraint: '" << lines.at(i).toString() << "'";
return -1;
}
QStringView enumKey = parts.at(1);
if (enumKey.endsWith(QLatin1Char(';')))
enumKey.chop(1);
bool bFound = false;
for (const auto &v : std::as_const(m_telegramIdEnum.values))
{
if (v.key == enumKey)
{
if (!ei.ns.isEmpty())
mi.type = ei.ns + QLatin1String("::") + mi.type;
m_visibleTelegrams.insert(v.value, structName.toString());
bFound = true;
break;
}
}
}
si.member.push_back(std::move(mi));
++i;
}
if (m_logger.isDebugEnabled())
{
if (si.baseStruct.isEmpty())
DEBUG_LOG(m_logger) << "Found Struct: " << si.type;
else
DEBUG_LOG(m_logger) << "Found Struct: " << si.type << ", base: " << si.baseStruct;
for (int j = 0; j < si.member.size(); ++j)
{
const MemberInformation &mi = si.member.at(j);
DEBUG_LOG(m_logger) << "Member[" << j << "]: " << mi.type << " - " << mi.name;
}
}
m_structs[si.type] = si;
return i;
}
int LogViewTetraTelegramsParser::parseEnum(const QVector<QStringView> &lines, int iStartPos, const QString &ns, StructInformation *si)
{
const QVector<QStringView> tokens = tokenize(lines.at(iStartPos));
if (tokens.size() < 2)
return -1;
QStringView enumName = tokens.at(1);
if (enumName == QLatin1String("class"))
{
if (tokens.size() < 3)
return -1;
enumName = tokens.at(2);
}
if (enumName.endsWith(QLatin1Char(';'))) // forward decl
return iStartPos; // move to next line
EnumInformation ei;
ei.type = enumName.toString();
ei.ns = ns;
int i = iStartPos + 1;
while (i < lines.size())
{
const QVector<QStringView> tokens = tokenize(lines.at(i).split(QStringLiteral("//")).first());
if (tokens.isEmpty() ||
(tokens.at(0) == QLatin1String("{")))
{
++i;
continue;
}
if (tokens.at(0) == QLatin1String("};"))
break;
if ((tokens.size() != 1 && tokens.size() != 3) ||
(tokens.size() == 3 && tokens.at(1) != QLatin1String("=")))
{
if (tokens.size() == 4 && tokens.at(0) == QLatin1String("}") && tokens.at(3).endsWith(QLatin1Char(';')) && si)
if (!bFound)
{
// enum in struct with direct decl of member
MemberInformation mi;
if (ns.isEmpty())
mi.type = ei.type;
else
mi.type = ns + QStringLiteral("::") + ei.type;
mi.isEnum = true;
mi.name = tokens.at(1).toString();
si->member.push_back(std::move(mi));
break;
WARNING_LOG(m_logger) << "Could not find enum value '" << enumKey.toString() << "' in enum TelegramId";
return -1;
}
WARNING_LOG(m_logger) << "Could not parse enum: '" << lines.at(i).toString() << "', line: " << i + 1;
return -1;
}
EnumValue ev;
ev.key = tokens.at(0).toString();
if (tokens.size() == 3)
{
QStringView value = tokens.at(2);
if (value.endsWith(QLatin1Char(',')))
value.chop(1);
ev.value = value.toInt();
}
else
{
int val = ei.values.isEmpty() ? 0 : (ei.values.last().value + 1);
ev.value = val;
}
ei.values.push_back(std::move(ev));
++i;
}
DEBUG_LOG(m_logger) << "Found Enum: " << ei.type;
for (const EnumValue &ev : std::as_const(ei.values))
DEBUG_LOG(m_logger) << "Member[" << i << "]: " << ev.key << " = " << ev.value;
if (ei.type == QLatin1String("TelegramId"))
m_telegramIdEnum = ei;
m_enums.push_back(std::move(ei));
return i;
}
int LogViewTetraTelegramsParser::parseConstraint(const QVector<QStringView> &lines, int iStartPos)
{
const QVector<QStringView> tokens = tokenize(lines.at(iStartPos));
if (tokens.size() != 4)
{
WARNING_LOG(m_logger) << "Could not parse constraint: '" << lines.at(iStartPos).toString() << "'";
return -1;
}
const QStringView &cs = tokens.at(3);
if (!cs.startsWith(QLatin1String("Constraints<")) || !cs.endsWith(QLatin1Char('>')))
{
WARNING_LOG(m_logger) << "Could not parse constraint: '" << lines.at(iStartPos).toString() << "'";
return -1;
}
QStringView structName = cs.mid(QLatin1String("Constraints<").size());
structName.chop(1);
DEBUG_LOG(m_logger) << "Constraint: " << structName.toString();
int i = iStartPos + 1;
while (i < lines.size())
{
const QVector<QStringView> tokens = tokenize(lines.at(i));
if (tokens.isEmpty() ||
(tokens.at(0) == QLatin1String("{")))
{
++i;
continue;
}
if (tokens.at(0) == QLatin1String("};"))
break;
if (tokens.size() != 8 || tokens.at(2) != QLatin1String("TelegramId")) // static constexpr TelegramId id() { return TelegramId::INIT; }
{
++i;
continue;
}
const QVector<QStringView> parts = tokens.at(6).split(u"::");
if (parts.size() != 2)
{
WARNING_LOG(m_logger) << "Could not parse constraint: '" << lines.at(i).toString() << "'";
return -1;
}
QStringView enumKey = parts.at(1);
if (enumKey.endsWith(QLatin1Char(';')))
enumKey.chop(1);
bool bFound = false;
for (const auto &v : std::as_const(m_telegramIdEnum.values))
{
if (v.key == enumKey)
{
m_visibleTelegrams.insert(v.value, structName.toString());
bFound = true;
break;
}
}
if (!bFound)
{
WARNING_LOG(m_logger) << "Could not find enum value '" << enumKey.toString() << "' in enum TelegramId";
return -1;
}
++i;
return i;
}
return i;
}
QString LogViewTetraTelegramsParser::getInnerType(const QString &type)
{
int idxLt = type.lastIndexOf(QLatin1Char('>'));
if (idxLt < 0)
return QString();
int idxGt = type.indexOf(QLatin1Char('<'));
if (idxGt < 0)
return QString();
return type.mid(idxGt + 1, idxLt - idxGt - 1);
}
void LogViewTetraTelegramsParser::categorizeMember(MemberInformation &mi) const
{
mi.isPod = isPod(mi.type);
mi.isEnum = mi.isPod ? false : isEnum(mi.type);
if (mi.type.startsWith(QLatin1String("std::vector<")))
mi.isArray = true;
mi.isStruct = mi.isArray ? false : isStruct(mi.type);
mi.isString = (mi.type == QLatin1String("std::string") || mi.type == QLatin1String("QString"));
mi.isBinary = (mi.type == QLatin1String("std::vector<unsigned char>") || mi.type == QLatin1String("QByteArray"));
}
static inline void bracketCount(const QStringView &str, int &cntLt, int &cntGt)
{
cntLt = 0;
cntGt = 0;
for (int i = 0; i < str.size(); ++i)
QString LogViewTetraTelegramsParser::getInnerType(const QString &type)
{
if (str.at(i) == QLatin1Char('<'))
cntLt++;
else if (str.at(i) == QLatin1Char('>'))
cntGt++;
int idxLt = type.lastIndexOf(QLatin1Char('>'));
if (idxLt < 0)
return QString();
int idxGt = type.indexOf(QLatin1Char('<'));
if (idxGt < 0)
return QString();
return type.mid(idxGt + 1, idxLt - idxGt - 1);
}
}
QVector<QStringView> LogViewTetraTelegramsParser::tokenize(const QStringView &line) const
{
QVector<QStringView> ret = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
// Calculate positions for each token (Qt6 QStringView has no position() method)
QVector<int> positions(ret.size());
int currentPos = 0;
for (int j = 0; j < ret.size(); ++j)
void LogViewTetraTelegramsParser::categorizeMember(MemberInformation &mi) const
{
// Find position of this token in the original line
positions[j] = line.indexOf(ret[j], currentPos);
currentPos = positions[j] + ret[j].size();
mi.isPod = isPod(mi.type);
mi.isEnum = mi.isPod ? false : isEnum(mi.type);
if (mi.type.startsWith(QLatin1String("std::vector<")))
mi.isArray = true;
mi.isStruct = mi.isArray ? false : isStruct(mi.type);
mi.isString = (mi.type == QLatin1String("std::string") || mi.type == QLatin1String("QString"));
mi.isBinary = (mi.type == QLatin1String("std::vector<unsigned char>") || mi.type == QLatin1String("QByteArray"));
}
int i = 0;
while (i < ret.size())
static inline void bracketCount(const QStringView &str, int &cntLt, int &cntGt)
{
cntLt = 0;
cntGt = 0;
for (int i = 0; i < str.size(); ++i)
{
if (str.at(i) == QLatin1Char('<'))
cntLt++;
else if (str.at(i) == QLatin1Char('>'))
cntGt++;
}
}
QVector<QStringView> LogViewTetraTelegramsParser::tokenize(const QStringView &line) const
{
QVector<QStringView> ret = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
// Calculate positions for each token (Qt6 QStringView has no position() method)
QVector<int> positions(ret.size());
int currentPos = 0;
for (int j = 0; j < ret.size(); ++j)
{
// Find position of this token in the original line
positions[j] = line.indexOf(ret[j], currentPos);
currentPos = positions[j] + ret[j].size();
}
int i = 0;
while (i < ret.size())
{
const QStringView &token = ret.at(i);
if (token.startsWith(QLatin1String("//")))
{
// all comment after this - merge into one
if (token.startsWith(QLatin1String("//")))
{
// all comment after this - merge into one
if (i == ret.size() - 1)
break;
const QStringView &lastToken = ret.last();
const QStringView newToken = line.mid(positions[i], positions.last() - positions[i] + lastToken.size());
DEBUG_LOG(m_logger) << "New Token: " << newToken.toString();
ret.resize(i + 1);
ret[i] = newToken;
break;
}
if (i == ret.size() - 1)
break;
const QStringView &lastToken = ret.last();
const QStringView newToken = line.mid(positions[i], positions.last() - positions[i] + lastToken.size());
DEBUG_LOG(m_logger) << "New Token: " << newToken.toString();
ret.resize(i + 1);
ret[i] = newToken;
break;
}
if (i == ret.size() - 1)
break;
int cntLt;
int cntGt;
bracketCount(token, cntLt, cntGt);
if (cntLt == cntGt)
{
++i;
continue;
}
int cntLt;
int cntGt;
bracketCount(token, cntLt, cntGt);
if (cntLt == cntGt)
{
++i;
continue;
}
const QStringView &nextToken = ret.at(i + 1);
const QStringView newToken = line.mid(positions[i], positions[i + 1] - positions[i] + nextToken.size());
DEBUG_LOG(m_logger) << "New Token: " << newToken.toString();
ret.removeAt(i + 1);
ret[i] = newToken;
DEBUG_LOG(m_logger) << "New Token: " << newToken.toString();
ret.removeAt(i + 1);
ret[i] = newToken;
}
return ret;
}
return ret;
}
bool LogViewTetraTelegramsParser::validStructTokens(const QVector<QStringView> &tokens)
{
if (tokens.isEmpty() || (tokens.at(0) == QLatin1String("{")) || (tokens.at(0) == QLatin1String("{}")) || (tokens.at(0) == QLatin1String("}")) ||
(tokens.at(0) == QLatin1String(":")) || (tokens.at(0) == QLatin1String(",")) || (tokens.at(0) == QLatin1String("virtual")))
return false;
if (tokens.at(0) == QLatin1String("};") || tokens.at(0) == QLatin1String("enum"))
return true;
const int len = tokens.last().startsWith(QLatin1String("//")) ? tokens.size() - 1 : tokens.size();
if (len == 2)
return true;
if (len < 4)
return false;
if (len >= 4 && tokens.at(2) == QLatin1String("="))
return true;
bool LogViewTetraTelegramsParser::validStructTokens(const QVector<QStringView> &tokens)
{
if (tokens.isEmpty() ||
(tokens.at(0) == QLatin1String("{")) ||
(tokens.at(0) == QLatin1String("{}")) ||
(tokens.at(0) == QLatin1String("}")) ||
(tokens.at(0) == QLatin1String(":")) ||
(tokens.at(0) == QLatin1String(",")) ||
(tokens.at(0) == QLatin1String("virtual")))
return false;
if (tokens.at(0) == QLatin1String("};") || tokens.at(0) == QLatin1String("enum"))
return true;
const int len = tokens.last().startsWith(QLatin1String("//")) ? tokens.size() - 1 : tokens.size();
if (len == 2)
return true;
if (len < 4)
return false;
if (len >= 4 && tokens.at(2) == QLatin1String("="))
return true;
return false;
}
}
} // namespace N_LogView
@@ -16,80 +16,82 @@
namespace N_LogView
{
struct MemberInformation
{
QString name;
QString type;
bool isArray = false;
bool isBinary = false;
bool isEnum = false;
bool isPod = false;
bool isString = false;
bool isStruct = false;
bool isVisible = true;
};
struct MemberInformation
{
QString name;
QString type;
bool isArray = false;
bool isBinary = false;
bool isEnum = false;
bool isPod = false;
bool isString = false;
bool isStruct = false;
bool isVisible = true;
};
struct StructInformation
{
QString type;
QString baseStruct; // we only allow one base...
struct StructInformation
{
QString type;
QString baseStruct; // we only allow one base...
QVector<MemberInformation> member;
bool isVisible = false;
};
QVector<MemberInformation> member;
bool isVisible = false;
};
struct EnumValue
{
QString key;
int value = 0;
};
struct EnumValue
{
QString key;
int value = 0;
};
struct EnumInformation
{
QString ns;
QString type;
QVector<EnumValue> values;
};
struct EnumInformation
{
QString ns;
QString type;
QVector<EnumValue> values;
};
struct PodInformation
{
QString type;
int byteLen = 0;
bool isBoolean = false;
bool isIntegral = false;
bool isSigned = false;
};
struct PodInformation
{
QString type;
int byteLen = 0;
bool isBoolean = false;
bool isIntegral = false;
bool isSigned = false;
};
class LogViewTetraTelegramsParser
{
public:
LogViewTetraTelegramsParser();
class LogViewTetraTelegramsParser
{
public:
LogViewTetraTelegramsParser();
bool parse(const QString &filename);
bool parse(const QString &filename);
EnumInformation enumFromType(const QString &type) const;
StructInformation structFromType(const QString &type) const;
PodInformation podFromType(const QString &type) const;
bool isEnum(const QString &type) const;
bool isStruct(const QString &type) const;
bool isPod(const QString &type) const;
QHash<int, QString> telegramsToCreate() const { return m_visibleTelegrams; }
QString nameFromTelegramId(int telId) const { return m_visibleTelegrams.value(telId); }
static QString getInnerType(const QString &type);
private:
void insertPod(const QString &type, int byteLen, bool isSigned, bool isIntegral, bool isBoolean = false);
int parseStruct(const QVector<QStringView> &lines, int iStartPos);
int parseEnum(const QVector<QStringView> &lines, int iStartPos, const QString &ns, StructInformation *si = nullptr);
int parseConstraint(const QVector<QStringView> &lines, int iStartPos);
void categorizeMember(MemberInformation &mi) const;
QVector<QStringView> tokenize(const QStringView &line) const;
static bool validStructTokens(const QVector<QStringView> &tokens);
private:
EnumInformation m_telegramIdEnum;
QVector<EnumInformation> m_enums;
QHash<QString, StructInformation> m_structs;
QHash<QString, PodInformation> m_pods;
QHash<int, QString> m_visibleTelegrams;
NGL::INGLLogger &m_logger;
};
EnumInformation enumFromType(const QString &type) const;
StructInformation structFromType(const QString &type) const;
PodInformation podFromType(const QString &type) const;
bool isEnum(const QString &type) const;
bool isStruct(const QString &type) const;
bool isPod(const QString &type) const;
QHash<int, QString> telegramsToCreate() const { return m_visibleTelegrams; }
QString nameFromTelegramId(int telId) const { return m_visibleTelegrams.value(telId); }
static QString getInnerType(const QString &type);
private:
void insertPod(const QString &type, int byteLen, bool isSigned, bool isIntegral, bool isBoolean = false);
int parseStruct(const QVector<QStringView> &lines, int iStartPos);
int parseEnum(const QVector<QStringView> &lines, int iStartPos, const QString &ns, StructInformation *si = nullptr);
int parseConstraint(const QVector<QStringView> &lines, int iStartPos);
void categorizeMember(MemberInformation &mi) const;
QVector<QStringView> tokenize(const QStringView &line) const;
static bool validStructTokens(const QVector<QStringView> &tokens);
private:
EnumInformation m_telegramIdEnum;
QVector<EnumInformation> m_enums;
QHash<QString, StructInformation> m_structs;
QHash<QString, PodInformation> m_pods;
QHash<int, QString> m_visibleTelegrams;
NGL::INGLLogger &m_logger;
};
} // namespace LogView
@@ -1,16 +1,16 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
#include "LogViewTextEdit.hpp"
#include "LogViewField.hpp"
#include "LogViewTelegram.hpp"
@@ -18,79 +18,78 @@
namespace N_LogView
{
// ---------------------------------------------------------------
LogViewTextEdit::LogViewTextEdit(LogViewField* a_field, QWidget* a_parent, const bool a_readonly)
: QLineEdit(a_parent)
, LogViewWidget(a_field, this, a_parent, a_readonly)
{
const QString value = a_field->value(0);
setText(value);
if (a_readonly)
// ---------------------------------------------------------------
LogViewTextEdit::LogViewTextEdit(LogViewField *a_field, QWidget *a_parent, const bool a_readonly)
: QLineEdit(a_parent)
, LogViewWidget(a_field, this, a_parent, a_readonly)
{
setReadOnly(true);
setAlignment(a_field->isRightAligned() ? Qt::AlignRight : Qt::AlignLeft);
}
const QString value = a_field->value(0);
setText(value);
// set a validator for number of chars
uint16_t maxArraySize = a_field->maxArraySize();
setMaxLength(maxArraySize);
updateToolTip(value);
if (a_readonly)
{
setReadOnly(true);
setAlignment(a_field->isRightAligned() ? Qt::AlignRight : Qt::AlignLeft);
}
// make proper width of widget
QFontMetrics fm(font());
// set a validator for number of chars
uint16_t maxArraySize = a_field->maxArraySize();
setMaxLength(maxArraySize);
updateToolTip(value);
// make proper width of widget
QFontMetrics fm(font());
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
setMinimumWidth(fm.width(QLatin1Char(' ') + value + QLatin1Char(' ')));
setMinimumWidth(fm.width(QLatin1Char(' ') + value + QLatin1Char(' ')));
#else
setMinimumWidth(fm.horizontalAdvance(QLatin1Char(' ') + value + QLatin1Char(' ')));
setMinimumWidth(fm.horizontalAdvance(QLatin1Char(' ') + value + QLatin1Char(' ')));
#endif
// connect signals
connect(this, &LogViewTextEdit::editingFinished,
this, &LogViewTextEdit::checkAndOvertakeContent);
}
// ---------------------------------------------------------------
void LogViewTextEdit::checkAndOvertakeContent()
{
updateToolTip(text()); // fixme nach jedem zeichen updaten
m_Valid = true;
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewTextEdit::saveContent(LogViewTelegram* a_telegram)
{
if (!isValid())
return false;
if (a_telegram->isJsonTelegram())
{
a_telegram->setJsonValue(m_Field->jsonPath(), text());
// connect signals
connect(this, &LogViewTextEdit::editingFinished, this, &LogViewTextEdit::checkAndOvertakeContent);
}
else
// ---------------------------------------------------------------
void LogViewTextEdit::checkAndOvertakeContent()
{
uint16_t size = getSize();
QString content = text();
uint16_t arraySize;
if (m_Field->isDynamicArray())
updateToolTip(text()); // fixme nach jedem zeichen updaten
m_Valid = true;
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewTextEdit::saveContent(LogViewTelegram *a_telegram)
{
if (!isValid())
return false;
if (a_telegram->isJsonTelegram())
{
arraySize = content.length();
a_telegram->setUIntX(LogViewTelegram::SIZE_CENTRAL_DYN_ARRAY_SIZE, arraySize);
// fixme: bei vielen Telegrammen muss Länge auf die Länge des Textes gesetzt werden. Dies kann nicht automatisch gemacht werden. Aber vielleicht kann man schauen, ob vor dem dyn. Array ein Feld Länge vorkommt, oder hartcodieren, oder konfigurierbaren
a_telegram->setJsonValue(m_Field->jsonPath(), text());
}
else
{
arraySize = m_Field->maxArraySize();
}
uint16_t size = getSize();
QString content = text();
uint16_t arraySize;
if (m_Field->isDynamicArray())
{
arraySize = content.length();
a_telegram->setUIntX(LogViewTelegram::SIZE_CENTRAL_DYN_ARRAY_SIZE, arraySize);
// fixme: bei vielen Telegrammen muss Länge auf die Länge des Textes gesetzt werden. Dies kann nicht automatisch gemacht werden. Aber vielleicht kann man schauen, ob vor dem dyn. Array ein Feld Länge vorkommt, oder hartcodieren, oder konfigurierbaren
}
else
{
arraySize = m_Field->maxArraySize();
}
// copy the text
for (int i = 0; i < arraySize; i++)
a_telegram->setUIntX(size, i < content.length() ? content[i].toLatin1() : 0);
// copy the text
for (int i = 0; i < arraySize; i++)
a_telegram->setUIntX(size, i < content.length() ? content[i].toLatin1() : 0);
}
return true;
}
return true;
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include "LogViewWidget.hpp"
@@ -25,7 +25,9 @@ namespace N_LogView
* @version 1.0
* @created 21-Mai-2010 10:28:05
*/
class LogViewTextEdit : public QLineEdit, public LogViewWidget
class LogViewTextEdit
: public QLineEdit
, public LogViewWidget
{
Q_OBJECT
public:
@@ -35,7 +37,7 @@ namespace N_LogView
* @param a_parent
* @param a_readonly
*/
LogViewTextEdit(LogViewField* a_field, QWidget* a_parent, const bool a_readonly);
LogViewTextEdit(LogViewField *a_field, QWidget *a_parent, const bool a_readonly);
/**
* Writes the content into telegram.
@@ -43,11 +45,10 @@ namespace N_LogView
*
* @param a_telegram
*/
bool saveContent(LogViewTelegram* a_telegram) override;
bool saveContent(LogViewTelegram *a_telegram) override;
protected slots:
void checkAndOvertakeContent();
};
}
@@ -1,16 +1,16 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
#include "LogViewValueEdit.hpp"
#include "LogViewField.hpp"
#include "LogViewTelegram.hpp"
@@ -18,118 +18,117 @@
namespace N_LogView
{
// ---------------------------------------------------------------
LogViewValueEdit::LogViewValueEdit(LogViewField* a_field, QWidget* a_parent, const bool a_readonly)
: QLineEdit(a_parent)
, LogViewWidget(a_field, this, a_parent, a_readonly)
, m_IsFloat(false)
{
const LogViewXdrStandardType *stdType = static_cast<const LogViewXdrStandardType*>(m_Field->xdrElement());
m_IsFloat = (LogViewXdrStandardType::e_Float == stdType->getValueKind());
// ---------------------------------------------------------------
LogViewValueEdit::LogViewValueEdit(LogViewField *a_field, QWidget *a_parent, const bool a_readonly)
: QLineEdit(a_parent)
, LogViewWidget(a_field, this, a_parent, a_readonly)
, m_IsFloat(false)
{
const LogViewXdrStandardType *stdType = static_cast<const LogViewXdrStandardType *>(m_Field->xdrElement());
m_IsFloat = (LogViewXdrStandardType::e_Float == stdType->getValueKind());
const QString valueText = a_field->value(0);
const QString valueText = a_field->value(0);
setText(valueText);
setText(valueText);
// checkAndOvertakeContent();
updateToolTip(valueText);
// checkAndOvertakeContent();
updateToolTip(valueText);
// make proper width of widget
QFontMetrics fm(font());
// make proper width of widget
QFontMetrics fm(font());
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
setMinimumWidth(fm.width(QLatin1Char(' ') + valueText + QLatin1Char(' ')));
setMinimumWidth(fm.width(QLatin1Char(' ') + valueText + QLatin1Char(' ')));
#else
setMinimumWidth(fm.horizontalAdvance(QLatin1Char(' ') + valueText + QLatin1Char(' ')));
setMinimumWidth(fm.horizontalAdvance(QLatin1Char(' ') + valueText + QLatin1Char(' ')));
#endif
if (a_readonly)
{
setReadOnly(true);
setAlignment(a_field->isRightAligned() ? Qt::AlignRight : Qt::AlignLeft);
}
else
{
connect(this, &LogViewValueEdit::editingFinished,
this, &LogViewValueEdit::checkAndOvertakeContent);
}
}
// ---------------------------------------------------------------
void LogViewValueEdit::checkAndOvertakeContent()
{
bool ok;
int64_t intValue = 0;
double floatValue = 0.0;
// get the calculated and checked value
if (m_IsFloat)
floatValue = getFloat(text(), (uint64_t&)intValue, ok);
else
intValue = getInteger(text(), ok);
// handle errors
if (!ok)
{
setFocus();
selectAll();
return; // abort
}
// update
if (m_IsFloat)
setText(QString::number(floatValue));
else
setText(QString::number(intValue));
updateToolTip(text());
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewValueEdit::saveContent(LogViewTelegram* a_telegram)
{
if (m_Valid)
{
bool ok;
if (m_IsFloat)
if (a_readonly)
{
// save the float or double-value
uint64_t valueAsUint64;
const double value = getFloat(text(), valueAsUint64, ok);
if (ok)
{
if (a_telegram->isJsonTelegram())
{
a_telegram->setJsonValue(m_Field->jsonPath(), value);
}
else
{
const LogViewXdrStandardType *stdType = static_cast<const LogViewXdrStandardType*>(m_Field->xdrElement());
LogViewXdrStandardType::E_ByteOrder byteOrder = stdType->getByteOrder();
a_telegram->setUIntX(getSize(), valueAsUint64, byteOrder);
}
return true;
}
setReadOnly(true);
setAlignment(a_field->isRightAligned() ? Qt::AlignRight : Qt::AlignLeft);
}
else
{
// save the integer-value
qint64 intValue = getInteger(text(), ok);
if (ok)
{
if (a_telegram->isJsonTelegram())
a_telegram->setJsonValue(m_Field->jsonPath(), intValue);
else
a_telegram->setUIntX(getSize(), intValue);
return true;
}
connect(this, &LogViewValueEdit::editingFinished, this, &LogViewValueEdit::checkAndOvertakeContent);
}
}
return false;
}
// ---------------------------------------------------------------
void LogViewValueEdit::checkAndOvertakeContent()
{
bool ok;
int64_t intValue = 0;
double floatValue = 0.0;
// get the calculated and checked value
if (m_IsFloat)
floatValue = getFloat(text(), (uint64_t &)intValue, ok);
else
intValue = getInteger(text(), ok);
// handle errors
if (!ok)
{
setFocus();
selectAll();
return; // abort
}
// update
if (m_IsFloat)
setText(QString::number(floatValue));
else
setText(QString::number(intValue));
updateToolTip(text());
}
// ---------------------------------------------------------------
// Writes the content into telegram.
// Returns true if successful.
// ---------------------------------------------------------------
bool LogViewValueEdit::saveContent(LogViewTelegram *a_telegram)
{
if (m_Valid)
{
bool ok;
if (m_IsFloat)
{
// save the float or double-value
uint64_t valueAsUint64;
const double value = getFloat(text(), valueAsUint64, ok);
if (ok)
{
if (a_telegram->isJsonTelegram())
{
a_telegram->setJsonValue(m_Field->jsonPath(), value);
}
else
{
const LogViewXdrStandardType *stdType = static_cast<const LogViewXdrStandardType *>(m_Field->xdrElement());
LogViewXdrStandardType::E_ByteOrder byteOrder = stdType->getByteOrder();
a_telegram->setUIntX(getSize(), valueAsUint64, byteOrder);
}
return true;
}
}
else
{
// save the integer-value
qint64 intValue = getInteger(text(), ok);
if (ok)
{
if (a_telegram->isJsonTelegram())
a_telegram->setJsonValue(m_Field->jsonPath(), intValue);
else
a_telegram->setUIntX(getSize(), intValue);
return true;
}
}
}
return false;
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include "LogViewWidget.hpp"
@@ -25,7 +25,9 @@ namespace N_LogView
* @version 1.0
* @created 20-Mai-2010 14:47:50
*/
class LogViewValueEdit : public QLineEdit, public LogViewWidget
class LogViewValueEdit
: public QLineEdit
, public LogViewWidget
{
Q_OBJECT
public:
@@ -35,7 +37,7 @@ namespace N_LogView
* @param a_parent
* @param a_readonly
*/
LogViewValueEdit(LogViewField* a_field, QWidget* a_parent, const bool a_readonly);
LogViewValueEdit(LogViewField *a_field, QWidget *a_parent, const bool a_readonly);
/**
* Writes the content into telegram.
@@ -43,15 +45,13 @@ namespace N_LogView
*
* @param a_telegram
*/
bool saveContent(LogViewTelegram* a_telegram) override;
bool saveContent(LogViewTelegram *a_telegram) override;
protected:
bool m_IsFloat;
protected slots:
void checkAndOvertakeContent();
};
}
@@ -1,16 +1,16 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
// manual class headers
#include "LogViewWidget.hpp"
@@ -23,208 +23,210 @@
namespace N_LogView
{
// ---------------------------------------------------------------
LogViewWidget::LogViewWidget(LogViewField* a_field, QWidget* a_widget, QWidget* a_parent, bool a_readonly)
: m_Readonly(a_readonly)
, m_Valid(true)
, m_Widget(a_widget)
, m_Field(a_field)
, m_Parent(a_parent)
, m_logger(getLogger("LogViewWidget"))
{
}
// ---------------------------------------------------------------
uint16_t LogViewWidget::getSize() const
{
// todo: check whether really a standardtype
const LogViewXdrStandardType* xdrStandardType = static_cast<const LogViewXdrStandardType*>(m_Field->xdrElement());
return xdrStandardType->getValueSize();
}
// ---------------------------------------------------------------
void LogViewWidget::showMessageBox(const QString &a_errorText) const
{
QMessageBox::warning(m_Parent, QObject::tr("Fehler"), a_errorText);
}
// ---------------------------------------------------------------
void LogViewWidget::updateToolTip(const QString &a_text)
{
bool isList = m_Field->valueListSize() > 1 || m_Field->isDynamicArray();
switch (m_Field->xdrElement()->getKind())
// ---------------------------------------------------------------
LogViewWidget::LogViewWidget(LogViewField *a_field, QWidget *a_widget, QWidget *a_parent, bool a_readonly)
: m_Readonly(a_readonly)
, m_Valid(true)
, m_Widget(a_widget)
, m_Field(a_field)
, m_Parent(a_parent)
, m_logger(getLogger("LogViewWidget"))
{
case LogViewXdrElement::e_KindStandardType:
switch (static_cast<const LogViewXdrStandardType*>(m_Field->xdrElement())->getValueKind())
}
// ---------------------------------------------------------------
uint16_t LogViewWidget::getSize() const
{
// todo: check whether really a standardtype
const LogViewXdrStandardType *xdrStandardType = static_cast<const LogViewXdrStandardType *>(m_Field->xdrElement());
return xdrStandardType->getValueSize();
}
// ---------------------------------------------------------------
void LogViewWidget::showMessageBox(const QString &a_errorText) const
{
QMessageBox::warning(m_Parent, QObject::tr("Fehler"), a_errorText);
}
// ---------------------------------------------------------------
void LogViewWidget::updateToolTip(const QString &a_text)
{
bool isList = m_Field->valueListSize() > 1 || m_Field->isDynamicArray();
switch (m_Field->xdrElement()->getKind())
{
case LogViewXdrStandardType::e_Character:
m_Widget->setToolTip(QObject::tr("%1 Zeichen").arg(a_text.length()));
if (!m_Readonly)
m_Widget->setToolTip(QObject::tr("%1<br><nobr>Maximal %2 Zeichen erlaubt</nobr>").arg(m_Widget->toolTip()).arg(m_Field->maxArraySize()));
break;
case LogViewXdrStandardType::e_Data:
if (m_Readonly)
m_Widget->setToolTip(QObject::tr("%1 Bytes").arg(m_Field->valueListSize()));
break;
case LogViewXdrStandardType::e_Unsigned:
case LogViewXdrStandardType::e_Signed:
if (m_Readonly && isList)
case LogViewXdrElement::e_KindStandardType:
switch (static_cast<const LogViewXdrStandardType *>(m_Field->xdrElement())->getValueKind())
{
case LogViewXdrStandardType::e_Character:
m_Widget->setToolTip(QObject::tr("%1 Zeichen").arg(a_text.length()));
if (!m_Readonly)
m_Widget->setToolTip(QObject::tr("%1<br><nobr>Maximal %2 Zeichen erlaubt</nobr>").arg(m_Widget->toolTip()).arg(m_Field->maxArraySize()));
break;
case LogViewXdrStandardType::e_Data:
if (m_Readonly)
m_Widget->setToolTip(QObject::tr("%1 Bytes").arg(m_Field->valueListSize()));
break;
case LogViewXdrStandardType::e_Unsigned:
case LogViewXdrStandardType::e_Signed:
if (m_Readonly && isList)
{
m_Widget->setToolTip(QObject::tr("%1 Elemente").arg(m_Field->valueListSize()));
}
else
{
// fixme: bei 3-byte werten werden fälschlicherweise 4 Bytes angezeigt
if (m_Field->isDateTimeField())
{
m_Widget->setToolTip(QObject::tr("Unixzeit: %1 ").arg(a_text));
}
else
{
m_Widget->setToolTip(QString());
}
// actual value in hex and binary
if (!isList)
{
int64_t value = a_text.toLong();
m_Widget->setToolTip(QStringLiteral("%1<b>%2</b> %3").arg(m_Widget->toolTip(), toHex(value), toBin(value)));
}
// range
if (!m_Field->isDateTimeField() && !m_Readonly)
{
const QString sep(isList ? QString() : QStringLiteral("<br>"));
m_Widget->setToolTip(
QStringLiteral("%1%2<nobr>Wertebereich: %3..%4</nobr>").arg(m_Widget->toolTip(), sep).arg(m_Field->getLowestValue()).arg(m_Field->getHighestValue()));
}
}
break;
case LogViewXdrStandardType::e_Float:
if (4 == m_Field->size())
m_Widget->setToolTip(QStringLiteral("<nobr>Wertebereich: +/-3.4e+/-38</nobr>"));
else
m_Widget->setToolTip(QStringLiteral("<nobr>Wertebereich: +/-1.7e+/-308</nobr>"));
break;
case LogViewXdrStandardType::e_Boolean:
m_Widget->setToolTip(QStringLiteral("true/false"));
}
break;
case LogViewXdrElement::e_KindEnum:
{
m_Widget->setToolTip(QObject::tr("%1 Elemente").arg(m_Field->valueListSize()));
uint64_t enumValue = a_text.toLong();
m_Widget->setToolTip(QStringLiteral("<b>%1 %2</b> %3").arg(enumValue).arg(toHex(enumValue), toBin(enumValue)));
break;
}
else
default:
ERROR_LOG(m_logger) << "Case not implemented";
}
}
// ---------------------------------------------------------------
double LogViewWidget::getFloat(const QString &a_text, uint64_t &a_FloatAsData, bool &a_ok, const bool a_reverse)
{
// INFO_LOG(m_logger) << "a_text=" << a_text.toStdString();
//LogViewXdrStandardType::E_ByteOrder byteOrder = ((LogViewXdrStandardType*)m_Field->xdrElement())->getByteOrder();
double value;
if (8 == getSize())
{
value = a_text.toDouble(&a_ok);
a_FloatAsData = LogViewTelegram::doubleToXdr(value);
}
else
{
value = a_text.toFloat(&a_ok);
a_FloatAsData = LogViewTelegram::floatToXdr(value);
}
// show error-message
// fixme zeige fehler genauer
if (!a_ok)
showMessageBox(QStringLiteral("Inalid real value: '%1'").arg(a_text));
m_Valid = a_ok;
// swap for display data on table
if (a_reverse)
{
int j = getSize() - 1;
uint64_t *ptr = &a_FloatAsData;
for (int i = 0; i < getSize() / 2; i++)
{
// fixme: bei 3-byte werten werden fälschlicherweise 4 Bytes angezeigt
if (m_Field->isDateTimeField())
{
m_Widget->setToolTip(QObject::tr("Unixzeit: %1 ").arg(a_text));
}
else
{
m_Widget->setToolTip(QString());
}
// actual value in hex and binary
if (!isList)
{
int64_t value = a_text.toLong();
m_Widget->setToolTip(QStringLiteral("%1<b>%2</b> %3").arg(m_Widget->toolTip(), toHex(value), toBin(value)));
}
// range
if (!m_Field->isDateTimeField() && !m_Readonly)
{
const QString sep(isList ? QString() : QStringLiteral("<br>"));
m_Widget->setToolTip(QStringLiteral("%1%2<nobr>Wertebereich: %3..%4</nobr>").arg(m_Widget->toolTip(), sep).arg(m_Field->getLowestValue()).arg(m_Field->getHighestValue()));
}
uint8_t data = ((uint8_t *)ptr)[j];
((uint8_t *)&a_FloatAsData)[j] = ((uint8_t *)&a_FloatAsData)[i];
((uint8_t *)&a_FloatAsData)[i] = data;
j--;
}
break;
case LogViewXdrStandardType::e_Float:
if (4 == m_Field->size())
m_Widget->setToolTip(QStringLiteral("<nobr>Wertebereich: +/-3.4e+/-38</nobr>"));
else
m_Widget->setToolTip(QStringLiteral("<nobr>Wertebereich: +/-1.7e+/-308</nobr>"));
break;
case LogViewXdrStandardType::e_Boolean:
m_Widget->setToolTip(QStringLiteral("true/false"));
}
break;
case LogViewXdrElement::e_KindEnum:
{
uint64_t enumValue = a_text.toLong();
m_Widget->setToolTip(QStringLiteral("<b>%1 %2</b> %3").arg(enumValue).arg(toHex(enumValue), toBin(enumValue)));
break;
}
default:
ERROR_LOG(m_logger) << "Case not implemented";
}
}
// ---------------------------------------------------------------
double LogViewWidget::getFloat(const QString& a_text, uint64_t& a_FloatAsData, bool& a_ok, const bool a_reverse)
{
// INFO_LOG(m_logger) << "a_text=" << a_text.toStdString();
//LogViewXdrStandardType::E_ByteOrder byteOrder = ((LogViewXdrStandardType*)m_Field->xdrElement())->getByteOrder();
double value;
if (8 == getSize())
{
value = a_text.toDouble(&a_ok);
a_FloatAsData = LogViewTelegram::doubleToXdr(value);
} else {
value = a_text.toFloat(&a_ok);
a_FloatAsData = LogViewTelegram::floatToXdr(value);
}
// show error-message
// fixme zeige fehler genauer
if (!a_ok)
showMessageBox(QStringLiteral("Inalid real value: '%1'").arg(a_text));
m_Valid = a_ok;
// swap for display data on table
if (a_reverse)
{
int j = getSize() - 1;
uint64_t* ptr = &a_FloatAsData;
for (int i = 0; i < getSize() / 2; i++)
// set the upper 4 bytes to 0 for float
if (4 == getSize())
{
uint8_t data = ((uint8_t*)ptr)[j];
((uint8_t*)&a_FloatAsData)[j] = ((uint8_t*)&a_FloatAsData)[i];
((uint8_t*)&a_FloatAsData)[i] = data;
j--;
((uint8_t *)&a_FloatAsData)[4] = 0;
((uint8_t *)&a_FloatAsData)[5] = 0;
((uint8_t *)&a_FloatAsData)[6] = 0;
((uint8_t *)&a_FloatAsData)[7] = 0;
}
return value;
}
// set the upper 4 bytes to 0 for float
if (4 == getSize())
{
((uint8_t*)&a_FloatAsData)[4] = 0;
((uint8_t*)&a_FloatAsData)[5] = 0;
((uint8_t*)&a_FloatAsData)[6] = 0;
((uint8_t*)&a_FloatAsData)[7] = 0;
}
return value;
}
// ---------------------------------------------------------------
// Converts a_text into a signed integer and returns it. The
// parameter a_ok will be true if all was successful. The
// attribute m_Valid will be set to a_ok.
// The range will be checked, if the value is out of range, an
// error will be shown as messge-box and a_ok will be false.
// The input a_text can be a calculation.
// ---------------------------------------------------------------
int64_t LogViewWidget::getInteger(const QString& a_text, bool& a_ok)
{
// calculate the expression into a number
N_SST::IntegerCalculator calculator;
N_SST::IntegerCalculator::E_Error error;
int64_t value = calculator.calc(a_text.toStdString(), error);
m_Valid = false;
a_ok = true;
if (N_SST::IntegerCalculator::e_Ok != error)
// ---------------------------------------------------------------
// Converts a_text into a signed integer and returns it. The
// parameter a_ok will be true if all was successful. The
// attribute m_Valid will be set to a_ok.
// The range will be checked, if the value is out of range, an
// error will be shown as messge-box and a_ok will be false.
// The input a_text can be a calculation.
// ---------------------------------------------------------------
int64_t LogViewWidget::getInteger(const QString &a_text, bool &a_ok)
{
// todo: show exact error-message
if (a_text != m_LastErrorValueText)
// calculate the expression into a number
N_SST::IntegerCalculator calculator;
N_SST::IntegerCalculator::E_Error error;
int64_t value = calculator.calc(a_text.toStdString(), error);
m_Valid = false;
a_ok = true;
if (N_SST::IntegerCalculator::e_Ok != error)
{
showMessageBox(QString::fromUtf8("Die Berechnung '%1' ist falsch").arg(a_text));
m_LastErrorValueText = a_text;
}
a_ok = false;
}
else
{
// check the range
int64_t highest = m_Field->getHighestValue();
if (value > highest)
{
a_ok = false;
// fixme: dieser Trick mit m_LastErrorValueText ist für den Benutzer etwas verwirrend, da
// plötzlich keine Reaktion mehr auf Tab, Ok oder wählen eines anderen Feldes passiert...
// todo: show exact error-message
if (a_text != m_LastErrorValueText)
{
showMessageBox(QString::fromUtf8("Der Wert '%1' ist zu hoch. Maximalwert: %2").arg(a_text).arg(highest));
showMessageBox(QString::fromUtf8("Die Berechnung '%1' ist falsch").arg(a_text));
m_LastErrorValueText = a_text;
}
return value; // abort
}
int64_t lowest = m_Field->getLowestValue();
if (value < lowest)
{
a_ok = false;
if (a_text != m_LastErrorValueText)
{
showMessageBox(QString::fromUtf8("Der Wert '%1' ist zu tief. Minimalwert: %2").arg(a_text).arg(lowest));
m_LastErrorValueText = a_text;
}
return value; // abort
}
m_Valid = true;
else
{
// check the range
int64_t highest = m_Field->getHighestValue();
if (value > highest)
{
a_ok = false;
// fixme: dieser Trick mit m_LastErrorValueText ist für den Benutzer etwas verwirrend, da
// plötzlich keine Reaktion mehr auf Tab, Ok oder wählen eines anderen Feldes passiert...
if (a_text != m_LastErrorValueText)
{
showMessageBox(QString::fromUtf8("Der Wert '%1' ist zu hoch. Maximalwert: %2").arg(a_text).arg(highest));
m_LastErrorValueText = a_text;
}
return value; // abort
}
int64_t lowest = m_Field->getLowestValue();
if (value < lowest)
{
a_ok = false;
if (a_text != m_LastErrorValueText)
{
showMessageBox(QString::fromUtf8("Der Wert '%1' ist zu tief. Minimalwert: %2").arg(a_text).arg(lowest));
m_LastErrorValueText = a_text;
}
return value; // abort
}
m_Valid = true;
}
return value;
}
return value;
}
} // namespace N_LogView
@@ -22,54 +22,52 @@ class QFont;
namespace N_LogView
{
template <typename T>
inline QString toHex(T num)
{
return QStringLiteral("0x%1").arg(num, 2, 16, QLatin1Char('0'));
}
template <typename T>
inline QString toBin(T num)
{
return QStringLiteral("0b%1").arg(num, 8, 2, QLatin1Char('0'));
}
template <typename T> inline QString toHex(T num)
{
return QStringLiteral("0x%1").arg(num, 2, 16, QLatin1Char('0'));
}
template <typename T> inline QString toBin(T num)
{
return QStringLiteral("0b%1").arg(num, 8, 2, QLatin1Char('0'));
}
class LogViewField;
class LogViewTelegram;
class LogViewField;
class LogViewTelegram;
/**
/**
* @author alois.wismer
* @version 1.0
* @created 20-Mai-2010 14:51:17
*/
class LogViewWidget
{
public:
LogViewWidget(LogViewField* a_field, QWidget* a_widget, QWidget* a_parent, bool a_readonly);
virtual ~LogViewWidget() = default;
class LogViewWidget
{
public:
LogViewWidget(LogViewField *a_field, QWidget *a_widget, QWidget *a_parent, bool a_readonly);
virtual ~LogViewWidget() = default;
virtual uint16_t getSize() const;
LogViewField* field() const { return m_Field; }
bool isValid() const { return m_Valid; }
virtual uint16_t getSize() const;
LogViewField *field() const { return m_Field; }
bool isValid() const { return m_Valid; }
/**
/**
* The content if the field is a text-field
*/
QString getText() const { return m_Text; }
QString getText() const { return m_Text; }
/**
/**
* Writes the content into telegram.
* Returns true if successful.
*
* @param a_telegram
*/
virtual bool saveContent(LogViewTelegram* a_telegram) = 0;
virtual bool saveContent(LogViewTelegram *a_telegram) = 0;
protected:
void showMessageBox(const QString &a_errorText) const;
void updateToolTip(const QString &a_text = QString());
double getFloat(const QString& a_text, uint64_t& a_FloatAsData, bool& a_ok, const bool a_reverse = false);
protected:
void showMessageBox(const QString &a_errorText) const;
void updateToolTip(const QString &a_text = QString());
double getFloat(const QString &a_text, uint64_t &a_FloatAsData, bool &a_ok, const bool a_reverse = false);
/**
/**
* Converts a_text into a signed integer and returns it. The parameter a_ok will
* be true if all was successful. The attribute m_Valid will be set to a_ok.
* The range will be checked, if the value is out of range, an error will be shown
@@ -79,24 +77,24 @@ protected:
* @param a_text
* @param a_ok
*/
int64_t getInteger(const QString& a_text, bool& a_ok);
int64_t getInteger(const QString &a_text, bool &a_ok);
protected:
bool m_Readonly;
bool m_Valid;
/**
protected:
bool m_Readonly;
bool m_Valid;
/**
* The content if the field is a text-field
*/
QString m_Text;
QString m_LastErrorValueText;
QWidget *m_Widget;
QString m_Text;
QString m_LastErrorValueText;
QWidget *m_Widget;
LogViewField *m_Field;
LogViewField *m_Field;
QWidget *m_Parent;
QWidget *m_Parent;
LOGGER_T m_logger;
};
LOGGER_T m_logger;
};
}
@@ -1,14 +1,14 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
#include "LogViewXdrElement.hpp"
@@ -16,46 +16,46 @@
namespace N_LogView
{
// ---------------------------------------------------------------
// Constructor of a struct or enum
// ---------------------------------------------------------------
LogViewXdrElement::LogViewXdrElement(const QString& a_name, const E_ElementKind a_kind, const char *loggerName)
: m_Name(a_name)
, m_Kind(a_kind)
, m_logger(getLogger(loggerName))
{
if (a_name.indexOf(QLatin1Char('<')) >= 0 || a_name.indexOf(QLatin1Char('[')) >= 0)
ERROR_LOG(m_logger) << "Element \'" << a_name.toStdString() << "\' has a problem";
}
// ---------------------------------------------------------------
void LogViewXdrElement::dump() const
{
INFO_LOG(m_logger) << "Element[" << getName() << "]: kind=" << getKindName();
}
// ---------------------------------------------------------------
QString LogViewXdrElement::getKindName() const
{
switch (getKind())
// ---------------------------------------------------------------
// Constructor of a struct or enum
// ---------------------------------------------------------------
LogViewXdrElement::LogViewXdrElement(const QString &a_name, const E_ElementKind a_kind, const char *loggerName)
: m_Name(a_name)
, m_Kind(a_kind)
, m_logger(getLogger(loggerName))
{
case e_KindDefine:
return QLatin1String("Define");
case e_KindEnum:
return QLatin1String("Enum");
case e_KindEnumElement:
return QLatin1String("EnumElement");
case e_KindStandardType:
return QLatin1String("StandardType");
case e_KindStruct:
return QLatin1String("Struct");
case e_KindStructElement:
return QLatin1String("StructElement");
case e_KindTypedef:
return QLatin1String("Typedef");
if (a_name.indexOf(QLatin1Char('<')) >= 0 || a_name.indexOf(QLatin1Char('[')) >= 0)
ERROR_LOG(m_logger) << "Element \'" << a_name.toStdString() << "\' has a problem";
}
// ---------------------------------------------------------------
void LogViewXdrElement::dump() const
{
INFO_LOG(m_logger) << "Element[" << getName() << "]: kind=" << getKindName();
}
// ---------------------------------------------------------------
QString LogViewXdrElement::getKindName() const
{
switch (getKind())
{
case e_KindDefine:
return QLatin1String("Define");
case e_KindEnum:
return QLatin1String("Enum");
case e_KindEnumElement:
return QLatin1String("EnumElement");
case e_KindStandardType:
return QLatin1String("StandardType");
case e_KindStruct:
return QLatin1String("Struct");
case e_KindStructElement:
return QLatin1String("StructElement");
case e_KindTypedef:
return QLatin1String("Typedef");
}
return QStringLiteral("Unknown (%1)").arg(getKind());
}
return QStringLiteral("Unknown (%1)").arg(getKind());
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include <QtCore/QString>
@@ -26,7 +26,6 @@ namespace N_LogView
class LogViewXdrElement
{
public:
/**
* @author alois.wismer
* @version 1.0
@@ -52,10 +51,10 @@ namespace N_LogView
* @param a_name
* @param a_kind
*/
LogViewXdrElement(const QString& a_name, const E_ElementKind a_kind, const char *loggerName);
LogViewXdrElement(const QString &a_name, const E_ElementKind a_kind, const char *loggerName);
public:
const QString& getName() const { return m_Name; }
const QString &getName() const { return m_Name; }
LogViewXdrElement::E_ElementKind getKind() const { return m_Kind; }
virtual void dump() const;
File diff suppressed because it is too large. Load diff
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include <QtCore/QString>
@@ -37,7 +37,6 @@ namespace N_LogView
class LogViewXdrParser : public N_SST::IntegerCalculator
{
public:
/**
* Defines in which structure the parser is parsing now
*
@@ -62,7 +61,7 @@ namespace N_LogView
*
* @param a_fileName
*/
void parseX_File(const QString& a_fileName);
void parseX_File(const QString &a_fileName);
/**
* This function delivers the name of the telegram.
@@ -89,16 +88,15 @@ namespace N_LogView
* @param a_name
* @param a_value
*/
bool getDefine(const QString& a_name, int64_t& a_value) const;
bool getDefine(const QString &a_name, int64_t &a_value) const;
/**
*
* @param a_name
*/
const LogViewXdrElement* getElement(const QString& a_name) const;
const LogViewXdrElement *getElement(const QString &a_name) const;
protected:
QString m_MessageBoxTitle;
bool m_WithinComment;
QString m_Line;
@@ -112,7 +110,7 @@ namespace N_LogView
* telegram structure.
*/
QString m_UnionType;
std::map<QString, LogViewXdrElement*> m_ElementMap;
std::map<QString, LogViewXdrElement *> m_ElementMap;
LogViewXdrStruct *m_ActElement;
@@ -131,7 +129,7 @@ namespace N_LogView
* @param a_dynArraySizeMethod
* @param a_byteOrder
*/
void addStandardType(const QString& a_name,
void addStandardType(const QString &a_name,
const uint16_t a_dataSize,
const uint16_t a_realSize,
const LogViewXdrStandardType::E_ValueKind a_kind,
@@ -142,7 +140,7 @@ namespace N_LogView
*
* @param a_line
*/
QString removeComments(const QString& a_line);
QString removeComments(const QString &a_line);
/**
*
@@ -173,7 +171,7 @@ namespace N_LogView
*
* @param a_line
*/
void parseUnion(const QString& a_line);
void parseUnion(const QString &a_line);
/**
*
@@ -181,7 +179,7 @@ namespace N_LogView
* @param a_name
* @param a_value
*/
bool parseEnumLine(const QString& a_line, QString& a_name, QString& a_value) const;
bool parseEnumLine(const QString &a_line, QString &a_name, QString &a_value) const;
/**
* Shows an error-message containing the line-nbr, the line itself and an
@@ -189,21 +187,21 @@ namespace N_LogView
*
* @param a_errorText
*/
void showErrorMessage(const QString& a_errorText) const;
void showErrorMessage(const QString &a_errorText) const;
/**
*
* @param a_calcText
* @param a_isOk
*/
int64_t calcValue(const QString& a_calcText, bool& a_isOk);
int64_t calcValue(const QString &a_calcText, bool &a_isOk);
/**
*
* @param a_variableName
* @param a_value
*/
bool getVariableValue(const std::string& a_variableName, int64_t& a_value) const override;
bool getVariableValue(const std::string &a_variableName, int64_t &a_value) const override;
/**
*
@@ -212,7 +210,7 @@ namespace N_LogView
* e_DynArrayMsgLength. Here the value in <x> will be subtracted from the message-
* length to get the size of the dynamic array.
*/
uint16_t parseArray(QString& a_name, uint16_t& a_dynArrayMsgOffset) const;
uint16_t parseArray(QString &a_name, uint16_t &a_dynArrayMsgOffset) const;
/**
*
@@ -225,7 +223,7 @@ namespace N_LogView
*
* @param a_line
*/
void fillWordList(const QString& a_line);
void fillWordList(const QString &a_line);
/**
*
@@ -237,13 +235,13 @@ namespace N_LogView
*
* @param a_ok
*/
QString getNextType(bool& a_ok);
QString getNextType(bool &a_ok);
/**
*
* @param a_enumStruct
*/
QString getNextEnum(const LogViewXdrStruct*& a_enumStruct);
QString getNextEnum(const LogViewXdrStruct *&a_enumStruct);
/**
*
@@ -251,7 +249,7 @@ namespace N_LogView
* @param a_firstBit
* @param a_lastBit
*/
bool parseBitfield(const QString& a_fieldText, int16_t& a_firstBit, int16_t& a_lastBit) const;
bool parseBitfield(const QString &a_fieldText, int16_t &a_firstBit, int16_t &a_lastBit) const;
/**
* adds an element to the element-map if it does not already exist within this map.
@@ -262,7 +260,7 @@ namespace N_LogView
* @param a_name
* @param a_element
*/
bool addToElementMap(const QString& a_name, LogViewXdrElement* a_element);
bool addToElementMap(const QString &a_name, LogViewXdrElement *a_element);
private:
LOGGER_T m_logger;
@@ -1,84 +1,83 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
// manual class headers
#include "LogViewXdrStandardType.hpp"
namespace N_LogView
{
// ---------------------------------------------------------------
// (a_valueKind must be Unsigned, if a_dynArraySizeMethod is
// e_DynArray...)
// ---------------------------------------------------------------
LogViewXdrStandardType::LogViewXdrStandardType(const QString& a_name, const int a_valueSize,
const int a_editSize, const E_ValueKind a_valueKind,
const E_DynArraySizeMethod a_dynArraySizeMethod, E_ByteOrder a_byteOrder)
: LogViewXdrElement(a_name, e_KindStandardType, "LogViewXdrStandardType")
, m_ValueSize(a_valueSize)
, m_EditSize(a_editSize)
, m_ValueKind(a_valueKind)
, m_ByteOrder(a_byteOrder)
, m_DynArraySizeMethod(a_dynArraySizeMethod)
{}
// ---------------------------------------------------------------
// (a_valueKind must be Unsigned, if a_dynArraySizeMethod is
// e_DynArray...)
// ---------------------------------------------------------------
LogViewXdrStandardType::LogViewXdrStandardType(const QString &a_name,
const int a_valueSize,
const int a_editSize,
const E_ValueKind a_valueKind,
const E_DynArraySizeMethod a_dynArraySizeMethod,
E_ByteOrder a_byteOrder)
: LogViewXdrElement(a_name, e_KindStandardType, "LogViewXdrStandardType")
, m_ValueSize(a_valueSize)
, m_EditSize(a_editSize)
, m_ValueKind(a_valueKind)
, m_ByteOrder(a_byteOrder)
, m_DynArraySizeMethod(a_dynArraySizeMethod)
{
}
// ---------------------------------------------------------------
uint16_t LogViewXdrStandardType::getValueSize() const
{
return m_ValueSize;
}
// ---------------------------------------------------------------
uint16_t LogViewXdrStandardType::getValueSize() const
{
return m_ValueSize;
}
// ---------------------------------------------------------------
LogViewXdrStandardType::E_ValueKind LogViewXdrStandardType::getValueKind() const
{
return m_ValueKind;
}
// ---------------------------------------------------------------
LogViewXdrStandardType::E_ValueKind LogViewXdrStandardType::getValueKind() const
{
return m_ValueKind;
}
// ---------------------------------------------------------------
void LogViewXdrStandardType::dump() const
{
INFO_LOG(m_logger) << "Element[" << getName()
<< "]: kind=" << getKindName()
<< " valueKind=" << getValueKind()
<< " valueSize=" << getValueSize()
<< " editSize=" << getEditSize()
<< " dynArrSizeMethod=" << getDynArraySizeMethod()
<< " byteOrder=" << getByteOrder();
}
// ---------------------------------------------------------------
void LogViewXdrStandardType::dump() const
{
INFO_LOG(m_logger) << "Element[" << getName() << "]: kind=" << getKindName() << " valueKind=" << getValueKind() << " valueSize=" << getValueSize()
<< " editSize=" << getEditSize() << " dynArrSizeMethod=" << getDynArraySizeMethod() << " byteOrder=" << getByteOrder();
}
// ---------------------------------------------------------------
LogViewXdrStandardType::E_DynArraySizeMethod LogViewXdrStandardType::getDynArraySizeMethod() const
{
return m_DynArraySizeMethod;
}
// ---------------------------------------------------------------
LogViewXdrStandardType::E_DynArraySizeMethod LogViewXdrStandardType::getDynArraySizeMethod() const
{
return m_DynArraySizeMethod;
}
// ---------------------------------------------------------------
LogViewXdrStandardType::E_ByteOrder LogViewXdrStandardType::getByteOrder() const
{
return m_ByteOrder;
}
// ---------------------------------------------------------------
LogViewXdrStandardType::E_ByteOrder LogViewXdrStandardType::getByteOrder() const
{
return m_ByteOrder;
}
// ---------------------------------------------------------------
// The 'real' size of the value, which will be allowd when
// editing this value
// ---------------------------------------------------------------
uint16_t LogViewXdrStandardType::getEditSize() const
{
return m_EditSize;
}
// ---------------------------------------------------------------
// The 'real' size of the value, which will be allowd when
// editing this value
// ---------------------------------------------------------------
uint16_t LogViewXdrStandardType::getEditSize() const
{
return m_EditSize;
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include "LogViewXdrElement.hpp"
@@ -29,7 +29,6 @@ namespace N_LogView
class LogViewXdrStandardType final : public LogViewXdrElement
{
public:
/**
* @author alois.wismer
* @version 1.0
@@ -130,7 +129,6 @@ namespace N_LogView
uint16_t getEditSize() const;
protected:
/**
* The size of this value as stored data. It may be bigger as the real (edit) size.
*/
@@ -144,7 +142,6 @@ namespace N_LogView
E_ByteOrder m_ByteOrder;
E_DynArraySizeMethod m_DynArraySizeMethod;
};
}
@@ -1,16 +1,16 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
#include "LogViewXdrStruct.hpp"
#include "LogViewXdrValue.hpp"
#include "LogViewXdrType.hpp"
@@ -18,88 +18,94 @@
namespace N_LogView
{
// ---------------------------------------------------------------
LogViewXdrStruct::LogViewXdrStruct(const QString& a_name, const LogViewXdrElement::E_ElementKind a_kind, uint16_t enumSize)
: LogViewXdrElement(a_name, a_kind, "LogViewXdrStruct")
, m_EnumSize(enumSize)
{
}
LogViewXdrStruct::~LogViewXdrStruct()
{
for (auto ptr : m_ChildList)
delete ptr;
}
// ---------------------------------------------------------------
void LogViewXdrStruct::addElement(const QString& a_name, const QString& a_type, const uint16_t a_arraySize, const uint16_t a_dynArrayOffset, const E_ElementKind a_kind, const int16_t a_firstBit, const int16_t a_lastBit, const bool a_isLast)
{
m_ChildList.push_back(new LogViewXdrType(a_name, a_type, a_arraySize, a_dynArrayOffset, a_kind, a_firstBit, a_lastBit, a_isLast));
}
// ---------------------------------------------------------------
void LogViewXdrStruct::addElement(const QString& a_name, const uint32_t a_value, const E_ElementKind a_kind)
{
m_ChildList.push_back(new LogViewXdrValue(a_name, a_value, a_kind));
}
// ---------------------------------------------------------------
LogViewXdrElement* LogViewXdrStruct::getChild(const uint32_t a_childIndex) const
{
if (m_ChildList.size() > a_childIndex)
return m_ChildList[a_childIndex];
return nullptr;
}
// ---------------------------------------------------------------
LogViewXdrType* LogViewXdrStruct::getChildAsType(const uint32_t a_childIndex) const
{
return static_cast<LogViewXdrType*>(getChild(a_childIndex)); // fixme: check ob es wirklich ein XdrType ist
}
// ---------------------------------------------------------------
LogViewXdrValue* LogViewXdrStruct::getChildAsValue(const uint32_t a_childIndex) const
{
return static_cast<LogViewXdrValue*>(getChild(a_childIndex)); // fixme: check ob es wirklich ein XdrValue ist
}
// ---------------------------------------------------------------
void LogViewXdrStruct::dump() const
{
INFO_LOG(m_logger) << "Element[" << getName().toStdString() << "]: kind=" << getKindName().toStdString() << " enumSize=" << getEnumSize();
INFO_LOG(m_logger) << "-------------- childs start -----------------";
std::vector<LogViewXdrElement*>::const_iterator iter = m_ChildList.begin();
while (iter != m_ChildList.end())
// ---------------------------------------------------------------
LogViewXdrStruct::LogViewXdrStruct(const QString &a_name, const LogViewXdrElement::E_ElementKind a_kind, uint16_t enumSize)
: LogViewXdrElement(a_name, a_kind, "LogViewXdrStruct")
, m_EnumSize(enumSize)
{
(*iter)->dump();
++iter;
}
INFO_LOG(m_logger) << "-------------- childs end -----------------";
}
// ---------------------------------------------------------------
uint32_t LogViewXdrStruct::getChildValue(const QString& a_name, bool* a_error) const
{
if (a_error)
*a_error = false;
std::vector<LogViewXdrElement*>::const_iterator iter = m_ChildList.begin();
while (iter != m_ChildList.end())
LogViewXdrStruct::~LogViewXdrStruct()
{
if ((*iter)->getName() == a_name)
return static_cast<const LogViewXdrValue*>(*iter)->getValue();
++iter;
for (auto ptr : m_ChildList)
delete ptr;
}
// ---------------------------------------------------------------
void LogViewXdrStruct::addElement(const QString &a_name,
const QString &a_type,
const uint16_t a_arraySize,
const uint16_t a_dynArrayOffset,
const E_ElementKind a_kind,
const int16_t a_firstBit,
const int16_t a_lastBit,
const bool a_isLast)
{
m_ChildList.push_back(new LogViewXdrType(a_name, a_type, a_arraySize, a_dynArrayOffset, a_kind, a_firstBit, a_lastBit, a_isLast));
}
// ---------------------------------------------------------------
void LogViewXdrStruct::addElement(const QString &a_name, const uint32_t a_value, const E_ElementKind a_kind)
{
m_ChildList.push_back(new LogViewXdrValue(a_name, a_value, a_kind));
}
// ---------------------------------------------------------------
LogViewXdrElement *LogViewXdrStruct::getChild(const uint32_t a_childIndex) const
{
if (m_ChildList.size() > a_childIndex)
return m_ChildList[a_childIndex];
return nullptr;
}
// ---------------------------------------------------------------
LogViewXdrType *LogViewXdrStruct::getChildAsType(const uint32_t a_childIndex) const
{
return static_cast<LogViewXdrType *>(getChild(a_childIndex)); // fixme: check ob es wirklich ein XdrType ist
}
// ---------------------------------------------------------------
LogViewXdrValue *LogViewXdrStruct::getChildAsValue(const uint32_t a_childIndex) const
{
return static_cast<LogViewXdrValue *>(getChild(a_childIndex)); // fixme: check ob es wirklich ein XdrValue ist
}
// ---------------------------------------------------------------
void LogViewXdrStruct::dump() const
{
INFO_LOG(m_logger) << "Element[" << getName().toStdString() << "]: kind=" << getKindName().toStdString() << " enumSize=" << getEnumSize();
INFO_LOG(m_logger) << "-------------- childs start -----------------";
std::vector<LogViewXdrElement *>::const_iterator iter = m_ChildList.begin();
while (iter != m_ChildList.end())
{
(*iter)->dump();
++iter;
}
INFO_LOG(m_logger) << "-------------- childs end -----------------";
}
// ---------------------------------------------------------------
uint32_t LogViewXdrStruct::getChildValue(const QString &a_name, bool *a_error) const
{
if (a_error)
*a_error = false;
std::vector<LogViewXdrElement *>::const_iterator iter = m_ChildList.begin();
while (iter != m_ChildList.end())
{
if ((*iter)->getName() == a_name)
return static_cast<const LogViewXdrValue *>(*iter)->getValue();
++iter;
}
if (a_error)
*a_error = true;
return 0;
}
if (a_error)
*a_error = true;
return 0;
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include <QtCore/QString>
@@ -39,27 +39,32 @@ namespace N_LogView
class LogViewXdrStruct final : public LogViewXdrElement
{
public:
LogViewXdrStruct(const QString& a_name, const LogViewXdrElement::E_ElementKind a_kind, uint16_t enumSize = 0);
LogViewXdrStruct(const QString &a_name, const LogViewXdrElement::E_ElementKind a_kind, uint16_t enumSize = 0);
~LogViewXdrStruct();
void addElement(const QString& a_name, const QString& a_type, const uint16_t a_arraySize, const uint16_t a_dynArrayOffset, const E_ElementKind a_kind, const int16_t a_firstBit = -1, const int16_t a_lastBit = -1, const bool a_isLast = true);
void addElement(const QString& a_name, const uint32_t a_value, const E_ElementKind a_kind);
void addElement(const QString &a_name,
const QString &a_type,
const uint16_t a_arraySize,
const uint16_t a_dynArrayOffset,
const E_ElementKind a_kind,
const int16_t a_firstBit = -1,
const int16_t a_lastBit = -1,
const bool a_isLast = true);
void addElement(const QString &a_name, const uint32_t a_value, const E_ElementKind a_kind);
LogViewXdrElement* getChild(const uint32_t a_childIndex) const;
LogViewXdrType* getChildAsType(const uint32_t a_childIndex) const;
LogViewXdrValue* getChildAsValue(const uint32_t a_childIndex) const;
LogViewXdrElement *getChild(const uint32_t a_childIndex) const;
LogViewXdrType *getChildAsType(const uint32_t a_childIndex) const;
LogViewXdrValue *getChildAsValue(const uint32_t a_childIndex) const;
void dump() const override;
uint32_t getChildValue(const QString& a_name, bool* a_error = nullptr) const;
uint32_t getChildValue(const QString &a_name, bool *a_error = nullptr) const;
uint16_t getEnumSize() const { return m_EnumSize; }
protected:
uint16_t m_EnumSize;
std::vector<LogViewXdrElement*> m_ChildList;
std::vector<LogViewXdrElement *> m_ChildList;
};
}
@@ -1,106 +1,104 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
#include "LogViewXdrType.hpp"
namespace N_LogView
{
// ---------------------------------------------------------------
LogViewXdrType::LogViewXdrType(const QString& a_name, const QString& a_type, const uint16_t a_arraySize, const uint16_t a_dynArrayOffset, const E_ElementKind a_kind)
: LogViewXdrElement(a_name, a_kind, "LogViewXdrElement")
, m_Type(a_type)
, m_ArraySize(a_arraySize)
, m_MaxArraySize(a_dynArrayOffset)
, m_FirstBit(-1)
, m_LastBit(-1)
, m_IsLast(true)
{
}
// ---------------------------------------------------------------
LogViewXdrType::LogViewXdrType(const QString& a_name, const QString& a_type, const uint16_t a_arraySize, const uint16_t a_dynArrayOffset, const E_ElementKind a_kind, const int16_t a_firstBit, const int16_t a_lastBit, const bool a_isLast)
: LogViewXdrElement(a_name, a_kind, "LogViewXdrType")
, m_Type(a_type)
, m_ArraySize(a_arraySize)
, m_MaxArraySize(a_dynArrayOffset)
, m_FirstBit(a_firstBit)
, m_LastBit(a_lastBit)
, m_IsLast(a_isLast)
{
}
// ---------------------------------------------------------------
void LogViewXdrType::dump() const
{
INFO_LOG(m_logger) << "Element[" << getName()
<< "]: kind=" << getKindName()
<< " type=" << getType()
<< " arraySize=" << getArraySize()
<< " maxArraySize=" << getMaxArraySize()
<< " firstBit=" << m_FirstBit
<< " lastBit=" << m_LastBit
<< " isLast=" << m_IsLast;
}
// ---------------------------------------------------------------
const QString& LogViewXdrType::getType() const
{
return m_Type;
}
// ---------------------------------------------------------------
// 0 => opaque
// 1 => normal (scalar) element
// >1 => array
// ---------------------------------------------------------------
uint16_t LogViewXdrType::getArraySize() const
{
return m_ArraySize;
}
// ---------------------------------------------------------------
bool LogViewXdrType::maskValue(uint32_t& a_value, const uint16_t a_size, QString& a_tooltip) const
{
// INFO_LOG(m_logger) << "firstBit=" << m_FirstBit << " lastBit=" << m_LastBit << " isLast=" << m_IsLast;
if (m_FirstBit != -1 && m_LastBit != -1)
// ---------------------------------------------------------------
LogViewXdrType::LogViewXdrType(const QString &a_name, const QString &a_type, const uint16_t a_arraySize, const uint16_t a_dynArrayOffset, const E_ElementKind a_kind)
: LogViewXdrElement(a_name, a_kind, "LogViewXdrElement")
, m_Type(a_type)
, m_ArraySize(a_arraySize)
, m_MaxArraySize(a_dynArrayOffset)
, m_FirstBit(-1)
, m_LastBit(-1)
, m_IsLast(true)
{
DEBUG_LOG(m_logger) << "MaskValue for Element " << m_Name
<< " type: " << m_Type
<< " size: " << m_ArraySize
<< " first:last " << m_FirstBit << ":" << m_LastBit
<< " isLast: " << m_IsLast;
uint16_t bitshift = (a_size*8)-m_LastBit-1;
uint32_t mask = (1<<(m_LastBit-m_FirstBit+1))-1;
// INFO_LOG(m_logger) << "value=" << a_value << " bitshift=" << bitshift << " mask=" << mask;
a_value = (a_value >> bitshift) & mask;
// make bold the corresponding bits in the bitfield
a_tooltip.insert(a_tooltip.length()-(a_size*8)+m_FirstBit, QLatin1String("<b>"));
a_tooltip.insert(a_tooltip.length()-(a_size*8)+m_LastBit+1, QLatin1String("</b>"));
return m_IsLast;
}
return true;
}
// ---------------------------------------------------------------
uint16_t LogViewXdrType::getMaxArraySize() const
{
return m_MaxArraySize;
}
// ---------------------------------------------------------------
LogViewXdrType::LogViewXdrType(const QString &a_name,
const QString &a_type,
const uint16_t a_arraySize,
const uint16_t a_dynArrayOffset,
const E_ElementKind a_kind,
const int16_t a_firstBit,
const int16_t a_lastBit,
const bool a_isLast)
: LogViewXdrElement(a_name, a_kind, "LogViewXdrType")
, m_Type(a_type)
, m_ArraySize(a_arraySize)
, m_MaxArraySize(a_dynArrayOffset)
, m_FirstBit(a_firstBit)
, m_LastBit(a_lastBit)
, m_IsLast(a_isLast)
{
}
// ---------------------------------------------------------------
void LogViewXdrType::dump() const
{
INFO_LOG(m_logger) << "Element[" << getName() << "]: kind=" << getKindName() << " type=" << getType() << " arraySize=" << getArraySize()
<< " maxArraySize=" << getMaxArraySize() << " firstBit=" << m_FirstBit << " lastBit=" << m_LastBit << " isLast=" << m_IsLast;
}
// ---------------------------------------------------------------
const QString &LogViewXdrType::getType() const
{
return m_Type;
}
// ---------------------------------------------------------------
// 0 => opaque
// 1 => normal (scalar) element
// >1 => array
// ---------------------------------------------------------------
uint16_t LogViewXdrType::getArraySize() const
{
return m_ArraySize;
}
// ---------------------------------------------------------------
bool LogViewXdrType::maskValue(uint32_t &a_value, const uint16_t a_size, QString &a_tooltip) const
{
// INFO_LOG(m_logger) << "firstBit=" << m_FirstBit << " lastBit=" << m_LastBit << " isLast=" << m_IsLast;
if (m_FirstBit != -1 && m_LastBit != -1)
{
DEBUG_LOG(m_logger) << "MaskValue for Element " << m_Name << " type: " << m_Type << " size: " << m_ArraySize << " first:last " << m_FirstBit << ":" << m_LastBit
<< " isLast: " << m_IsLast;
uint16_t bitshift = (a_size * 8) - m_LastBit - 1;
uint32_t mask = (1 << (m_LastBit - m_FirstBit + 1)) - 1;
// INFO_LOG(m_logger) << "value=" << a_value << " bitshift=" << bitshift << " mask=" << mask;
a_value = (a_value >> bitshift) & mask;
// make bold the corresponding bits in the bitfield
a_tooltip.insert(a_tooltip.length() - (a_size * 8) + m_FirstBit, QLatin1String("<b>"));
a_tooltip.insert(a_tooltip.length() - (a_size * 8) + m_LastBit + 1, QLatin1String("</b>"));
return m_IsLast;
}
return true;
}
// ---------------------------------------------------------------
uint16_t LogViewXdrType::getMaxArraySize() const
{
return m_MaxArraySize;
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include "LogViewXdrElement.hpp"
@@ -32,7 +32,6 @@ namespace N_LogView
class LogViewXdrType final : public LogViewXdrElement
{
public:
/**
*
* @param a_name
@@ -41,7 +40,7 @@ namespace N_LogView
* @param a_dynArrayOffset
* @param a_kind
*/
LogViewXdrType(const QString& a_name, const QString& a_type, const uint16_t a_arraySize, const uint16_t a_dynArrayOffset, const E_ElementKind a_kind);
LogViewXdrType(const QString &a_name, const QString &a_type, const uint16_t a_arraySize, const uint16_t a_dynArrayOffset, const E_ElementKind a_kind);
/**
*
@@ -54,13 +53,20 @@ namespace N_LogView
* @param a_lastBit
* @param a_isLast
*/
LogViewXdrType(const QString& a_name, const QString& a_type, const uint16_t a_arraySize, const uint16_t a_dynArrayOffset, const E_ElementKind a_kind, const int16_t a_firstBit, const int16_t a_lastBit, const bool a_isLast);
LogViewXdrType(const QString &a_name,
const QString &a_type,
const uint16_t a_arraySize,
const uint16_t a_dynArrayOffset,
const E_ElementKind a_kind,
const int16_t a_firstBit,
const int16_t a_lastBit,
const bool a_isLast);
void dump() const override;
const QString& getType() const;
const QString &getType() const;
/**
* 0 => opaque
@@ -75,13 +81,12 @@ namespace N_LogView
* @param a_size
* @param a_tooltip
*/
bool maskValue(uint32_t& a_value, const uint16_t a_size, QString& a_tooltip) const;
bool maskValue(uint32_t &a_value, const uint16_t a_size, QString &a_tooltip) const;
uint16_t getMaxArraySize() const;
protected:
QString m_Type;
/**
* 0 => opaque
@@ -108,4 +113,3 @@ namespace N_LogView
};
}
@@ -1,40 +1,41 @@
// **************************************************************************
//
//
// (C) Copyright 2009 Swiss SIMTEC AG
//
//
// **************************************************************************
//
//
// $HeadURL$
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
//
//
// **************************************************************************
#include "LogViewXdrValue.hpp"
namespace N_LogView
{
// ---------------------------------------------------------------
LogViewXdrValue::LogViewXdrValue(const QString& a_name, const int64_t a_value, const LogViewXdrElement::E_ElementKind a_kind)
: LogViewXdrElement(a_name, a_kind, "LogViewXdrValue")
, m_Value(a_value)
{}
// ---------------------------------------------------------------
LogViewXdrValue::LogViewXdrValue(const QString &a_name, const int64_t a_value, const LogViewXdrElement::E_ElementKind a_kind)
: LogViewXdrElement(a_name, a_kind, "LogViewXdrValue")
, m_Value(a_value)
{
}
// ---------------------------------------------------------------
void LogViewXdrValue::dump() const
{
INFO_LOG(m_logger) << "Element[" << getName() << "]: kind=" << getKindName() << " value=" << getValue();
}
// ---------------------------------------------------------------
void LogViewXdrValue::dump() const
{
INFO_LOG(m_logger) << "Element[" << getName() << "]: kind=" << getKindName() << " value=" << getValue();
}
// ---------------------------------------------------------------
int64_t LogViewXdrValue::getValue() const
{
return m_Value;
}
// ---------------------------------------------------------------
int64_t LogViewXdrValue::getValue() const
{
return m_Value;
}
} // namespace N_LogView
@@ -10,7 +10,7 @@
// $LastChangedRevision$
//
// **************************************************************************
#pragma once
#include "LogViewXdrElement.hpp"
@@ -28,13 +28,12 @@ namespace N_LogView
class LogViewXdrValue final : public LogViewXdrElement
{
public:
LogViewXdrValue(const QString& a_name, const int64_t a_value, const LogViewXdrElement::E_ElementKind a_kind);
LogViewXdrValue(const QString &a_name, const int64_t a_value, const LogViewXdrElement::E_ElementKind a_kind);
void dump() const override;
int64_t getValue() const;
protected:
int64_t m_Value;
};
}
@@ -13,25 +13,24 @@
namespace N_LogView
{
LOGGER_T getLogger(const char *name)
{
static const char ns[] = "LogView.";
std::string loggerName;
const size_t len = strlen(name);
loggerName.reserve(sizeof(ns) + len);
loggerName.append(ns, sizeof(ns) - 1);
loggerName.append(name, len);
LOGGER_T getLogger(const char *name)
{
static const char ns[] = "LogView.";
std::string loggerName;
const size_t len = strlen(name);
loggerName.reserve(sizeof(ns) + len);
loggerName.append(ns, sizeof(ns) - 1);
loggerName.append(name, len);
try
{
return NGL::NGLLoggerBootstrap::getNGLRootLogger().
getNGLLogger(loggerName);
try
{
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(loggerName);
}
catch (const std::exception &ex)
{
fprintf(stderr, "Error retrieving logger: %s", ex.what());
abort();
}
}
catch (const std::exception &ex)
{
fprintf(stderr, "Error retrieving logger: %s", ex.what());
abort();
}
}
} // namespace LogView
@@ -12,11 +12,11 @@
namespace N_LogView
{
typedef NGL::INGLLogger &LOGGER_T;
typedef NGL::INGLLogger &LOGGER_T;
LOGGER_T getLogger(const char *name);
inline LOGGER_T getLogger(const QString &loggerName)
{
return getLogger(loggerName.toUtf8().constData());
}
LOGGER_T getLogger(const char *name);
inline LOGGER_T getLogger(const QString &loggerName)
{
return getLogger(loggerName.toUtf8().constData());
}
} // namespace LogView