QVariant OperationModel::data(const QModelIndex &index, int role) const { if (index.isValid()) { int row = index.row(); if (row >= 0 && row < m_items.count()) { Operation *item = m_items[row]; if (role == IndexRole){ return QVariant(item->index()); } else if (role == Qt::DisplayRole || role == NameRole) { return QVariant(item->name()); } else if (role == LastDateRole) { return QVariant(item->lastDate()); } else if (role == BonsaiIdRole) { return QVariant(item->bonsaiId()); } else { return QVariant("ERR: Unknown role for daymodel: " + role); } } else { return QVariant("ERR: Invalid index"); } } else { return QVariant("ERR: Invalid index"); } return QVariant("ERR: other"); }
bool OperationModel::insert(Operation &op) { //TODO if db open QSqlQuery query(db); query.prepare("INSERT INTO operations ( name, bonsai_id, last_date) VALUES ( ?, ?, ? )"); query.bindValue(0, op.name()); query.bindValue(1, op.bonsaiId()); query.bindValue(2, op.lastDate()); bool ret = query.exec(); if(!ret) qDebug() << query.lastError(); //addRow(op); return ret; }