GUI: Refactorizations

This commit is contained in:
PKEuS 2017-08-03 12:39:31 +02:00
parent dfc48be70e
commit b4cf79f1b7
13 changed files with 63 additions and 64 deletions

View File

@ -52,7 +52,7 @@ bool ApplicationList::loadSettings()
bool succeeded = true; bool succeeded = true;
if (!names.empty() && !paths.empty() && params.empty()) { if (!names.empty() && !paths.empty() && params.empty()) {
for (int i = 0; i < paths.length(); i++) for (int i = 0; i < paths.length(); i++)
params << ""; params << QString();
succeeded = false; succeeded = false;
} }

View File

@ -104,7 +104,7 @@ void CheckThread::run()
a = addonPath + '/' + addon + '/' + addon + ".py"; a = addonPath + '/' + addon + '/' + addon + ".py";
else else
continue; continue;
QString dumpFile = QString::fromStdString(file + ".dump"); QString dumpFile = file + ".dump";
QString cmd = "python " + a + ' ' + dumpFile; QString cmd = "python " + a + ' ' + dumpFile;
qDebug() << cmd; qDebug() << cmd;
process.start(cmd); process.start(cmd);

View File

@ -26,10 +26,10 @@
QString getPath(const QString &type) QString getPath(const QString &type)
{ {
QSettings settings; QSettings settings;
QString path = settings.value(type, "").toString(); QString path = settings.value(type, QString()).toString();
if (path.isEmpty()) { if (path.isEmpty()) {
// if not set, fallback to last check path hoping that it will be close enough // if not set, fallback to last check path hoping that it will be close enough
path = settings.value(SETTINGS_LAST_CHECK_PATH, "").toString(); path = settings.value(SETTINGS_LAST_CHECK_PATH, QString()).toString();
if (path.isEmpty()) if (path.isEmpty())
// if not set, return user's home directory as the best we can do for now // if not set, return user's home directory as the best we can do for now
return QDir::homePath(); return QDir::homePath();

View File

@ -67,6 +67,5 @@ void FileViewDialog::loadTextFile(const QString &filename, QTextEdit *edit)
QByteArray filedata = file.readAll(); QByteArray filedata = file.readAll();
file.close(); file.close();
QString filestringdata(filedata); edit->setPlainText(filedata);
edit->setPlainText(filestringdata);
} }

View File

@ -66,7 +66,7 @@ void LogView::clearButtonClicked()
void LogView::saveButtonClicked() void LogView::saveButtonClicked()
{ {
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Log"), QString fileName = QFileDialog::getSaveFileName(this, tr("Save Log"),
"", tr("Text files (*.txt *.log);;All files (*.*)")); QString(), tr("Text files (*.txt *.log);;All files (*.*)"));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {

View File

@ -554,7 +554,7 @@ void MainWindow::analyzeFiles()
{ {
QStringList selected = selectFilesToAnalyze(QFileDialog::ExistingFiles); QStringList selected = selectFilesToAnalyze(QFileDialog::ExistingFiles);
const QString file0 = (selected.size() ? selected[0].toLower() : ""); const QString file0 = (selected.size() ? selected[0].toLower() : QString());
if (file0.endsWith(".sln") || file0.endsWith(".vcxproj") || file0.endsWith(compile_commands_json)) { if (file0.endsWith(".sln") || file0.endsWith(".vcxproj") || file0.endsWith(compile_commands_json)) {
ImportProject p; ImportProject p;
p.import(selected[0].toStdString()); p.import(selected[0].toStdString());

View File

@ -156,7 +156,7 @@ bool ProjectFile::read(const QString &filename)
void ProjectFile::readRootPath(QXmlStreamReader &reader) void ProjectFile::readRootPath(QXmlStreamReader &reader)
{ {
QXmlStreamAttributes attribs = reader.attributes(); QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value("", RootPathNameAttrib).toString(); QString name = attribs.value(QString(), RootPathNameAttrib).toString();
if (!name.isEmpty()) if (!name.isEmpty())
mRootPath = name; mRootPath = name;
} }
@ -223,7 +223,7 @@ void ProjectFile::readIncludeDirs(QXmlStreamReader &reader)
// Read dir-elements // Read dir-elements
if (reader.name().toString() == DirElementName) { if (reader.name().toString() == DirElementName) {
QXmlStreamAttributes attribs = reader.attributes(); QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value("", DirNameAttrib).toString(); QString name = attribs.value(QString(), DirNameAttrib).toString();
if (!name.isEmpty()) if (!name.isEmpty())
mIncludeDirs << name; mIncludeDirs << name;
} }
@ -260,7 +260,7 @@ void ProjectFile::readDefines(QXmlStreamReader &reader)
// Read define-elements // Read define-elements
if (reader.name().toString() == DefineName) { if (reader.name().toString() == DefineName) {
QXmlStreamAttributes attribs = reader.attributes(); QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value("", DefineNameAttrib).toString(); QString name = attribs.value(QString(), DefineNameAttrib).toString();
if (!name.isEmpty()) if (!name.isEmpty())
mDefines << name; mDefines << name;
} }
@ -298,7 +298,7 @@ void ProjectFile::readCheckPaths(QXmlStreamReader &reader)
// Read dir-elements // Read dir-elements
if (reader.name().toString() == PathName) { if (reader.name().toString() == PathName) {
QXmlStreamAttributes attribs = reader.attributes(); QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value("", PathNameAttrib).toString(); QString name = attribs.value(QString(), PathNameAttrib).toString();
if (!name.isEmpty()) if (!name.isEmpty())
mPaths << name; mPaths << name;
} }
@ -335,14 +335,14 @@ void ProjectFile::readExcludes(QXmlStreamReader &reader)
// Read exclude-elements // Read exclude-elements
if (reader.name().toString() == ExcludePathName) { if (reader.name().toString() == ExcludePathName) {
QXmlStreamAttributes attribs = reader.attributes(); QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value("", ExcludePathNameAttrib).toString(); QString name = attribs.value(QString(), ExcludePathNameAttrib).toString();
if (!name.isEmpty()) if (!name.isEmpty())
mExcludedPaths << name; mExcludedPaths << name;
} }
// Read ignore-elements - deprecated but support reading them // Read ignore-elements - deprecated but support reading them
else if (reader.name().toString() == IgnorePathName) { else if (reader.name().toString() == IgnorePathName) {
QXmlStreamAttributes attribs = reader.attributes(); QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value("", IgnorePathNameAttrib).toString(); QString name = attribs.value(QString(), IgnorePathNameAttrib).toString();
if (!name.isEmpty()) if (!name.isEmpty())
mExcludedPaths << name; mExcludedPaths << name;
} }

View File

@ -316,7 +316,7 @@ QString ResultsTree::severityToTranslatedString(Severity::SeverityType severity)
case Severity::none: case Severity::none:
default: default:
return ""; return QString();
} }
} }
@ -1033,7 +1033,7 @@ QString ResultsTree::severityToIcon(Severity::SeverityType severity) const
case Severity::information: case Severity::information:
return ":images/dialog-information.png"; return ":images/dialog-information.png";
default: default:
return ""; return QString();
} }
} }

View File

@ -77,7 +77,7 @@ void ResultsView::clear(bool results)
mUI.mTree->clear(); mUI.mTree->clear();
} }
mUI.mDetails->setText(""); mUI.mDetails->setText(QString());
mStatistics->clear(); mStatistics->clear();
@ -363,7 +363,7 @@ void ResultsView::readErrorsXml(const QString &filename)
foreach (item, errors) { foreach (item, errors) {
mUI.mTree->addErrorItem(item); mUI.mTree->addErrorItem(item);
} }
mUI.mTree->setCheckDirectory(""); mUI.mTree->setCheckDirectory(QString());
} }
void ResultsView::updateDetails(const QModelIndex &index) void ResultsView::updateDetails(const QModelIndex &index)
@ -372,7 +372,7 @@ void ResultsView::updateDetails(const QModelIndex &index)
QStandardItem *item = model->itemFromIndex(index); QStandardItem *item = model->itemFromIndex(index);
if (!item) { if (!item) {
mUI.mDetails->setText(""); mUI.mDetails->setText(QString());
return; return;
} }
@ -384,7 +384,7 @@ void ResultsView::updateDetails(const QModelIndex &index)
// If there is no severity data then it is a parent item without summary and message // If there is no severity data then it is a parent item without summary and message
if (!data.contains("severity")) { if (!data.contains("severity")) {
mUI.mDetails->setText(""); mUI.mDetails->setText(QString());
return; return;
} }
@ -395,7 +395,7 @@ void ResultsView::updateDetails(const QModelIndex &index)
.arg(tr("Message")).arg(message); .arg(tr("Message")).arg(message);
const QString file0 = data["file0"].toString(); const QString file0 = data["file0"].toString();
if (file0 != "" && Path::isHeader(data["file"].toString().toStdString())) if (!file0.isEmpty() && Path::isHeader(data["file"].toString().toStdString()))
formattedMsg += QString("\n\n%1: %2").arg(tr("First included by")).arg(QDir::toNativeSeparators(file0)); formattedMsg += QString("\n\n%1: %2").arg(tr("First included by")).arg(QDir::toNativeSeparators(file0));
if (mUI.mTree->showIdColumn()) if (mUI.mTree->showIdColumn())

