query.bindValue(":id", id);
return query.exec();
}
+
+bool EmuFrontFileObjectModel::insertRows(int row, int count, const QModelIndex &parent)
+{
+ if (parent.isValid())
+ return false;
+ if (rowCount() < row)
+ row = rowCount() + 1;
+ qDebug() << "Inserting " << count << " rows from row " << row;
+ QSqlQuery q;
+ q.prepare(QString("INSERT INTO %1 (id, name, fileid) "
+ " VALUES (NULL, '', NULL) ").arg(tableName));
+ beginInsertRows(QModelIndex(), row, row + count - 1);
+ for (int i = 0; i < count; ++i) {
+ q.exec();
+ }
+ endInsertRows();
+ return true;
+}
EmuFrontFileObjectModel(QObject *parent = 0);
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
+ bool insertRows(int row, int count, const QModelIndex &parent);
enum {
EmuFrontFileObject_Id,
EmuFrontFileObject_Name,
void EmuFrontDataDialog::addButtonClicked()
{
qDebug() << "Delete button clicked";
+ int row = objectList->currentIndex().row();
+ if (row == -1) row = 0;
+ model->insertRows(row, 1);
+ QModelIndex ind = model->index(row, 1);
+ if (!ind.isValid()){
+ qDebug() << "Invalid index";
+ return;
+ }
+ objectList->setCurrentIndex(ind);
+ objectList->edit(ind);
}