GUI: Sent ErrorItem with Error -signal.

This commit modifies and registers ErrorItem as proper metatype so it
can be used with Qt signals. Then sending Error-signals is refactored
so that ErrorItem instances are sent instead of several different
arguments that already contained couple of lists.
This commit is contained in:
Kimmo Varis 2010-07-14 14:24:46 +03:00
parent bea714445a
commit 6c6ab0a78d
7 changed files with 29 additions and 58 deletions

View File

@ -21,6 +21,7 @@
#include <QString>
#include <QStringList>
#include <QMetaType>
class ErrorLine;
@ -36,6 +37,7 @@ public:
ErrorItem() { }
ErrorItem(const ErrorItem &item);
ErrorItem(const ErrorLine &line);
~ErrorItem() { }
QString file;
QStringList files;
@ -45,6 +47,8 @@ public:
QString msg;
};
Q_DECLARE_METATYPE(ErrorItem);
/**
* @brief A class containing error data for one shown error line.
*/

View File

@ -22,6 +22,7 @@
#include <QTranslator>
#include <QMetaType>
#include "mainwindow.h"
#include "erroritem.h"
int main(int argc, char *argv[])
{
@ -29,7 +30,7 @@ int main(int argc, char *argv[])
app.setWindowIcon(QIcon(":icon.png"));
// Register this metatype that is used to transfer error info
qRegisterMetaType< QList<unsigned int> >("QList<unsigned int>");
qRegisterMetaType<ErrorItem>("ErrorItem");
// Set codecs so that UTF-8 strings in sources are handled correctly.
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));

View File

@ -20,6 +20,7 @@
#include <QVBoxLayout>
#include <QFile>
#include <QMessageBox>
#include "erroritem.h"
#include "resultsview.h"
#include "report.h"
#include "txtreport.h"
@ -66,22 +67,9 @@ void ResultsView::Progress(int value)
mUI.mProgress->setValue(value);
}
void ResultsView::Error(const QString &file,
const QString &severity,
const QString &message,
const QStringList &files,
const QList<unsigned int> &lines,
const QString &id)
void ResultsView::Error(const ErrorItem &item)
{
mErrorsFound = true;
ErrorItem item;
item.file = file;
item.files = files;
item.id = id;
item.lines = lines;
item.msg = message;
item.severity = severity;
mUI.mTree->AddErrorItem(item);
emit GotResults();
}

View File

@ -29,6 +29,8 @@
#include "report.h"
#include "ui_resultsview.h"
class ErrorItem;
/// @addtogroup GUI
/// @{
@ -158,19 +160,9 @@ public slots:
/**
* @brief Slot for new error to be displayed
*
* @param file filename
* @param severity error severity
* @param message error message
* @param files list of files affected by the error
* @param lines list of file line numers affected by the error
* @param id error id
* @param item Error data
*/
void Error(const QString &file,
const QString &severity,
const QString &message,
const QStringList &files,
const QList<unsigned int> &lines,
const QString &id);
void Error(const ErrorItem &item);
/**
* @brief Collapse all results in the result list.

View File

@ -141,18 +141,8 @@ void ThreadHandler::Initialize(ResultsView *view)
connect(&mResults, SIGNAL(Progress(int)),
view, SLOT(Progress(int)));
connect(&mResults, SIGNAL(Error(const QString &,
const QString &,
const QString &,
const QStringList &,
const QList<unsigned int> &,
const QString &)),
view, SLOT(Error(const QString &,
const QString &,
const QString &,
const QStringList &,
const QList<unsigned int> &,
const QString &)));
connect(&mResults, SIGNAL(Error(const ErrorItem &)),
view, SLOT(Error(const ErrorItem &)));
}

View File

@ -17,8 +17,9 @@
*/
#include "threadresult.h"
#include <QDebug>
#include "erroritem.h"
#include "threadresult.h"
ThreadResult::ThreadResult() : mMaxProgress(0), mProgress(0)
{
@ -62,12 +63,15 @@ void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
lines << (*tok).line;
}
emit Error(QString(callStackToString(msg._callStack).c_str()),
QString(msg._severity.c_str()),
QString(msg._msg.c_str()),
files,
lines,
QString(msg._id.c_str()));
ErrorItem item;
item.file = QString(callStackToString(msg._callStack).c_str());
item.files = files;
item.id = QString(msg._id.c_str());
item.lines = lines;
item.msg = QString(msg._msg.c_str());
item.severity = QString(msg._severity.c_str());
emit Error(item);
}
QString ThreadResult::GetNextFile()

View File

@ -26,6 +26,8 @@
#include <QVariant>
#include "../lib/errorlogger.h"
class ErrorItem;
/// @addtogroup GUI
/// @{
@ -87,19 +89,9 @@ signals:
/**
* @brief Signal of a new error
*
* @param file filename
* @param severity error severity
* @param message error message
* @param files list of files affected by the error
* @param lines list of file line numers affected by the error
* @param id error id
* @param item Error data
*/
void Error(const QString &file,
const QString &severity,
const QString &message,
const QStringList &files,
const QList<unsigned int> &lines,
const QString &id);
void Error(const ErrorItem &item);
protected: