From b6be476e84d02d5d54735d268f616c2e7d0a842f Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Tue, 22 Sep 2020 17:19:34 +0200 Subject: [PATCH] restable: do not use resize mode "ResizeToContents" on the table rows: this forces a full extraction of all rows at every opportunity. Also: cache doc and font which are repeatedly requested by calls to the model data() method --- src/qtgui/restable.cpp | 53 ++++++++++++++++++++++++++++++------------ src/qtgui/restable.h | 6 +++++ 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/qtgui/restable.cpp b/src/qtgui/restable.cpp index 3294e18e..6642acea 100644 --- a/src/qtgui/restable.cpp +++ b/src/qtgui/restable.cpp @@ -301,6 +301,7 @@ void RecollModel::readDocSource() void RecollModel::setDocSource(std::shared_ptr nsource) { LOGDEB("RecollModel::setDocSource\n"); + m_rowforcachedoc = -1; if (!nsource) { m_source = std::shared_ptr(); } else { @@ -371,11 +372,15 @@ QVariant RecollModel::data(const QModelIndex& index, int role) const // this to adjust the row height (there is probably a better way // to do it in the delegate?) if (role == Qt::FontRole && prefs.reslistfontsize > 0) { - QFont font = m_table->font(); - int fs = prefs.reslistfontsize <= fsadjusttable ? prefs.reslistfontsize: - prefs.reslistfontsize - fsadjusttable; - font.setPointSize(fs); - return font; + if (m_reslfntszforcached != prefs.reslistfontsize) { + m_reslfntszforcached = prefs.reslistfontsize; + m_table->setDefRowHeight(); + m_cachedfont = m_table->font(); + int fs = prefs.reslistfontsize <= fsadjusttable ? + prefs.reslistfontsize: prefs.reslistfontsize - fsadjusttable; + m_cachedfont.setPointSize(fs); + } + return m_cachedfont; } if (!m_source || role != Qt::DisplayRole || !index.isValid() || @@ -383,14 +388,17 @@ QVariant RecollModel::data(const QModelIndex& index, int role) const return QVariant(); } - Rcl::Doc doc; - if (!m_source->getDoc(index.row(), doc)) { - return QVariant(); + if (m_rowforcachedoc != index.row()) { + m_rowforcachedoc = index.row(); + LOGINF("RecollModel::data: calling getDoc for row "<getDoc(index.row(), m_cachedoc)) { + return QVariant(); + } } string colname = m_fields[index.column()]; - string data = m_getters[index.column()](colname, doc); + string data = m_getters[index.column()](colname, m_cachedoc); #ifndef _WIN32 // Special case url, because it may not be utf-8. URL-encode in this case. @@ -535,6 +543,26 @@ public: } }; +void ResTable::setDefRowHeight() +{ + QHeaderView *header = tableView->verticalHeader(); + if (header) { + // Don't do this: it forces a query on the whole model (all + // docs) to compute the height. No idea why this was needed, + // things seem to work ok without it. The row height does not + // shrink when the font is reduced, but I'm not sure that it + // worked before. +// header->setSectionResizeMode(QHeaderView::ResizeToContents); + // Compute ourselves instead, for one row. + QFont font = tableView->font(); + int fs = prefs.reslistfontsize <= fsadjusttable ? + prefs.reslistfontsize : prefs.reslistfontsize - fsadjusttable; + font.setPointSize(fs); + QFontMetrics fm(font); + header->setDefaultSectionSize(fm.height() + ROWHEIGHTPAD); + } +} + void ResTable::init() { if (!(m_model = new RecollModel(prefs.restableFields, this))) @@ -574,12 +602,7 @@ void ResTable::init() header->setMovable(true); #endif - header = tableView->verticalHeader(); - if (header) { - header->setDefaultSectionSize(QApplication::fontMetrics().height() + - ROWHEIGHTPAD); - header->setSectionResizeMode(QHeaderView::ResizeToContents); - } + setDefRowHeight(); QShortcut *sc = new QShortcut(QKeySequence(Qt::Key_Escape), this); connect(sc, SIGNAL(activated()), tableView->selectionModel(), SLOT(clear())); diff --git a/src/qtgui/restable.h b/src/qtgui/restable.h index 087e5dc4..c5accd6b 100644 --- a/src/qtgui/restable.h +++ b/src/qtgui/restable.h @@ -82,6 +82,11 @@ private: bool m_ignoreSort; FieldGetter* chooseGetter(const std::string&); HighlightData m_hdata; + // Things we cache because we are repeatedly asked for the same. + mutable QFont m_cachedfont; + mutable int m_reslfntszforcached{-1}; + mutable Rcl::Doc m_cachedoc; + mutable int m_rowforcachedoc{-1}; }; class ResTable; @@ -127,6 +132,7 @@ public: virtual int getDetailDocNumOrTopRow(); void setRclMain(RclMain *m, bool ismain); + void setDefRowHeight(); public slots: virtual void onTableView_currentChanged(const QModelIndex&);