View File

@ -47,10 +47,10 @@ void StatsDialog::setProject(const ProjectFile* projectFile)
mUI.mIncludePaths->setText(projectFile->getIncludeDirs().join(";")); mUI.mIncludePaths->setText(projectFile->getIncludeDirs().join(";"));
mUI.mDefines->setText(projectFile->getDefines().join(";")); mUI.mDefines->setText(projectFile->getDefines().join(";"));
} else { } else {
mUI.mProject->setText(""); mUI.mProject->setText(QString());
mUI.mPaths->setText(""); mUI.mPaths->setText(QString());
mUI.mIncludePaths->setText(""); mUI.mIncludePaths->setText(QString());
mUI.mDefines->setText(""); mUI.mDefines->setText(QString());
} }
} }

View File

@ -71,7 +71,7 @@ QString ThreadResult::getNextFile()
{ {
QMutexLocker locker(&mutex); QMutexLocker locker(&mutex);
if (mFiles.isEmpty()) { if (mFiles.isEmpty()) {
return ""; return QString();
} }
return mFiles.takeFirst(); return mFiles.takeFirst();

View File

@ -68,7 +68,7 @@ int XmlReport::determineVersion(const QString &filename)
if (reader.name() == ResultElementName) { if (reader.name() == ResultElementName) {
QXmlStreamAttributes attribs = reader.attributes(); QXmlStreamAttributes attribs = reader.attributes();
if (attribs.hasAttribute(QString(VersionAttribute))) { if (attribs.hasAttribute(QString(VersionAttribute))) {
int ver = attribs.value("", VersionAttribute).toString().toInt(); int ver = attribs.value(QString(), VersionAttribute).toString().toInt();
return ver; return ver;
} else } else
return 1; return 1;

View File

@ -28,25 +28,25 @@
#include "xmlreportv2.h" #include "xmlreportv2.h"
#include "cppcheck.h" #include "cppcheck.h"
static const char ResultElementName[] = "results"; static const QString ResultElementName = "results";
static const char CppcheckElementName[] = "cppcheck"; static const QString CppcheckElementName = "cppcheck";
static const char ErrorElementName[] = "error"; static const QString ErrorElementName = "error";
static const char ErrorsElementName[] = "errors"; static const QString ErrorsElementName = "errors";
static const char LocationElementName[] = "location"; static const QString LocationElementName = "location";
static const char ColAttribute[] = "col"; static const QString ColAttribute = "col";
static const char CWEAttribute[] = "cwe"; static const QString CWEAttribute = "cwe";
static const char SinceDateAttribute[] = "sinceDate"; static const QString SinceDateAttribute = "sinceDate";
static const char TagAttribute[] = "tag"; static const QString TagAttribute = "tag";
static const char FilenameAttribute[] = "file"; static const QString FilenameAttribute = "file";
static const char IncludedFromFilenameAttribute[] = "file0"; static const QString IncludedFromFilenameAttribute = "file0";
static const char InconclusiveAttribute[] = "inconclusive"; static const QString InconclusiveAttribute = "inconclusive";
static const char InfoAttribute[] = "info"; static const QString InfoAttribute = "info";
static const char LineAttribute[] = "line"; static const QString LineAttribute = "line";
static const char IdAttribute[] = "id"; static const QString IdAttribute = "id";
static const char SeverityAttribute[] = "severity"; static const QString SeverityAttribute = "severity";
static const char MsgAttribute[] = "msg"; static const QString MsgAttribute = "msg";
static const char VersionAttribute[] = "version"; static const QString VersionAttribute = "version";
static const char VerboseAttribute[] = "verbose"; static const QString VerboseAttribute = "verbose";
XmlReportV2::XmlReportV2(const QString &filename) : XmlReportV2::XmlReportV2(const QString &filename) :
XmlReport(filename), XmlReport(filename),
@ -209,20 +209,20 @@ ErrorItem XmlReportV2::readError(QXmlStreamReader *reader)
// Read error element from inside errors element // Read error element from inside errors element
if (mXmlReader->name() == ErrorElementName) { if (mXmlReader->name() == ErrorElementName) {
QXmlStreamAttributes attribs = reader->attributes(); QXmlStreamAttributes attribs = reader->attributes();
item.errorId = attribs.value("", IdAttribute).toString(); item.errorId = attribs.value(QString(), IdAttribute).toString();
item.severity = GuiSeverity::fromString(attribs.value("", SeverityAttribute).toString()); item.severity = GuiSeverity::fromString(attribs.value(QString(), SeverityAttribute).toString());
const QString summary = attribs.value("", MsgAttribute).toString(); const QString summary = attribs.value(QString(), MsgAttribute).toString();
item.summary = XmlReport::unquoteMessage(summary); item.summary = XmlReport::unquoteMessage(summary);
const QString message = attribs.value("", VerboseAttribute).toString(); const QString message = attribs.value(QString(), VerboseAttribute).toString();
item.message = XmlReport::unquoteMessage(message); item.message = XmlReport::unquoteMessage(message);
if (attribs.hasAttribute("", InconclusiveAttribute)) if (attribs.hasAttribute(QString(), InconclusiveAttribute))
item.inconclusive = true; item.inconclusive = true;
if (attribs.hasAttribute("", CWEAttribute)) if (attribs.hasAttribute(QString(), CWEAttribute))
item.cwe = attribs.value("", CWEAttribute).toString().toInt(); item.cwe = attribs.value(QString(), CWEAttribute).toString().toInt();
if (attribs.hasAttribute("", SinceDateAttribute)) if (attribs.hasAttribute(QString(), SinceDateAttribute))
item.sinceDate = attribs.value("", SinceDateAttribute).toString(); item.sinceDate = attribs.value(QString(), SinceDateAttribute).toString();
if (attribs.hasAttribute("", TagAttribute)) { if (attribs.hasAttribute(QString(), TagAttribute)) {
const QString tag = attribs.value("", TagAttribute).toString(); const QString tag = attribs.value(QString(), TagAttribute).toString();
if (tag == "fp") if (tag == "fp")
item.tag = ErrorItem::FP; item.tag = ErrorItem::FP;
else if (tag == "ignore") else if (tag == "ignore")
@ -240,16 +240,16 @@ ErrorItem XmlReportV2::readError(QXmlStreamReader *reader)
// Read location element from inside error element // Read location element from inside error element
if (mXmlReader->name() == LocationElementName) { if (mXmlReader->name() == LocationElementName) {
QXmlStreamAttributes attribs = mXmlReader->attributes(); QXmlStreamAttributes attribs = mXmlReader->attributes();
QString file0 = attribs.value("", IncludedFromFilenameAttribute).toString(); QString file0 = attribs.value(QString(), IncludedFromFilenameAttribute).toString();
if (!file0.isEmpty()) if (!file0.isEmpty())
item.file0 = XmlReport::unquoteMessage(file0); item.file0 = XmlReport::unquoteMessage(file0);
QErrorPathItem loc; QErrorPathItem loc;
loc.file = XmlReport::unquoteMessage(attribs.value("", FilenameAttribute).toString()); loc.file = XmlReport::unquoteMessage(attribs.value(QString(), FilenameAttribute).toString());
loc.line = attribs.value("", LineAttribute).toString().toUInt(); loc.line = attribs.value(QString(), LineAttribute).toString().toUInt();
if (attribs.hasAttribute("", ColAttribute)) if (attribs.hasAttribute(QString(), ColAttribute))
loc.col = attribs.value("", ColAttribute).toString().toInt(); loc.col = attribs.value(QString(), ColAttribute).toString().toInt();
if (attribs.hasAttribute("", InfoAttribute)) if (attribs.hasAttribute(QString(), InfoAttribute))
loc.info = XmlReport::unquoteMessage(attribs.value("", InfoAttribute).toString()); loc.info = XmlReport::unquoteMessage(attribs.value(QString(), InfoAttribute).toString());
item.errorPath.push_front(loc); item.errorPath.push_front(loc);
} }
break; break;