void CreateLog() { Logging::CLogger& logger = Logging::CLogger::getInstance(); logger.Reset(); std::shared_ptr<Logging::CFormat> warningFormat(new Logging::CFormat(FOUR_CHAR_ID('w', 'a', 'r', 'n'))); *warningFormat.get() << new Logging::CTime() << new Logging::CText(", ") << new Logging::CText("[WARNING] - ") << new Logging::CTrace(); std::shared_ptr<Logging::CFormat> errorFormat(new Logging::CFormat(FOUR_CHAR_ID('e', 'r', 'r', 'o'))); *errorFormat.get() << new Logging::CTime() << new Logging::CText(", ") << new Logging::CText("[ERROR] - ") << new Logging::CTrace(); std::shared_ptr<Logging::CFormat> infoFormat(new Logging::CFormat(FOUR_CHAR_ID('i', 'n', 'f', 'o'))); *infoFormat.get() << new Logging::CTime() << new Logging::CText(", ") << new Logging::CText("[INFO] - ") << new Logging::CTrace(); #ifdef DEBUG std::shared_ptr<Logging::CFormat> debugFormat(new Logging::CFormat(FOUR_CHAR_ID('d', 'e', 'b', 'u'))); *debugFormat.get() << new Logging::CTime() << new Logging::CText(", ") << new Logging::CText("[DEBUG] - ") << new Logging::CTrace(); #endif std::shared_ptr<CCoutSink> sink(new CCoutSink()); //std::shared_ptr<CFileSink> fileSink(new CFileSink()); logger.AddLogger(warningFormat, sink); logger.AddLogger(errorFormat, sink); logger.AddLogger(infoFormat, sink); //logger.AddLogger(warningFormat, fileSink); //logger.AddLogger(errorFormat, fileSink); //logger.AddLogger(infoFormat, fileSink); #ifdef DEBUG logger.AddLogger(debugFormat, sink); #endif }
void QalculateHighlighter::highlightBlock(const QString& text) { if ( text.isEmpty() || text.trimmed().isEmpty() || text.startsWith(QLatin1String(">>> ")) // filter error messages, they get highlighted via html || text.startsWith(i18n("ERROR") + QLatin1Char(':')) || text.startsWith(i18n("WARNING") + QLatin1Char(':')) ) { return; } int pos = 0; int count; ///TODO: Can't we use CALCULATOR->parse() or similar? /// Question is how to get the connection between /// MathStructur and position+length in @p text const QStringList& words = text.split(QRegExp(QLatin1String("\\b")), QString::SkipEmptyParts); qDebug() << "highlight block:" << text; CALCULATOR->beginTemporaryStopMessages(); const QString decimalSymbol = QLocale().decimalPoint(); for ( int i = 0; i < words.size(); ++i, pos += count ) { count = words[i].size(); if ( words[i].trimmed().isEmpty() ) { continue; } qDebug() << "highlight word:" << words[i]; QTextCharFormat format = errorFormat(); if ( i < words.size() - 1 && words[i+1].trimmed() == QLatin1String("(") && CALCULATOR->getFunction(words[i].toUtf8().constData()) ) { // should be a function qDebug() << "function"; format = functionFormat(); } else if ( isOperatorAndWhitespace(words[i]) ) { // stuff like ") * (" is an invalid expression, but acutally OK // check if last number is actually a float bool isFloat = false; if ( words[i].trimmed() == decimalSymbol ) { if ( i > 0 ) { // lookbehind QString lastWord = words[i-1].trimmed(); if ( !lastWord.isEmpty() && lastWord.at(lastWord.size()-1).isNumber() ) { qDebug() << "actually float"; isFloat = true; } } if ( !isFloat && i < words.size() - 1 ) { // lookahead QString nextWord = words[i+1].trimmed(); if ( !nextWord.isEmpty() && nextWord.at(0).isNumber() ) { qDebug() << "float coming"; isFloat = true; } } } if ( !isFloat ) { qDebug() << "operator / whitespace"; format = operatorFormat(); } else { format = numberFormat(); } } else { MathStructure expr = CALCULATOR->parse(words[i].toLatin1().constData()); if ( expr.isNumber() || expr.isNumber_exp() ) { qDebug() << "number"; format = numberFormat(); } else if ( expr.isVariable() ) { qDebug() << "variable"; format = variableFormat(); } else if ( expr.isUndefined() ) { qDebug() << "undefined"; } else if ( expr.isUnit() || expr.isUnit_exp() ) { qDebug() << "unit"; format = keywordFormat(); } } setFormat(pos, count, format); } CALCULATOR->endTemporaryStopMessages(); }