Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NotebooksModel::NotebooksModel(QObject* parent)
- : QSqlTableModel(parent)
- {
- setTable(QStringLiteral("notebooks"));
- setEditStrategy(QSqlTableModel::OnFieldChange);
- select();
- }
- int NotebooksModel::columnCount(const QModelIndex &parent) const
- {
- Q_UNUSED(parent)
- return 1;
- }
- Qt::ItemFlags NotebooksModel::flags(const QModelIndex &index) const
- {
- return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
- }
- QVariant NotebooksModel::data(const QModelIndex &index, int role) const
- {
- if (!index.isValid())
- return QVariant();
- switch(role)
- {
- case Qt::DisplayRole:
- return QSqlTableModel::data(createIndex(index.row(), Field::Title), role);
- case Qt::EditRole:
- return QSqlTableModel::data(createIndex(index.row(), Field::Title), role);
- case Qt::ToolTipRole:
- return QSqlTableModel::data(createIndex(index.row(), Field::Description), role).toString();
- default:
- return QVariant();
- }
- }
- bool NotebooksModel::setData(const QModelIndex &index, const QVariant &value, int role)
- {
- return QSqlTableModel::setData(createIndex(index.row(), Field::Title), value, role);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement