Skip to content
Snippets Groups Projects

Change log scrolling to per-pixel

Merged Peter Albrecht requested to merge feature/pixelwiseLogScrolling into master
2 files
+ 70
52
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -21,16 +21,15 @@
*/
#include "LogTable.h"
#include <filesystem>
#include <QHeaderView>
#include <QApplication>
#include <QHeaderView>
#include <QScrollBar>
#include <QTimer>
#include "LogTableModel.h"
#include "LogMessageDelegate.h"
#include <filesystem>
#include "LogTableModel.h"
namespace armarx
{
@@ -38,13 +37,12 @@ namespace armarx
#define BUFFER_SIZE_FACTOR 1.3
LogTable::LogTable(QWidget* parent) :
QTableView(parent),
newMessageCount(0),
maxNewLogLevelType(eUNDEFINED)
QTableView(parent), newMessageCount(0), maxNewLogLevelType(eUNDEFINED)
{
autoscrollActive = true;
selectedSearchIndex = -1;
this->setVerticalScrollMode(ScrollMode::ScrollPerPixel);
setObjectName(QString::fromUtf8("tableLog"));
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -90,33 +88,41 @@ namespace armarx
setFont(font);
setItemDelegateForColumn(getModel()->getColumn(ARMARX_LOG_MESSAGESTR), new LogMessageDelegate());
setItemDelegateForColumn(getModel()->getColumn(ARMARX_LOG_MESSAGESTR),
new LogMessageDelegate());
QAbstractItemModel* absmodel = qobject_cast<QAbstractItemModel*>(model());
connect(absmodel, SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(checkAutoScroll(QModelIndex, int, int)));
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(doubleClickOnCell(QModelIndex)));
connect(absmodel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(itemsAdded(QModelIndex, QModelIndex)));
connect(absmodel,
SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)),
this,
SLOT(checkAutoScroll(QModelIndex, int, int)));
connect(
this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(doubleClickOnCell(QModelIndex)));
connect(absmodel,
SIGNAL(dataChanged(QModelIndex, QModelIndex)),
this,
SLOT(itemsAdded(QModelIndex, QModelIndex)));
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(checkAutoScroll()));
// connect(this, SIGNAL(scrollToEnd()), this, SLOT(scrollToBottom()));
}
LogTable::~LogTable()
{
}
QString LogTable::getCurrentLiveFilter() const
QString
LogTable::getCurrentLiveFilter() const
{
return currentLiveFilter;
}
void LogTable::liveFilterRow(const QString& filterStr, int row)
void
LogTable::liveFilterRow(const QString& filterStr, int row)
{
LogTableModel* logModel = getModel();
bool contains = logModel->rowContainsString(row, filterStr);
if (! isRowHidden(row) && !contains)
if (!isRowHidden(row) && !contains)
{
setRowHidden(row, true);
}
@@ -126,8 +132,8 @@ namespace armarx
}
}
void LogTable::liveFilter(const QString& filterStr, int startRow)
void
LogTable::liveFilter(const QString& filterStr, int startRow)
{
LogTableModel* logModel = getModel();
currentLiveFilter = filterStr;
@@ -138,7 +144,7 @@ namespace armarx
for (int i = startRow; i < rowCount; i++)
{
if (! isRowHidden(i) && !logModel->rowContainsString(i, filterStr))
if (!isRowHidden(i) && !logModel->rowContainsString(i, filterStr))
{
setRowHidden(i, true);
}
@@ -148,7 +154,7 @@ namespace armarx
}
if (filterStr != currentLiveFilter)
{
break; // filterstring already changed again -> cancel
break; // filterstring already changed again -> cancel
}
}
}
@@ -184,7 +190,7 @@ namespace armarx
}
if (filterStr != currentLiveFilter)
{
break; // filterstring already changed again -> cancel
break; // filterstring already changed again -> cancel
}
}
@@ -199,16 +205,17 @@ namespace armarx
lastLiveFilter = filterStr;
}
bool LogTable::liveSearch(const QString& search)
bool
LogTable::liveSearch(const QString& search)
{
getModel()->search(search);
// scrollToBottom();
clearSelection();
return selectNextSearchResult(true, true);
}
void LogTable::resetLiveFilter()
void
LogTable::resetLiveFilter()
{
// ARMARX_WARNING_S << "LiveFilterReseted";
selectedSearchIndex = -1;
@@ -216,22 +223,27 @@ namespace armarx
liveFilter("");
}
void LogTable::resetLiveSearch()
void
LogTable::resetLiveSearch()
{
getModel()->search("");
// repaint();
}
LogTableModel* LogTable::getModel()
LogTableModel*
LogTable::getModel()
{
return dynamic_cast<LogTableModel*>(model());
}
bool LogTable::checkAutoScroll(const QModelIndex& parent, int start, int end)
bool
LogTable::checkAutoScroll(const QModelIndex& parent, int start, int end)
{
return checkAutoScroll();
}
bool LogTable::checkAutoScroll(int dummy)
bool
LogTable::checkAutoScroll(int dummy)
{
if (verticalScrollBar()->value() == verticalScrollBar()->maximum())
{
@@ -246,12 +258,13 @@ namespace armarx
return autoscrollActive;
}
void LogTable::itemsAdded(QModelIndex leftTop, QModelIndex bottomRight)
void
LogTable::itemsAdded(QModelIndex leftTop, QModelIndex bottomRight)
{
}
void LogTable::showEvent(QShowEvent* event)
void
LogTable::showEvent(QShowEvent* event)
{
resetNewMessageCount();
@@ -260,12 +273,16 @@ namespace armarx
// verticalHeader()->setResizeMode(QHeaderView::Fixed);
if (autoscrollActive)
{
QTimer::singleShot(50, this, SLOT(scrollToBottom())); // delayed because something is inserting one line after this function or something
QTimer::singleShot(
50,
this,
SLOT(
scrollToBottom())); // delayed because something is inserting one line after this function or something
}
}
void LogTable::hideEvent(QHideEvent*)
void
LogTable::hideEvent(QHideEvent*)
{
if (verticalScrollBar()->value() == verticalScrollBar()->maximum())
{
@@ -277,11 +294,11 @@ namespace armarx
}
}
void LogTable::rowsInserted(const QModelIndex& parent, int start, int end)
void
LogTable::rowsInserted(const QModelIndex& parent, int start, int end)
{
auto logModel = getModel();
auto fontHeight = QFontMetrics(font()).height();
auto fontHeight = QFontMetrics(font()).height();
// ARMARX_INFO << "Adjusting height for " << start << " to " << end << " count: " << logModel->rowCount();
for (int i = start; i <= end && i < logModel->rowCount(); ++i)
{
@@ -322,7 +339,6 @@ namespace armarx
// for(int i = start; i < end; i++)
// resizeRowToContents(i);
// verticalHeader()->setResizeMode(QHeaderView::Fixed);
}
if (autoscrollActive)
@@ -331,7 +347,8 @@ namespace armarx
}
}
void LogTable::rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end)
void
LogTable::rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end)
{
if (end - start >= model()->rowCount() - 1)
{
@@ -339,8 +356,8 @@ namespace armarx
}
}
bool LogTable::selectNextSearchResult(bool backwards, bool keepSelectionIfPossible)
bool
LogTable::selectNextSearchResult(bool backwards, bool keepSelectionIfPossible)
{
int checkCounter = 0; // just a counter for avoiding inifite loops
@@ -356,8 +373,9 @@ namespace armarx
do // search until we reach old line again
{
if ((tempSelectedSearchIndex != oldSelectedSearchIndex || keepSelectionIfPossible)
&& getModel()->rowContainsString(tempSelectedSearchIndex, getModel()->getCurrentSearchStr()))
if ((tempSelectedSearchIndex != oldSelectedSearchIndex || keepSelectionIfPossible) &&
getModel()->rowContainsString(tempSelectedSearchIndex,
getModel()->getCurrentSearchStr()))
{
selectRow(tempSelectedSearchIndex);
return true;
@@ -389,14 +407,13 @@ namespace armarx
{
break;
}
}
while (tempSelectedSearchIndex != oldSelectedSearchIndex);
} while (tempSelectedSearchIndex != oldSelectedSearchIndex);
return false;
}
void LogTable::doubleClickOnCell(const QModelIndex& index)
void
LogTable::doubleClickOnCell(const QModelIndex& index)
{
if (index.column() != getModel()->getColumn(ARMARX_LOG_FILESTR))
{
@@ -404,20 +421,19 @@ namespace armarx
}
QString fileWithLineNumber = model()->data(index).toString();
std::string file = fileWithLineNumber.toStdString();
std::string file = fileWithLineNumber.toStdString();
file.erase(file.rfind(':'));
std::string line = fileWithLineNumber.toStdString();
line = line.erase(0, line.rfind(':') + 1);
if (!std::filesystem::exists(file))
{
ARMARX_INFO << "File '" << file << "' does not exists - cannot open it.";
ARMARX_INFO << "File '" << file << "' does not exists - cannot open it.";
return;
}
fileOpener.openFileWithDefaultEditor(file, atoi(line.c_str()));
// std::string command = "qtcreator -client " + fileWithLineNumber.toStdString() + "&";
// if(system(command.c_str())){}
}
}
} // namespace armarx
Loading