mirror of https://github.com/qt/qtbase.git
Widgets snippets: Use the header file instead of a new class each time
In several snippets, the TableModel class is created and used. I included a header file to avoid code repetition. Change-Id: Ie6318606cc89a2f5f1c137a36195fe290b6c1be6 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
ae6f389942
commit
46b8f2eb1a
|
@ -13,29 +13,7 @@
|
|||
#include <QItemSelectionModel>
|
||||
#include <QTableView>
|
||||
|
||||
class TableModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TableModel(int rows, int columns, QObject *parent = nullptr)
|
||||
: QAbstractTableModel(parent), m_rows(rows), m_columns(columns) {}
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override {
|
||||
return m_rows;
|
||||
}
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override {
|
||||
return m_columns;
|
||||
}
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
private:
|
||||
int m_rows, m_columns;
|
||||
|
||||
};
|
||||
#include "../common-table-model/model.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
|
|
@ -17,25 +17,7 @@
|
|||
#include <QTableView>
|
||||
|
||||
#include "../include/mainwindow.h"
|
||||
|
||||
class TableModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TableModel(int rows, int columns, QObject *parent = nullptr) {}
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override {
|
||||
return QVariant();
|
||||
}
|
||||
};
|
||||
#include "../common-table-model/model.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
|
|
|
@ -13,25 +13,7 @@
|
|||
#include <QItemSelectionModel>
|
||||
#include <QTableView>
|
||||
|
||||
class TableModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TableModel(int rows, int columns, QObject *parent = nullptr)
|
||||
: QAbstractTableModel(parent), rowCount(rows), columnCount(columns) {}
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override {
|
||||
return columnCount;
|
||||
}
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override {
|
||||
return QVariant();
|
||||
}
|
||||
};
|
||||
#include "../common-table-model/model.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
|
|
@ -15,26 +15,7 @@
|
|||
#include <QTableView>
|
||||
|
||||
#include "../include/mainwindow.h"
|
||||
|
||||
class TableModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TableModel(int rows, int columns, QObject *parent = nullptr)
|
||||
: QAbstractTableModel(parent) {}
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override {
|
||||
return QVariant();
|
||||
}
|
||||
};
|
||||
#include "../common-table-model/model.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
|
|
Loading…
Reference in New Issue