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
+46 -15
View File
@@ -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();
}
+4
View File
@@ -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;
};