mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Fix perf issues and crash when showing 1'100'000 items (#9968)
This commit is contained in:
parent
97521c4ec4
commit
b3bed2927e
@ -27,8 +27,6 @@
|
|||||||
#include "support/gettext.h"
|
#include "support/gettext.h"
|
||||||
|
|
||||||
#include <QChar>
|
#include <QChar>
|
||||||
#include <QPixmap>
|
|
||||||
#include <QListWidgetItem>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -169,7 +167,7 @@ QString getBlock(char_type c)
|
|||||||
&& c <= unicode_blocks[lastBlock].end)
|
&& c <= unicode_blocks[lastBlock].end)
|
||||||
return qt_(unicode_blocks[lastBlock].name);
|
return qt_(unicode_blocks[lastBlock].name);
|
||||||
|
|
||||||
// c falls into an uncovered area, but we can guess which
|
// c falls into an uncovered area, but we can guess which
|
||||||
if (c > unicode_blocks[lastBlock].end
|
if (c > unicode_blocks[lastBlock].end
|
||||||
&& c < unicode_blocks[lastBlock + 1].start)
|
&& c < unicode_blocks[lastBlock + 1].start)
|
||||||
return QString();
|
return QString();
|
||||||
@ -195,11 +193,11 @@ QString getBlock(char_type c)
|
|||||||
//
|
//
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class GuiSymbols::Model : public QAbstractItemModel
|
class GuiSymbols::Model : public QAbstractListModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Model(GuiSymbols * parent)
|
Model(GuiSymbols * parent)
|
||||||
: QAbstractItemModel(parent)
|
: QAbstractListModel(parent)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QModelIndex index(int row, int column, QModelIndex const &) const
|
QModelIndex index(int row, int column, QModelIndex const &) const
|
||||||
@ -217,42 +215,40 @@ public:
|
|||||||
return symbols_.count();
|
return symbols_.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
int columnCount(QModelIndex const &) const
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant data(QModelIndex const & index, int role) const
|
QVariant data(QModelIndex const & index, int role) const
|
||||||
{
|
{
|
||||||
static QString const strCharacter = qt_("Character: ");
|
static QString const strCharacter = qt_("Character: ");
|
||||||
static QString const strCodePoint = qt_("Code Point: ");
|
static QString const strCodePoint = qt_("Code Point: ");
|
||||||
|
|
||||||
char_type c = symbols_.at(index.row());
|
char_type c = symbols_.at(index.row());
|
||||||
|
|
||||||
if (role == Qt::TextAlignmentRole)
|
switch (role) {
|
||||||
|
case Qt::TextAlignmentRole:
|
||||||
return QVariant(Qt::AlignCenter);
|
return QVariant(Qt::AlignCenter);
|
||||||
|
case Qt::DisplayRole:
|
||||||
if (role == Qt::DisplayRole)
|
|
||||||
return toqstr(c);
|
return toqstr(c);
|
||||||
|
case Qt::ToolTipRole: {
|
||||||
if (role == Qt::ToolTipRole) {
|
char codeName[10];
|
||||||
// FIXME THREAD
|
|
||||||
static char codeName[10];
|
|
||||||
|
|
||||||
sprintf(codeName, "0x%04x", c);
|
sprintf(codeName, "0x%04x", c);
|
||||||
return strCharacter + toqstr(c) + '\n'
|
return strCharacter + toqstr(c) + '\n'
|
||||||
+ strCodePoint + QLatin1String(codeName);
|
+ strCodePoint + QLatin1String(codeName);
|
||||||
}
|
}
|
||||||
|
case Qt::SizeHintRole:
|
||||||
//LYXERR0("role: " << role << " row: " << index.row());
|
// Fix many symbols not displaying in combination with
|
||||||
return QVariant();
|
// setUniformItemSizes
|
||||||
|
return QSize(1000,1000);
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSymbols(QList<char_type> const & symbols)
|
void setSymbols(QList<char_type> const & symbols)
|
||||||
{
|
{
|
||||||
QAbstractItemModel::beginResetModel();
|
beginResetModel();
|
||||||
|
beginInsertRows(QModelIndex(), 0, symbols.size() - 1);
|
||||||
symbols_ = symbols;
|
symbols_ = symbols;
|
||||||
QAbstractItemModel::endResetModel();
|
endInsertRows();
|
||||||
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -277,16 +273,20 @@ GuiSymbols::GuiSymbols(GuiView & lv)
|
|||||||
setFocusProxy(symbolsLW);
|
setFocusProxy(symbolsLW);
|
||||||
|
|
||||||
symbolsLW->setViewMode(QListView::IconMode);
|
symbolsLW->setViewMode(QListView::IconMode);
|
||||||
|
symbolsLW->setLayoutMode(QListView::Batched);
|
||||||
|
symbolsLW->setBatchSize(1000);
|
||||||
|
symbolsLW->setUniformItemSizes(true);
|
||||||
|
|
||||||
// increase the display size of the symbols a bit
|
// increase the display size of the symbols a bit
|
||||||
QFont font = symbolsLW->font();
|
QFont font = symbolsLW->font();
|
||||||
const int size = font.pointSize() + 3;
|
const int size = font.pointSize() + 3;
|
||||||
font.setPointSize(size);
|
font.setPointSize(size);
|
||||||
symbolsLW->setFont(font);
|
symbolsLW->setFont(font);
|
||||||
QFontMetrics fm(font);
|
QFontMetrics fm(font);
|
||||||
const int cellHeight = fm.height() + 2;
|
const int cellHeight = fm.height() + 6;
|
||||||
// FIXME: using at least cellHeight because of
|
// FIXME: using at least cellHeight because of
|
||||||
// QFontMetrics::maxWidth() is returning 0 with Qt/Cocoa on Mac OS
|
// 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->setGridSize(QSize(cellWidth, cellHeight));
|
||||||
symbolsLW->setModel(model_);
|
symbolsLW->setModel(model_);
|
||||||
}
|
}
|
||||||
@ -387,7 +387,7 @@ void GuiSymbols::on_categoryFilterCB_toggled(bool on)
|
|||||||
{
|
{
|
||||||
updateSymbolList(on);
|
updateSymbolList(on);
|
||||||
if (on)
|
if (on)
|
||||||
scrollToItem(categoryCO->currentText());
|
scrollToItem(categoryCO->currentText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user