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
|
QVariant LocaleModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid()
|
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.column() >= g_model_cols
|
||||||
|| index.row() >= g_locale_list_count + 2)
|
|| index.row() >= g_locale_list_count + 2)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@ -821,9 +821,9 @@ int LocaleModel::rowCount(const QModelIndex &parent) const
|
|||||||
Qt::ItemFlags LocaleModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags LocaleModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return {};
|
||||||
if (index.row() == 0 && index.column() == g_model_cols - 1)
|
if (index.row() == 0 && index.column() == g_model_cols - 1)
|
||||||
return 0;
|
return {};
|
||||||
if (index.row() == 0)
|
if (index.row() == 0)
|
||||||
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
||||||
return QAbstractItemModel::flags(index);
|
return QAbstractItemModel::flags(index);
|
||||||
@ -835,7 +835,7 @@ bool LocaleModel::setData(const QModelIndex &index, const QVariant &value, int r
|
|||||||
|| index.row() != 0
|
|| index.row() != 0
|
||||||
|| index.column() >= g_model_cols - 1
|
|| index.column() >= g_model_cols - 1
|
||||||
|| role != Qt::EditRole
|
|| role != Qt::EditRole
|
||||||
|| m_data_list.at(index.column()).type() != value.type())
|
|| m_data_list.at(index.column()).typeId() != value.typeId())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_data_list[index.column()] = value;
|
m_data_list[index.column()] = value;
|
||||||
|
@ -13,17 +13,17 @@ class LocaleModel : public QAbstractItemModel
|
|||||||
public:
|
public:
|
||||||
LocaleModel(QObject *parent = nullptr);
|
LocaleModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
virtual QModelIndex index(int row, int column,
|
QModelIndex index(int row, int column,
|
||||||
const QModelIndex &parent = QModelIndex()) const;
|
const QModelIndex &parent = QModelIndex()) const override;
|
||||||
virtual QModelIndex parent(const QModelIndex &index) const;
|
QModelIndex parent(const QModelIndex &index) const override;
|
||||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
virtual QVariant headerData(int section, Qt::Orientation orientation,
|
QVariant headerData(int section, Qt::Orientation orientation,
|
||||||
int role = Qt::DisplayRole ) const;
|
int role = Qt::DisplayRole ) const override;
|
||||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
virtual bool setData(const QModelIndex &index, const QVariant &value,
|
bool setData(const QModelIndex &index, const QVariant &value,
|
||||||
int role = Qt::EditRole);
|
int role = Qt::EditRole) override;
|
||||||
private:
|
private:
|
||||||
QList<QVariant> m_data_list;
|
QList<QVariant> m_data_list;
|
||||||
};
|
};
|
||||||
|
@ -26,26 +26,26 @@ public:
|
|||||||
class EditorFactory : public QItemEditorFactory
|
class EditorFactory : public QItemEditorFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EditorFactory() {
|
EditorFactory()
|
||||||
static DoubleEditorCreator double_editor_creator;
|
{
|
||||||
registerEditor(QVariant::Double, &double_editor_creator);
|
// registerEditor() assumes ownership of the creator.
|
||||||
|
registerEditor(QVariant::Double, new DoubleEditorCreator);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
LocaleWidget::LocaleWidget(QWidget *parent)
|
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());
|
QStyledItemDelegate *delegate = qobject_cast<QStyledItemDelegate*>(m_view->itemDelegate());
|
||||||
Q_ASSERT(delegate != 0);
|
Q_ASSERT(delegate != 0);
|
||||||
static EditorFactory editor_factory;
|
static EditorFactory editorFactory;
|
||||||
delegate->setItemEditorFactory(&editor_factory);
|
delegate->setItemEditorFactory(&editorFactory);
|
||||||
|
|
||||||
m_view->setModel(m_model);
|
m_view->setModel(m_model);
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
layout->setMargin(0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
layout->addWidget(m_view);
|
layout->addWidget(m_view);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
TARGET = testlocales
|
TARGET = testlocales
|
||||||
CONFIG += debug
|
CONFIG += debug
|
||||||
|
QT += widgets
|
||||||
SOURCES += localemodel.cpp localewidget.cpp main.cpp
|
SOURCES += localemodel.cpp localewidget.cpp main.cpp
|
||||||
HEADERS += localemodel.h localewidget.h
|
HEADERS += localemodel.h localewidget.h
|
||||||
|
Loading…
x
Reference in New Issue
Block a user