logic: error limit and better user experience (issue #385)

* only show up to 1000 errors in table and code view
* click button in bottom right of error table to show all
* same error order in code and table
* highlight error line when switching reference in code view
* improved error view performance

bug id = 385
This commit is contained in:
Eberhard Graether
2017-05-30 23:11:20 +02:00
parent a34abe6b4b
commit 29cfbe0f66
20 changed files with 204 additions and 75 deletions
@@ -388,9 +388,11 @@ void CodeController::handleMessage(MessageShowErrors* message)
if (!view->showsErrors() || !message->errorId)
{
std::vector<ErrorInfo> errors;
m_collection = m_storageAccess->getErrorSourceLocations(&errors);
m_collection = m_storageAccess->getErrorSourceLocationsLimited(&errors);
std::vector<CodeSnippetParams> snippets = getSnippetsForCollection(m_collection);
std::sort(snippets.begin(), snippets.end(), CodeSnippetParams::sortById);
view->clear();
view->setErrorInfos(errors);
view->showCodeSnippets(
@@ -14,19 +14,36 @@ ErrorController::~ErrorController()
void ErrorController::handleMessage(MessageClearErrorCount* message)
{
clear();
getView()->resetErrorLimit();
}
void ErrorController::handleMessage(MessageFinishedParsing* message)
{
clear();
getView()->addErrors(m_storageAccess->getErrors(), false);
getView()->setErrorCount(m_storageAccess->getErrorCount());
getView()->addErrors(m_storageAccess->getErrorsLimited(), false);
}
void ErrorController::handleMessage(MessageNewErrors* message)
{
getView()->addErrors(message->errors, true);
getView()->showDockWidget();
ErrorFilter filter;
int room = message->errors.size() + filter.limit - message->errorCount.total;
if (room > 0)
{
std::vector<ErrorInfo> errors = message->errors;
if (room < int(errors.size()))
{
errors.resize(room);
}
getView()->addErrors(message->errors, true);
getView()->showDockWidget();
}
getView()->setErrorCount(message->errorCount);
}
void ErrorController::handleMessage(MessageShowErrors* message)
@@ -39,11 +56,13 @@ void ErrorController::handleMessage(MessageShowErrors* message)
clear();
std::vector<ErrorInfo> errors = m_storageAccess->getErrors();
std::vector<ErrorInfo> errors = m_storageAccess->getErrorsLimited();
if (errors.size())
{
getView()->showDockWidget();
}
getView()->setErrorCount(message->errorCount);
getView()->addErrors(errors, false);
}
+4
View File
@@ -4,6 +4,7 @@
#include <vector>
#include "component/view/View.h"
#include "data/ErrorCountInfo.h"
#include "data/ErrorInfo.h"
class ErrorView
@@ -19,6 +20,9 @@ public:
virtual void addErrors(const std::vector<ErrorInfo>& errors, bool scrollTo) = 0;
virtual void setErrorId(Id errorId) = 0;
virtual void setErrorCount(ErrorCountInfo info) = 0;
virtual void resetErrorLimit() = 0;
};
#endif // ERROR_VIEW_H
@@ -68,3 +68,9 @@ bool CodeSnippetParams::sort(const CodeSnippetParams& a, const CodeSnippetParams
return a.startLineNumber < b.startLineNumber;
}
bool CodeSnippetParams::sortById(const CodeSnippetParams& a, const CodeSnippetParams& b)
{
return a.locationFile->getSourceLocations().begin()->get()->getLocationId() <
b.locationFile->getSourceLocations().begin()->get()->getLocationId();
}
@@ -14,6 +14,7 @@ struct CodeSnippetParams
// comparefunction for snippetsorting
static bool sort(const CodeSnippetParams& a, const CodeSnippetParams& b);
static bool sortById(const CodeSnippetParams& a, const CodeSnippetParams& b);
uint startLineNumber;
uint endLineNumber;
+3
View File
@@ -11,6 +11,7 @@ struct ErrorFilter
, fatal(true)
, unindexedError(false)
, unindexedFatal(true)
, limit(1000)
{
}
@@ -32,6 +33,8 @@ struct ErrorFilter
bool unindexedError;
bool unindexedFatal;
size_t limit;
};
#endif // ERROR_FILTER_H
+39 -8
View File
@@ -417,7 +417,10 @@ void PersistentStorage::finishInjection()
if (m_preInjectionErrorCount != errors.size())
{
MessageNewErrors(std::vector<ErrorInfo>(errors.begin() + m_preInjectionErrorCount, errors.end())).dispatchImmediately();
MessageNewErrors(
std::vector<ErrorInfo>(errors.begin() + m_preInjectionErrorCount, errors.end()),
getErrorCount(errors)
).dispatch();
}
}
@@ -1424,10 +1427,14 @@ StorageStats PersistentStorage::getStorageStats() const
}
ErrorCountInfo PersistentStorage::getErrorCount() const
{
return getErrorCount(getErrors());
}
ErrorCountInfo PersistentStorage::getErrorCount(const std::vector<ErrorInfo>& errors) const
{
ErrorCountInfo info;
std::vector<ErrorInfo> errors = getErrors();
for (const ErrorInfo& error : errors)
{
info.total++;
@@ -1443,21 +1450,40 @@ ErrorCountInfo PersistentStorage::getErrorCount() const
std::vector<ErrorInfo> PersistentStorage::getErrors() const
{
std::vector<ErrorInfo> errors = m_sqliteIndexStorage.getAll<StorageError>();
std::vector<ErrorInfo> filteredErrors;
std::vector<ErrorInfo> errors;
for (const ErrorInfo& error : errors)
for (const ErrorInfo& error : m_sqliteIndexStorage.getAll<StorageError>())
{
if (m_errorFilter.filter(error))
{
filteredErrors.push_back(error);
errors.push_back(error);
}
}
return filteredErrors;
return errors;
}
std::shared_ptr<SourceLocationCollection> PersistentStorage::getErrorSourceLocations(std::vector<ErrorInfo>* errors) const
std::vector<ErrorInfo> PersistentStorage::getErrorsLimited() const
{
std::vector<ErrorInfo> errors;
for (const ErrorInfo& error : m_sqliteIndexStorage.getAll<StorageError>())
{
if (m_errorFilter.filter(error))
{
errors.push_back(error);
}
if (m_errorFilter.limit > 0 && errors.size() >= m_errorFilter.limit)
{
break;
}
}
return errors;
}
std::shared_ptr<SourceLocationCollection> PersistentStorage::getErrorSourceLocationsLimited(std::vector<ErrorInfo>* errors) const
{
TRACE();
@@ -1482,6 +1508,11 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getErrorSourceLocat
error.columnNumber
);
}
if (m_errorFilter.limit > 0 && errors->size() >= m_errorFilter.limit)
{
break;
}
}
addCompleteFlagsToSourceLocationCollection(collection.get());
+3 -2
View File
@@ -131,9 +131,10 @@ public:
virtual StorageStats getStorageStats() const;
virtual ErrorCountInfo getErrorCount() const;
virtual ErrorCountInfo getErrorCount(const std::vector<ErrorInfo>& errors) const;
virtual std::vector<ErrorInfo> getErrors() const;
virtual std::shared_ptr<SourceLocationCollection> getErrorSourceLocations(std::vector<ErrorInfo>* errors) const;
virtual std::vector<ErrorInfo> getErrorsLimited() const;
virtual std::shared_ptr<SourceLocationCollection> getErrorSourceLocationsLimited(std::vector<ErrorInfo>* errors) const;
private:
Id getFileNodeId(const FilePath& filePath) const;
+2 -3
View File
@@ -72,9 +72,8 @@ public:
virtual StorageStats getStorageStats() const = 0;
virtual ErrorCountInfo getErrorCount() const = 0;
virtual std::vector<ErrorInfo> getErrors() const = 0;
virtual std::shared_ptr<SourceLocationCollection> getErrorSourceLocations(std::vector<ErrorInfo>* errors) const = 0;
virtual std::vector<ErrorInfo> getErrorsLimited() const = 0;
virtual std::shared_ptr<SourceLocationCollection> getErrorSourceLocationsLimited(std::vector<ErrorInfo>* errors) const = 0;
virtual void setErrorFilter(const ErrorFilter& filter);
+4 -4
View File
@@ -300,21 +300,21 @@ ErrorCountInfo StorageAccessProxy::getErrorCount() const
return ErrorCountInfo();
}
std::vector<ErrorInfo> StorageAccessProxy::getErrors() const
std::vector<ErrorInfo> StorageAccessProxy::getErrorsLimited() const
{
if (hasSubject())
{
return m_subject->getErrors();;
return m_subject->getErrorsLimited();
}
return std::vector<ErrorInfo>();
}
std::shared_ptr<SourceLocationCollection> StorageAccessProxy::getErrorSourceLocations(std::vector<ErrorInfo>* errors) const
std::shared_ptr<SourceLocationCollection> StorageAccessProxy::getErrorSourceLocationsLimited(std::vector<ErrorInfo>* errors) const
{
if (hasSubject())
{
return m_subject->getErrorSourceLocations(errors);
return m_subject->getErrorSourceLocationsLimited(errors);
}
return std::make_shared<SourceLocationCollection>();
+2 -3
View File
@@ -64,9 +64,8 @@ public:
virtual StorageStats getStorageStats() const;
virtual ErrorCountInfo getErrorCount() const;
virtual std::vector<ErrorInfo> getErrors() const;
virtual std::shared_ptr<SourceLocationCollection> getErrorSourceLocations(std::vector<ErrorInfo>* errors) const;
virtual std::vector<ErrorInfo> getErrorsLimited() const;
virtual std::shared_ptr<SourceLocationCollection> getErrorSourceLocationsLimited(std::vector<ErrorInfo>* errors) const;
virtual Id addNodeBookmark(const NodeBookmark& bookmark);
virtual Id addEdgeBookmark(const EdgeBookmark& bookmark);
@@ -3,14 +3,16 @@
#include "utility/messaging/Message.h"
#include "data/ErrorCountInfo.h"
#include "data/ErrorInfo.h"
class MessageNewErrors
: public Message<MessageNewErrors>
{
public:
MessageNewErrors(const std::vector<ErrorInfo>& errors)
MessageNewErrors(const std::vector<ErrorInfo>& errors, ErrorCountInfo errorCount)
: errors(errors)
, errorCount(errorCount)
{
setSendAsTask(false);
}
@@ -26,6 +28,7 @@ public:
}
const std::vector<ErrorInfo> errors;
const ErrorCountInfo errorCount;
};
#endif // MESSAGE_NEW_ERRORS_H
@@ -1,9 +1,10 @@
#ifndef MESSAGE_SHOW_ERRORS_H
#define MESSAGE_SHOW_ERRORS_H
#include "data/ErrorCountInfo.h"
#include "utility/messaging/Message.h"
#include "data/ErrorCountInfo.h"
class MessageShowErrors
: public Message<MessageShowErrors>
{
@@ -10,6 +10,7 @@
#include "utility/logging/logging.h"
#include "utility/messaging/type/MessageCodeViewExpandedInitialFiles.h"
#include "utility/messaging/type/MessageScrollCode.h"
#include "utility/messaging/type/MessageShowErrors.h"
#include "utility/ResourcePaths.h"
#include "data/location/SourceLocation.h"
@@ -860,6 +861,11 @@ void QtCodeNavigator::handleMessage(MessageShowReference* message)
requestScroll(ref.filePath, 0, ref.locationId, message->animated, false);
emit scrollRequest();
if (ref.locationType == LOCATION_ERROR)
{
MessageShowErrors(ref.tokenId).dispatch();
}
}
updateRefLabel();
+11 -14
View File
@@ -80,31 +80,23 @@ void QtTable::updateRows()
verticalHeader()->setStyleSheet("::section { width: " + QString::number(width) + "px; }");
verticalHeader()->setDefaultSectionSize(ApplicationSettings::getInstance()->getFontSize() + 6);
if (this->selectionModel()->hasSelection())
if (this->selectionModel()->hasSelection() && selectionModel()->selection().indexes()[0].row() >= model()->rowCount() - 2)
{
if (selectionModel()->selection().indexes()[0].row() >= model()->rowCount() - 2)
{
clearSelection();
showLastRow();
}
}
else
{
showLastRow();
clearSelection();
}
}
int QtTable::getFilledRowCount()
{
for (int i = 0; i < model()->rowCount(); i++)
for (int i = model()->rowCount() - 1; i >= 0; i--)
{
if (model()->index(i, 0).data(Qt::DisplayRole).toString().isEmpty())
if (!model()->index(i, 0).data(Qt::DisplayRole).toString().isEmpty())
{
return i;
return i + 1;
}
}
return model()->rowCount();
return 0;
}
void QtTable::showFirstRow()
@@ -120,6 +112,11 @@ void QtTable::showLastRow()
}
}
bool QtTable::hasSelection() const
{
return this->selectionModel()->hasSelection();
}
void QtTable::resizeEvent(QResizeEvent* event)
{
QTableView::resizeEvent(event);
+2
View File
@@ -19,6 +19,8 @@ public:
void showFirstRow();
void showLastRow();
bool hasSelection() const;
protected:
virtual void resizeEvent(QResizeEvent* event);
+67 -29
View File
@@ -5,8 +5,10 @@
#include <QFrame>
#include <QHeaderView>
#include <QItemSelectionModel>
#include <QLabel>
#include <QLineEdit>
#include <QPalette>
#include <QPushButton>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QStyledItemDelegate>
@@ -107,13 +109,38 @@ void QtErrorView::initView()
QBoxLayout* checkboxes = new QHBoxLayout();
checkboxes->addSpacing(15);
m_showFatals = createFilterCheckbox("fatals", true, checkboxes);
m_showErrors = createFilterCheckbox("errors", true, checkboxes);
m_showNonIndexedFatals = createFilterCheckbox("fatals in non-indexed files", true, checkboxes);
m_showNonIndexedErrors = createFilterCheckbox("errors in non-indexed files", false, checkboxes);
{
m_showFatals = createFilterCheckbox("fatals", m_errorFilter.fatal, checkboxes);
m_showErrors = createFilterCheckbox("errors", m_errorFilter.error, checkboxes);
m_showNonIndexedFatals = createFilterCheckbox("fatals in non-indexed files", m_errorFilter.unindexedFatal, checkboxes);
m_showNonIndexedErrors = createFilterCheckbox("errors in non-indexed files", m_errorFilter.unindexedError, checkboxes);
}
checkboxes->addStretch();
{
m_allLabel = new QLabel("");
checkboxes->addWidget(m_allLabel);
m_allLabel->hide();
}
checkboxes->addSpacing(5);
{
m_allButton = new QPushButton("");
connect(m_allButton, &QPushButton::clicked,
[=]()
{
m_errorFilter.limit = 0;
errorFilterChanged();
}
);
checkboxes->addWidget(m_allButton);
m_allButton->hide();
}
checkboxes->addSpacing(10);
layout->addLayout(checkboxes);
doRefreshView();
@@ -139,6 +166,39 @@ void QtErrorView::setErrorId(Id errorId)
m_setErrorIdFunctor(errorId);
}
void QtErrorView::setErrorCount(ErrorCountInfo info)
{
m_onQtThread(
[=]()
{
m_allLabel->setVisible(m_errorFilter.limit > 0 && info.total > m_errorFilter.limit);
m_allButton->setVisible(m_errorFilter.limit > 0 && info.total > m_errorFilter.limit);
m_allLabel->setText("<b>Only showing first " + QString::number(m_errorFilter.limit) + " errors</b>");
m_allButton->setText("show all " + QString::number(info.total));
}
);
}
void QtErrorView::resetErrorLimit()
{
ErrorFilter filter;
m_errorFilter.limit = filter.limit;
errorFilterChanged();
}
void QtErrorView::errorFilterChanged(int i)
{
m_table->selectionModel()->clearSelection();
m_errorFilter.error = m_showErrors->isChecked();
m_errorFilter.fatal = m_showFatals->isChecked();
m_errorFilter.unindexedError = m_showNonIndexedErrors->isChecked();
m_errorFilter.unindexedFatal = m_showNonIndexedFatals->isChecked();
MessageErrorFilterChanged(m_errorFilter).dispatch();
}
void QtErrorView::doRefreshView()
{
setStyleSheet();
@@ -151,16 +211,16 @@ void QtErrorView::doClear()
m_model->removeRows(0, m_model->rowCount());
}
m_errors.clear();
m_table->updateRows();
}
void QtErrorView::doAddErrors(const std::vector<ErrorInfo>& errors, bool scrollTo)
{
for (const ErrorInfo& error : errors)
{
m_errors.push_back(error);
addErrorToTable(error);
}
m_table->updateRows();
if (scrollTo)
{
@@ -191,19 +251,12 @@ void QtErrorView::setStyleSheet() const
QPalette palette(m_showErrors->palette());
palette.setColor(QPalette::WindowText, QColor(ColorScheme::getInstance()->getColor("table/text/normal").c_str()));
//palette.setColor(QPalette::Text, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str()));
//palette.setColor(QPalette::ButtonText, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str()));
//m_showErrors->setAutoFillBackground(true);
m_showErrors->setPalette(palette);
m_showFatals->setPalette(palette);
m_showNonIndexedErrors->setPalette(palette);
m_showNonIndexedFatals->setPalette(palette);
//widget->setStyleSheet(
//utility::getStyleSheet(ResourcePaths::getGuiPath() + "error_view/error_view.css").c_str()
//);
m_table->updateRows();
}
@@ -235,8 +288,6 @@ void QtErrorView::addErrorToTable(const ErrorInfo& error)
m_model->setItem(rowNumber, COLUMN::INDEXED, new QStandardItem(error.indexed ? "yes" : "no"));
m_model->setItem(rowNumber, COLUMN::ID, new QStandardItem(QString::number(error.id)));
m_table->updateRows();
}
QCheckBox* QtErrorView::createFilterCheckbox(const QString& name, bool checked, QBoxLayout* layout)
@@ -244,20 +295,7 @@ QCheckBox* QtErrorView::createFilterCheckbox(const QString& name, bool checked,
QCheckBox* checkbox = new QCheckBox(name);
checkbox->setChecked(checked);
connect(checkbox, &QCheckBox::stateChanged,
[=](int)
{
m_table->selectionModel()->clearSelection();
ErrorFilter filter;
filter.error = m_showErrors->isChecked();
filter.fatal = m_showFatals->isChecked();
filter.unindexedError = m_showNonIndexedErrors->isChecked();
filter.unindexedFatal = m_showNonIndexedFatals->isChecked();
MessageErrorFilterChanged(filter).dispatch();
}
);
connect(checkbox, SIGNAL(stateChanged(int)), this, SLOT(errorFilterChanged(int)));
layout->addWidget(checkbox);
layout->addSpacing(25);
+16 -4
View File
@@ -4,11 +4,13 @@
#include <QWidget>
#include "component/view/ErrorView.h"
#include "data/ErrorFilter.h"
#include "qt/utility/QtThreadedFunctor.h"
class QBoxLayout;
class QCheckBox;
class QPalette;
class QLabel;
class QPushButton;
class QStandardItemModel;
class QtTable;
@@ -32,6 +34,12 @@ public:
virtual void addErrors(const std::vector<ErrorInfo>& errors, bool scrollTo);
virtual void setErrorId(Id errorId);
virtual void setErrorCount(ErrorCountInfo info);
virtual void resetErrorLimit();
private slots:
void errorFilterChanged(int i = 0);
private:
enum COLUMN {
TYPE = 0,
@@ -61,6 +69,13 @@ private:
QtThreadedFunctor<const std::vector<ErrorInfo>&, bool> m_addErrorsFunctor;
QtThreadedFunctor<Id> m_setErrorIdFunctor;
QtThreadedLambdaFunctor m_onQtThread;
ErrorFilter m_errorFilter;
QLabel* m_allLabel;
QPushButton* m_allButton;
QCheckBox* m_showErrors;
QCheckBox* m_showFatals;
QCheckBox* m_showNonIndexedErrors;
@@ -69,9 +84,6 @@ private:
QStandardItemModel* m_model;
QtTable* m_table;
std::vector<ErrorInfo> m_errors;
QPalette* m_palette;
bool m_ignoreRowSelection;
};
+6 -1
View File
@@ -74,7 +74,7 @@ void QtStatusView::initView()
);
filters->addWidget(clearButton);
filters->addSpacing(15);
filters->addSpacing(10);
layout->addLayout(filters);
@@ -153,6 +153,11 @@ void QtStatusView::doAddStatus(const std::vector<Status>& status)
}
m_table->updateRows();
if (!m_table->hasSelection())
{
m_table->showLastRow();
}
}
void QtStatusView::setStyleSheet() const