mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Fix perf issues and crash when showing 1'100'000 items (#9968)
This commit is contained in:
parent
997349280e
commit
13a993fda8
@ -27,8 +27,6 @@
|
||||
#include "support/gettext.h"
|
||||
|
||||
#include <QChar>
|
||||
#include <QPixmap>
|
||||
#include <QListWidgetItem>
|
||||
#include <QString>
|
||||
|
||||
#include <cstdio>
|
||||
@ -194,11 +192,11 @@ QString getBlock(char_type c)
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
class GuiSymbols::Model : public QAbstractItemModel
|
||||
class GuiSymbols::Model : public QAbstractListModel
|
||||
{
|
||||
public:
|
||||
Model(GuiSymbols * parent)
|
||||
: QAbstractItemModel(parent)
|
||||
: QAbstractListModel(parent)
|
||||
{}
|
||||
|
||||
QModelIndex index(int row, int column, QModelIndex const &) const
|
||||
@ -216,11 +214,6 @@ public:
|
||||
return symbols_.count();
|
||||
}
|
||||
|
||||
int columnCount(QModelIndex const &) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant data(QModelIndex const & index, int role) const
|
||||
{
|
||||
static QString const strCharacter = qt_("Character: ");
|
||||
@ -230,27 +223,33 @@ public:
|
||||
|
||||
char_type c = symbols_.at(index.row());
|
||||
|
||||
if (role == Qt::TextAlignmentRole)
|
||||
switch (role) {
|
||||
case Qt::TextAlignmentRole:
|
||||
return QVariant(Qt::AlignCenter);
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
case Qt::DisplayRole:
|
||||
return toqstr(c);
|
||||
|
||||
if (role == Qt::ToolTipRole) {
|
||||
case Qt::ToolTipRole: {
|
||||
char codeName[10];
|
||||
sprintf(codeName, "0x%04x", c);
|
||||
return strCharacter + toqstr(c) + '\n'
|
||||
+ strCodePoint + QLatin1String(codeName);
|
||||
}
|
||||
|
||||
//LYXERR0("role: " << role << " row: " << index.row());
|
||||
return QVariant();
|
||||
case Qt::SizeHintRole:
|
||||
// Fix many symbols not displaying in combination with
|
||||
// setUniformItemSizes
|
||||
return QSize(1000,1000);
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
void setSymbols(QList<char_type> const & symbols)
|
||||
{
|
||||
QAbstractItemModel::beginResetModel();
|
||||
beginResetModel();
|
||||
beginInsertRows(QModelIndex(), 0, symbols.size() - 1);
|
||||
symbols_ = symbols;
|
||||
QAbstractItemModel::endResetModel();
|
||||
endInsertRows();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -275,16 +274,20 @@ GuiSymbols::GuiSymbols(GuiView & lv)
|
||||
setFocusProxy(symbolsLW);
|
||||
|
||||
symbolsLW->setViewMode(QListView::IconMode);
|
||||
symbolsLW->setLayoutMode(QListView::Batched);
|
||||
symbolsLW->setBatchSize(1000);
|
||||
symbolsLW->setUniformItemSizes(true);
|
||||
|
||||
// increase the display size of the symbols a bit
|
||||
QFont font = symbolsLW->font();
|
||||
const int size = font.pointSize() + 3;
|
||||
font.setPointSize(size);
|
||||
symbolsLW->setFont(font);
|
||||
QFontMetrics fm(font);
|
||||
const int cellHeight = fm.height() + 2;
|
||||
const int cellHeight = fm.height() + 6;
|
||||
// FIXME: using at least cellHeight because of
|
||||
// QFontMetrics::maxWidth() is returning 0 with Qt/Cocoa on Mac OS
|
||||
const int cellWidth = max(cellHeight, fm.maxWidth() + 2);
|
||||
const int cellWidth = max(cellHeight - 2, fm.maxWidth() + 4);
|
||||
symbolsLW->setGridSize(QSize(cellWidth, cellHeight));
|
||||
symbolsLW->setModel(model_);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user