Modernise testlocales/ program and make it compile
After several years unused, it had bit-rotted to the point of not compiling and failing an assertion. It also appears to have always had a bad free() on exit, due to passing the address of a static object to a function that took ownership and later deleted it. Change-Id: I91856258c3fedf820bf151b5d205d257876a8e13 Reviewed-by: Jason McDonald <macadder1@gmail.com>
This commit is contained in:
parent
1d48bf34db
commit
065548e7b4
@ -680,7 +680,7 @@ LocaleModel::LocaleModel(QObject *parent)
|
||||
QVariant LocaleModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid()
|
||||
|| role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::ToolTipRole
|
||||
|| (role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::ToolTipRole)
|
||||
|| index.column() >= g_model_cols
|
||||
|| index.row() >= g_locale_list_count + 2)
|
||||
return QVariant();
|
||||
@ -821,9 +821,9 @@ int LocaleModel::rowCount(const QModelIndex &parent) const
|
||||
Qt::ItemFlags LocaleModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
return {};
|
||||
if (index.row() == 0 && index.column() == g_model_cols - 1)
|
||||
return 0;
|
||||
return {};
|
||||
if (index.row() == 0)
|
||||
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
||||
return QAbstractItemModel::flags(index);
|
||||
@ -835,7 +835,7 @@ bool LocaleModel::setData(const QModelIndex &index, const QVariant &value, int r
|
||||
|| index.row() != 0
|
||||
|| index.column() >= g_model_cols - 1
|
||||
|| role != Qt::EditRole
|
||||
|| m_data_list.at(index.column()).type() != value.type())
|
||||
|| m_data_list.at(index.column()).typeId() != value.typeId())
|
||||
return false;
|
||||
|
||||
m_data_list[index.column()] = value;
|
||||
|
@ -13,17 +13,17 @@ class LocaleModel : public QAbstractItemModel
|
||||
public:
|
||||
LocaleModel(QObject *parent = nullptr);
|
||||
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
virtual QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QModelIndex parent(const QModelIndex &index) const;
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole ) const;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole);
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const override;
|
||||
QModelIndex parent(const QModelIndex &index) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole ) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
private:
|
||||
QList<QVariant> m_data_list;
|
||||
};
|
||||
|
@ -26,26 +26,26 @@ public:
|
||||
class EditorFactory : public QItemEditorFactory
|
||||
{
|
||||
public:
|
||||
EditorFactory() {
|
||||
static DoubleEditorCreator double_editor_creator;
|
||||
registerEditor(QVariant::Double, &double_editor_creator);
|
||||
EditorFactory()
|
||||
{
|
||||
// registerEditor() assumes ownership of the creator.
|
||||
registerEditor(QVariant::Double, new DoubleEditorCreator);
|
||||
}
|
||||
};
|
||||
|
||||
LocaleWidget::LocaleWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent),
|
||||
m_model(new LocaleModel(this)),
|
||||
m_view(new QTableView(this))
|
||||
{
|
||||
m_model = new LocaleModel(this);
|
||||
m_view = new QTableView(this);
|
||||
|
||||
QStyledItemDelegate *delegate = qobject_cast<QStyledItemDelegate*>(m_view->itemDelegate());
|
||||
Q_ASSERT(delegate != 0);
|
||||
static EditorFactory editor_factory;
|
||||
delegate->setItemEditorFactory(&editor_factory);
|
||||
static EditorFactory editorFactory;
|
||||
delegate->setItemEditorFactory(&editorFactory);
|
||||
|
||||
m_view->setModel(m_model);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setMargin(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(m_view);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
TARGET = testlocales
|
||||
CONFIG += debug
|
||||
QT += widgets
|
||||
SOURCES += localemodel.cpp localewidget.cpp main.cpp
|
||||
HEADERS += localemodel.h localewidget.h
|
Loading…
x
Reference in New Issue
Block a user