Advertisement
Guest User

Untitled

a guest
May 8th, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. NotebooksModel::NotebooksModel(QObject* parent)
  2. : QSqlTableModel(parent)
  3. {
  4. setTable(QStringLiteral("notebooks"));
  5. setEditStrategy(QSqlTableModel::OnFieldChange);
  6. select();
  7. }
  8.  
  9. int NotebooksModel::columnCount(const QModelIndex &parent) const
  10. {
  11. Q_UNUSED(parent)
  12.  
  13. return 1;
  14. }
  15.  
  16. Qt::ItemFlags NotebooksModel::flags(const QModelIndex &index) const
  17. {
  18. return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
  19. }
  20.  
  21. QVariant NotebooksModel::data(const QModelIndex &index, int role) const
  22. {
  23. if (!index.isValid())
  24. return QVariant();
  25.  
  26. switch(role)
  27. {
  28. case Qt::DisplayRole:
  29. return QSqlTableModel::data(createIndex(index.row(), Field::Title), role);
  30.  
  31. case Qt::EditRole:
  32. return QSqlTableModel::data(createIndex(index.row(), Field::Title), role);
  33.  
  34. case Qt::ToolTipRole:
  35. return QSqlTableModel::data(createIndex(index.row(), Field::Description), role).toString();
  36.  
  37. default:
  38. return QVariant();
  39. }
  40. }
  41.  
  42. bool NotebooksModel::setData(const QModelIndex &index, const QVariant &value, int role)
  43. {
  44. return QSqlTableModel::setData(createIndex(index.row(), Field::Title), value, role);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement