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
This commit is contained in:
parent
4df9106b46
commit
b6be476e84
@ -301,6 +301,7 @@ void RecollModel::readDocSource()
|
|||||||
void RecollModel::setDocSource(std::shared_ptr<DocSequence> nsource)
|
void RecollModel::setDocSource(std::shared_ptr<DocSequence> nsource)
|
||||||
{
|
{
|
||||||
LOGDEB("RecollModel::setDocSource\n");
|
LOGDEB("RecollModel::setDocSource\n");
|
||||||
|
m_rowforcachedoc = -1;
|
||||||
if (!nsource) {
|
if (!nsource) {
|
||||||
m_source = std::shared_ptr<DocSequence>();
|
m_source = std::shared_ptr<DocSequence>();
|
||||||
} else {
|
} 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
|
// this to adjust the row height (there is probably a better way
|
||||||
// to do it in the delegate?)
|
// to do it in the delegate?)
|
||||||
if (role == Qt::FontRole && prefs.reslistfontsize > 0) {
|
if (role == Qt::FontRole && prefs.reslistfontsize > 0) {
|
||||||
QFont font = m_table->font();
|
if (m_reslfntszforcached != prefs.reslistfontsize) {
|
||||||
int fs = prefs.reslistfontsize <= fsadjusttable ? prefs.reslistfontsize:
|
m_reslfntszforcached = prefs.reslistfontsize;
|
||||||
prefs.reslistfontsize - fsadjusttable;
|
m_table->setDefRowHeight();
|
||||||
font.setPointSize(fs);
|
m_cachedfont = m_table->font();
|
||||||
return 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() ||
|
if (!m_source || role != Qt::DisplayRole || !index.isValid() ||
|
||||||
@ -383,14 +388,17 @@ QVariant RecollModel::data(const QModelIndex& index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
Rcl::Doc doc;
|
if (m_rowforcachedoc != index.row()) {
|
||||||
if (!m_source->getDoc(index.row(), doc)) {
|
m_rowforcachedoc = index.row();
|
||||||
return QVariant();
|
LOGINF("RecollModel::data: calling getDoc for row "<<index.row()<<"\n");
|
||||||
|
if (!m_source->getDoc(index.row(), m_cachedoc)) {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string colname = m_fields[index.column()];
|
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
|
#ifndef _WIN32
|
||||||
// Special case url, because it may not be utf-8. URL-encode in this case.
|
// 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()
|
void ResTable::init()
|
||||||
{
|
{
|
||||||
if (!(m_model = new RecollModel(prefs.restableFields, this)))
|
if (!(m_model = new RecollModel(prefs.restableFields, this)))
|
||||||
@ -574,12 +602,7 @@ void ResTable::init()
|
|||||||
header->setMovable(true);
|
header->setMovable(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
header = tableView->verticalHeader();
|
setDefRowHeight();
|
||||||
if (header) {
|
|
||||||
header->setDefaultSectionSize(QApplication::fontMetrics().height() +
|
|
||||||
ROWHEIGHTPAD);
|
|
||||||
header->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
||||||
}
|
|
||||||
|
|
||||||
QShortcut *sc = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
QShortcut *sc = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
||||||
connect(sc, SIGNAL(activated()), tableView->selectionModel(), SLOT(clear()));
|
connect(sc, SIGNAL(activated()), tableView->selectionModel(), SLOT(clear()));
|
||||||
|
|||||||
@ -82,6 +82,11 @@ private:
|
|||||||
bool m_ignoreSort;
|
bool m_ignoreSort;
|
||||||
FieldGetter* chooseGetter(const std::string&);
|
FieldGetter* chooseGetter(const std::string&);
|
||||||
HighlightData m_hdata;
|
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;
|
class ResTable;
|
||||||
@ -127,6 +132,7 @@ public:
|
|||||||
virtual int getDetailDocNumOrTopRow();
|
virtual int getDetailDocNumOrTopRow();
|
||||||
|
|
||||||
void setRclMain(RclMain *m, bool ismain);
|
void setRclMain(RclMain *m, bool ismain);
|
||||||
|
void setDefRowHeight();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void onTableView_currentChanged(const QModelIndex&);
|
virtual void onTableView_currentChanged(const QModelIndex&);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user