ui: Scroll table to newest error and fixed error number column width

This commit is contained in:
Eberhard Graether
2016-10-25 17:47:38 +02:00
parent 15bd89e0ed
commit 2e10c65491
8 changed files with 86 additions and 67 deletions
+10 -8
View File
@@ -36,14 +36,7 @@ QHeaderView::section:horizontal {
font-size: <setting:font_size>px; font-size: <setting:font_size>px;
font-weight: bold; font-weight: bold;
padding: 1px 6px; padding: 1px 6px;
height: <setting:font_size+5>px;; height: <setting:font_size+5>px;
}
QCheckBox {
color: <color:error/text/normal>;
border-color: <color:error/table>;
/*background-color: <color:error/table>;*/
} }
QHeaderView::section:vertical { QHeaderView::section:vertical {
@@ -55,6 +48,15 @@ QHeaderView::section:vertical {
padding-left: 5px; padding-left: 5px;
} }
QCheckBox {
color: <color:error/text/normal>;
border-color: <color:error/table>;
/*background-color: <color:error/table>;*/
}
QScrollBar:vertical { QScrollBar:vertical {
} }
@@ -20,21 +20,12 @@ void ErrorController::handleMessage(MessageFinishedParsing* message)
{ {
clear(); clear();
auto errors = m_storageAccess->getAllErrors(); getView()->addErrors(m_storageAccess->getAllErrors(), false);
for (const ErrorInfo& error : errors)
{
getView()->addError(error);
}
} }
void ErrorController::handleMessage(MessageNewErrors* message) void ErrorController::handleMessage(MessageNewErrors* message)
{ {
for (const ErrorInfo& error : message->errors) getView()->addErrors(message->errors, true);
{
getView()->addError(error);
}
getView()->showDockWidget(); getView()->showDockWidget();
} }
@@ -51,13 +42,7 @@ void ErrorController::handleMessage(MessageShowErrors* message)
clear(); clear();
auto errors = m_storageAccess->getAllErrors(); getView()->addErrors(m_storageAccess->getAllErrors(), false);
for (const ErrorInfo& error : errors)
{
getView()->addError(error);
}
getView()->showDockWidget(); getView()->showDockWidget();
} }
+1 -1
View File
@@ -17,7 +17,7 @@ public:
virtual void clear() = 0; 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; virtual void setErrorId(Id errorId) = 0;
}; };
@@ -3,13 +3,13 @@
#include "utility/messaging/Message.h" #include "utility/messaging/Message.h"
#include "data/StorageTypes.h" #include "data/ErrorInfo.h"
class MessageNewErrors class MessageNewErrors
: public Message<MessageNewErrors> : public Message<MessageNewErrors>
{ {
public: public:
MessageNewErrors(const std::vector<StorageError>& errors) MessageNewErrors(const std::vector<ErrorInfo>& errors)
: errors(errors) : errors(errors)
{ {
setSendAsTask(false); setSendAsTask(false);
@@ -25,7 +25,7 @@ public:
os << errors.size() << " errors"; os << errors.size() << " errors";
} }
const std::vector<StorageError> errors; const std::vector<ErrorInfo> errors;
}; };
#endif // MESSAGE_NEW_ERRORS_H #endif // MESSAGE_NEW_ERRORS_H
+46 -15
View File
@@ -1,32 +1,34 @@
#include "qt/element/QtTable.h" #include "qt/element/QtTable.h"
#include <cmath>
#include <QHeaderView>
#include <QResizeEvent> #include <QResizeEvent>
#include <QScrollBar>
#include "settings/ApplicationSettings.h"
QtTable::QtTable(QWidget* parent) QtTable::QtTable(QWidget* parent)
: QTableView(parent) : QTableView(parent)
, m_rowsToFill(0) , 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() 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() void QtTable::updateRows()
{ {
while (model()->rowCount() <= m_rowsToFill) while (model()->rowCount() <= m_rowsToFill)
@@ -46,6 +48,12 @@ void QtTable::updateRows()
break; 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() int QtTable::getFilledRowCount()
@@ -60,3 +68,26 @@ int QtTable::getFilledRowCount()
return model()->rowCount(); 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();
}
+4
View File
@@ -7,6 +7,7 @@ class QtTable
: public QTableView : public QTableView
{ {
Q_OBJECT Q_OBJECT
public: public:
QtTable(QWidget* parent = nullptr); QtTable(QWidget* parent = nullptr);
virtual ~QtTable(); virtual ~QtTable();
@@ -14,9 +15,12 @@ public:
void updateRows(); void updateRows();
int getFilledRowCount(); int getFilledRowCount();
void showLastRow();
protected: protected:
virtual void resizeEvent(QResizeEvent* event); virtual void resizeEvent(QResizeEvent* event);
private: private:
float m_rowsToFill; float m_rowsToFill;
}; };
+16 -19
View File
@@ -23,7 +23,7 @@ QtErrorView::QtErrorView(ViewLayout* viewLayout)
: ErrorView(viewLayout) : ErrorView(viewLayout)
, m_clearFunctor(std::bind(&QtErrorView::doClear, this)) , m_clearFunctor(std::bind(&QtErrorView::doClear, this))
, m_refreshFunctor(std::bind(&QtErrorView::doRefreshView, 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_setErrorIdFunctor(std::bind(&QtErrorView::doSetErrorId, this, std::placeholders::_1))
, m_ignoreNextSelection(false) , m_ignoreNextSelection(false)
{ {
@@ -48,17 +48,6 @@ void QtErrorView::initView()
widget->setLayout(layout); widget->setLayout(layout);
m_table = new QtTable(this); 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_model = new QStandardItemModel(this);
m_table->setModel(m_model); m_table->setModel(m_model);
@@ -73,7 +62,6 @@ void QtErrorView::initView()
QStringList headers; QStringList headers;
headers << "Type" << "Message" << "File" << "Line" << "Indexed"; headers << "Type" << "Message" << "File" << "Line" << "Indexed";
m_model->setHorizontalHeaderLabels(headers); m_model->setHorizontalHeaderLabels(headers);
m_table->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
connect(m_table->selectionModel(), &QItemSelectionModel::currentRowChanged, connect(m_table->selectionModel(), &QItemSelectionModel::currentRowChanged,
[=](const QModelIndex& index, const QModelIndex& previousIndex) [=](const QModelIndex& index, const QModelIndex& previousIndex)
@@ -119,9 +107,9 @@ void QtErrorView::clear()
m_clearFunctor(); 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) void QtErrorView::setErrorId(Id errorId)
@@ -144,11 +132,18 @@ void QtErrorView::doClear()
m_errors.clear(); 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) void QtErrorView::doSetErrorId(Id errorId)
@@ -168,7 +163,7 @@ void QtErrorView::setStyleSheet() const
utility::setWidgetBackgroundColor(widget, ColorScheme::getInstance()->getColor("error/background")); 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::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::Text, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str()));
//palette.setColor(QPalette::ButtonText, 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( widget->setStyleSheet(
utility::getStyleSheet(ResourcePaths::getGuiPath() + "error_view/error_view.css").c_str() utility::getStyleSheet(ResourcePaths::getGuiPath() + "error_view/error_view.css").c_str()
); );
m_table->updateRows();
} }
void QtErrorView::addErrorToTable(const ErrorInfo& error) void QtErrorView::addErrorToTable(const ErrorInfo& error)
+3 -3
View File
@@ -29,7 +29,7 @@ public:
// ErrorView implementation // ErrorView implementation
virtual void clear(); virtual void clear();
virtual void addError(const ErrorInfo& error); virtual void addErrors(const std::vector<ErrorInfo>& errors, bool scrollTo);
virtual void setErrorId(Id errorId); virtual void setErrorId(Id errorId);
private: private:
@@ -44,7 +44,7 @@ private:
void doRefreshView(); void doRefreshView();
void doClear(); void doClear();
void doAddError(const ErrorInfo& error); void doAddErrors(const std::vector<ErrorInfo>& errors, bool scrollTo);
void doSetErrorId(Id errorId); void doSetErrorId(Id errorId);
void setStyleSheet() const; void setStyleSheet() const;
@@ -56,7 +56,7 @@ private:
QtThreadedFunctor<void> m_clearFunctor; QtThreadedFunctor<void> m_clearFunctor;
QtThreadedFunctor<void> m_refreshFunctor; QtThreadedFunctor<void> m_refreshFunctor;
QtThreadedFunctor<const ErrorInfo&> m_addErrorFunctor; QtThreadedFunctor<const std::vector<ErrorInfo>&, bool> m_addErrorsFunctor;
QtThreadedFunctor<Id> m_setErrorIdFunctor; QtThreadedFunctor<Id> m_setErrorIdFunctor;
QCheckBox* m_showErrors; QCheckBox* m_showErrors;