ui: Scroll table to newest error and fixed error number column width
This commit is contained in:
@@ -36,14 +36,7 @@ QHeaderView::section:horizontal {
|
||||
font-size: <setting:font_size>px;
|
||||
font-weight: bold;
|
||||
padding: 1px 6px;
|
||||
height: <setting:font_size+5>px;;
|
||||
}
|
||||
|
||||
|
||||
QCheckBox {
|
||||
color: <color:error/text/normal>;
|
||||
border-color: <color:error/table>;
|
||||
/*background-color: <color:error/table>;*/
|
||||
height: <setting:font_size+5>px;
|
||||
}
|
||||
|
||||
QHeaderView::section:vertical {
|
||||
@@ -55,6 +48,15 @@ QHeaderView::section:vertical {
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
|
||||
QCheckBox {
|
||||
color: <color:error/text/normal>;
|
||||
border-color: <color:error/table>;
|
||||
/*background-color: <color:error/table>;*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
QScrollBar:vertical {
|
||||
}
|
||||
|
||||
|
||||
@@ -20,21 +20,12 @@ void ErrorController::handleMessage(MessageFinishedParsing* message)
|
||||
{
|
||||
clear();
|
||||
|
||||
auto errors = m_storageAccess->getAllErrors();
|
||||
|
||||
for (const ErrorInfo& error : errors)
|
||||
{
|
||||
getView()->addError(error);
|
||||
}
|
||||
getView()->addErrors(m_storageAccess->getAllErrors(), false);
|
||||
}
|
||||
|
||||
void ErrorController::handleMessage(MessageNewErrors* message)
|
||||
{
|
||||
for (const ErrorInfo& error : message->errors)
|
||||
{
|
||||
getView()->addError(error);
|
||||
}
|
||||
|
||||
getView()->addErrors(message->errors, true);
|
||||
getView()->showDockWidget();
|
||||
}
|
||||
|
||||
@@ -51,13 +42,7 @@ void ErrorController::handleMessage(MessageShowErrors* message)
|
||||
|
||||
clear();
|
||||
|
||||
auto errors = m_storageAccess->getAllErrors();
|
||||
|
||||
for (const ErrorInfo& error : errors)
|
||||
{
|
||||
getView()->addError(error);
|
||||
}
|
||||
|
||||
getView()->addErrors(m_storageAccess->getAllErrors(), false);
|
||||
getView()->showDockWidget();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
|
||||
virtual void clear() = 0;
|
||||
|
||||
virtual void addError(const ErrorInfo& error) = 0;
|
||||
virtual void addErrors(const std::vector<ErrorInfo>& errors, bool scrollTo) = 0;
|
||||
virtual void setErrorId(Id errorId) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
|
||||
#include "data/StorageTypes.h"
|
||||
#include "data/ErrorInfo.h"
|
||||
|
||||
class MessageNewErrors
|
||||
: public Message<MessageNewErrors>
|
||||
{
|
||||
public:
|
||||
MessageNewErrors(const std::vector<StorageError>& errors)
|
||||
MessageNewErrors(const std::vector<ErrorInfo>& errors)
|
||||
: errors(errors)
|
||||
{
|
||||
setSendAsTask(false);
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
os << errors.size() << " errors";
|
||||
}
|
||||
|
||||
const std::vector<StorageError> errors;
|
||||
const std::vector<ErrorInfo> errors;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_NEW_ERRORS_H
|
||||
|
||||
@@ -1,32 +1,34 @@
|
||||
#include "qt/element/QtTable.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QResizeEvent>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include "settings/ApplicationSettings.h"
|
||||
|
||||
QtTable::QtTable(QWidget* parent)
|
||||
: QTableView(parent)
|
||||
, m_rowsToFill(0)
|
||||
{
|
||||
setAlternatingRowColors(true);
|
||||
setShowGrid(false);
|
||||
|
||||
verticalHeader()->sectionResizeMode(QHeaderView::Fixed);
|
||||
verticalHeader()->setDefaultAlignment(Qt::AlignRight);
|
||||
|
||||
horizontalHeader()->setStretchLastSection(true);
|
||||
horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
|
||||
|
||||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
}
|
||||
|
||||
QtTable::~QtTable()
|
||||
{
|
||||
}
|
||||
|
||||
void QtTable::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
QTableView::resizeEvent(event);
|
||||
int tableHeight = event->size().height();
|
||||
|
||||
if (this->model()->rowCount() == 0)
|
||||
{
|
||||
this->model()->insertRow(0);
|
||||
}
|
||||
|
||||
m_rowsToFill = (float)tableHeight / this->rowHeight(0);
|
||||
|
||||
updateRows();
|
||||
}
|
||||
|
||||
void QtTable::updateRows()
|
||||
{
|
||||
while (model()->rowCount() <= m_rowsToFill)
|
||||
@@ -46,6 +48,12 @@ void QtTable::updateRows()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int rowCount = model()->rowCount() > m_rowsToFill ? model()->rowCount() : m_rowsToFill;
|
||||
int width = ApplicationSettings::getInstance()->getFontSize() * 0.7 * int(1 + std::log10(rowCount));
|
||||
|
||||
verticalHeader()->setStyleSheet("::section { width: " + QString::number(width) + "px; }");
|
||||
verticalHeader()->setDefaultSectionSize(ApplicationSettings::getInstance()->getFontSize() + 6);
|
||||
}
|
||||
|
||||
int QtTable::getFilledRowCount()
|
||||
@@ -60,3 +68,26 @@ int QtTable::getFilledRowCount()
|
||||
|
||||
return model()->rowCount();
|
||||
}
|
||||
|
||||
void QtTable::showLastRow()
|
||||
{
|
||||
if (m_rowsToFill <= getFilledRowCount())
|
||||
{
|
||||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||
}
|
||||
}
|
||||
|
||||
void QtTable::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
QTableView::resizeEvent(event);
|
||||
int tableHeight = event->size().height();
|
||||
|
||||
if (this->model()->rowCount() == 0)
|
||||
{
|
||||
this->model()->insertRow(0);
|
||||
}
|
||||
|
||||
m_rowsToFill = (float)tableHeight / this->rowHeight(0);
|
||||
|
||||
updateRows();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ class QtTable
|
||||
: public QTableView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtTable(QWidget* parent = nullptr);
|
||||
virtual ~QtTable();
|
||||
@@ -14,9 +15,12 @@ public:
|
||||
void updateRows();
|
||||
int getFilledRowCount();
|
||||
|
||||
void showLastRow();
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent(QResizeEvent* event);
|
||||
|
||||
|
||||
private:
|
||||
float m_rowsToFill;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ QtErrorView::QtErrorView(ViewLayout* viewLayout)
|
||||
: ErrorView(viewLayout)
|
||||
, m_clearFunctor(std::bind(&QtErrorView::doClear, this))
|
||||
, m_refreshFunctor(std::bind(&QtErrorView::doRefreshView, this))
|
||||
, m_addErrorFunctor(std::bind(&QtErrorView::doAddError, this, std::placeholders::_1))
|
||||
, m_addErrorsFunctor(std::bind(&QtErrorView::doAddErrors, this, std::placeholders::_1, std::placeholders::_2))
|
||||
, m_setErrorIdFunctor(std::bind(&QtErrorView::doSetErrorId, this, std::placeholders::_1))
|
||||
, m_ignoreNextSelection(false)
|
||||
{
|
||||
@@ -48,17 +48,6 @@ void QtErrorView::initView()
|
||||
widget->setLayout(layout);
|
||||
|
||||
m_table = new QtTable(this);
|
||||
m_table->setAlternatingRowColors(true);
|
||||
|
||||
m_table->setShowGrid(false);
|
||||
m_table->verticalHeader()->setAlternatingRowColors(true);
|
||||
m_table->verticalHeader()->sectionResizeMode(QHeaderView::Fixed);
|
||||
m_table->verticalHeader()->setDefaultSectionSize(ApplicationSettings::getInstance()->getFontSize() + 6);
|
||||
m_table->horizontalHeader()->setStretchLastSection(true);
|
||||
|
||||
m_table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_table->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
m_model = new QStandardItemModel(this);
|
||||
m_table->setModel(m_model);
|
||||
|
||||
@@ -73,7 +62,6 @@ void QtErrorView::initView()
|
||||
QStringList headers;
|
||||
headers << "Type" << "Message" << "File" << "Line" << "Indexed";
|
||||
m_model->setHorizontalHeaderLabels(headers);
|
||||
m_table->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
|
||||
|
||||
connect(m_table->selectionModel(), &QItemSelectionModel::currentRowChanged,
|
||||
[=](const QModelIndex& index, const QModelIndex& previousIndex)
|
||||
@@ -119,9 +107,9 @@ void QtErrorView::clear()
|
||||
m_clearFunctor();
|
||||
}
|
||||
|
||||
void QtErrorView::addError(const ErrorInfo& error)
|
||||
void QtErrorView::addErrors(const std::vector<ErrorInfo>& errors, bool scrollTo)
|
||||
{
|
||||
m_addErrorFunctor(error);
|
||||
m_addErrorsFunctor(errors, scrollTo);
|
||||
}
|
||||
|
||||
void QtErrorView::setErrorId(Id errorId)
|
||||
@@ -144,11 +132,18 @@ void QtErrorView::doClear()
|
||||
m_errors.clear();
|
||||
}
|
||||
|
||||
void QtErrorView::doAddError(const ErrorInfo& error)
|
||||
void QtErrorView::doAddErrors(const std::vector<ErrorInfo>& errors, bool scrollTo)
|
||||
{
|
||||
m_errors.push_back(error);
|
||||
for (const ErrorInfo& error : errors)
|
||||
{
|
||||
m_errors.push_back(error);
|
||||
addErrorToTable(error);
|
||||
}
|
||||
|
||||
addErrorToTable(error);
|
||||
if (scrollTo)
|
||||
{
|
||||
m_table->showLastRow();
|
||||
}
|
||||
}
|
||||
|
||||
void QtErrorView::doSetErrorId(Id errorId)
|
||||
@@ -168,7 +163,7 @@ void QtErrorView::setStyleSheet() const
|
||||
utility::setWidgetBackgroundColor(widget, ColorScheme::getInstance()->getColor("error/background"));
|
||||
|
||||
|
||||
QPalette palette( m_showErrors->palette() );
|
||||
QPalette palette(m_showErrors->palette());
|
||||
palette.setColor(QPalette::WindowText, QColor(ColorScheme::getInstance()->getColor("error/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()));
|
||||
@@ -182,6 +177,8 @@ void QtErrorView::setStyleSheet() const
|
||||
widget->setStyleSheet(
|
||||
utility::getStyleSheet(ResourcePaths::getGuiPath() + "error_view/error_view.css").c_str()
|
||||
);
|
||||
|
||||
m_table->updateRows();
|
||||
}
|
||||
|
||||
void QtErrorView::addErrorToTable(const ErrorInfo& error)
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
|
||||
// ErrorView implementation
|
||||
virtual void clear();
|
||||
virtual void addError(const ErrorInfo& error);
|
||||
virtual void addErrors(const std::vector<ErrorInfo>& errors, bool scrollTo);
|
||||
virtual void setErrorId(Id errorId);
|
||||
|
||||
private:
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
|
||||
void doRefreshView();
|
||||
void doClear();
|
||||
void doAddError(const ErrorInfo& error);
|
||||
void doAddErrors(const std::vector<ErrorInfo>& errors, bool scrollTo);
|
||||
void doSetErrorId(Id errorId);
|
||||
|
||||
void setStyleSheet() const;
|
||||
@@ -56,7 +56,7 @@ private:
|
||||
|
||||
QtThreadedFunctor<void> m_clearFunctor;
|
||||
QtThreadedFunctor<void> m_refreshFunctor;
|
||||
QtThreadedFunctor<const ErrorInfo&> m_addErrorFunctor;
|
||||
QtThreadedFunctor<const std::vector<ErrorInfo>&, bool> m_addErrorsFunctor;
|
||||
QtThreadedFunctor<Id> m_setErrorIdFunctor;
|
||||
|
||||
QCheckBox* m_showErrors;
|
||||
|
||||
Reference in New Issue
Block a user