diff --git a/bin/app/data/gui/error_view/error_view.css b/bin/app/data/gui/error_view/error_view.css index 75dbb52f..0a47bddb 100644 --- a/bin/app/data/gui/error_view/error_view.css +++ b/bin/app/data/gui/error_view/error_view.css @@ -36,14 +36,7 @@ QHeaderView::section:horizontal { font-size: px; font-weight: bold; padding: 1px 6px; - height: px;; -} - - -QCheckBox { - color: ; - border-color: ; - /*background-color: ;*/ + height: px; } QHeaderView::section:vertical { @@ -55,6 +48,15 @@ QHeaderView::section:vertical { padding-left: 5px; } + +QCheckBox { + color: ; + border-color: ; + /*background-color: ;*/ +} + + + QScrollBar:vertical { } diff --git a/src/lib/component/controller/ErrorController.cpp b/src/lib/component/controller/ErrorController.cpp index 39b290ca..54e8d51b 100644 --- a/src/lib/component/controller/ErrorController.cpp +++ b/src/lib/component/controller/ErrorController.cpp @@ -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(); } diff --git a/src/lib/component/view/ErrorView.h b/src/lib/component/view/ErrorView.h index 9d45dbe3..72eb4c00 100644 --- a/src/lib/component/view/ErrorView.h +++ b/src/lib/component/view/ErrorView.h @@ -17,7 +17,7 @@ public: virtual void clear() = 0; - virtual void addError(const ErrorInfo& error) = 0; + virtual void addErrors(const std::vector& errors, bool scrollTo) = 0; virtual void setErrorId(Id errorId) = 0; }; diff --git a/src/lib/utility/messaging/type/MessageNewErrors.h b/src/lib/utility/messaging/type/MessageNewErrors.h index f96559d8..f86d2269 100644 --- a/src/lib/utility/messaging/type/MessageNewErrors.h +++ b/src/lib/utility/messaging/type/MessageNewErrors.h @@ -3,13 +3,13 @@ #include "utility/messaging/Message.h" -#include "data/StorageTypes.h" +#include "data/ErrorInfo.h" class MessageNewErrors : public Message { public: - MessageNewErrors(const std::vector& errors) + MessageNewErrors(const std::vector& errors) : errors(errors) { setSendAsTask(false); @@ -25,7 +25,7 @@ public: os << errors.size() << " errors"; } - const std::vector errors; + const std::vector errors; }; #endif // MESSAGE_NEW_ERRORS_H diff --git a/src/lib_gui/qt/element/QtTable.cpp b/src/lib_gui/qt/element/QtTable.cpp index 85f95ab3..328d2617 100644 --- a/src/lib_gui/qt/element/QtTable.cpp +++ b/src/lib_gui/qt/element/QtTable.cpp @@ -1,32 +1,34 @@ #include "qt/element/QtTable.h" +#include + +#include #include +#include + +#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(); +} diff --git a/src/lib_gui/qt/element/QtTable.h b/src/lib_gui/qt/element/QtTable.h index 5e9b0215..134881eb 100644 --- a/src/lib_gui/qt/element/QtTable.h +++ b/src/lib_gui/qt/element/QtTable.h @@ -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; }; diff --git a/src/lib_gui/qt/view/QtErrorView.cpp b/src/lib_gui/qt/view/QtErrorView.cpp index 36e0daed..38788741 100644 --- a/src/lib_gui/qt/view/QtErrorView.cpp +++ b/src/lib_gui/qt/view/QtErrorView.cpp @@ -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& 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& 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) diff --git a/src/lib_gui/qt/view/QtErrorView.h b/src/lib_gui/qt/view/QtErrorView.h index a724b091..a194ebdb 100644 --- a/src/lib_gui/qt/view/QtErrorView.h +++ b/src/lib_gui/qt/view/QtErrorView.h @@ -29,7 +29,7 @@ public: // ErrorView implementation virtual void clear(); - virtual void addError(const ErrorInfo& error); + virtual void addErrors(const std::vector& 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& errors, bool scrollTo); void doSetErrorId(Id errorId); void setStyleSheet() const; @@ -56,7 +56,7 @@ private: QtThreadedFunctor m_clearFunctor; QtThreadedFunctor m_refreshFunctor; - QtThreadedFunctor m_addErrorFunctor; + QtThreadedFunctor&, bool> m_addErrorsFunctor; QtThreadedFunctor m_setErrorIdFunctor; QCheckBox* m_showErrors;