PDA

View Full Version : Access to QSqlTableModel::isDirty Question.



patrik08
12th April 2007, 15:55
I have write a QTableView to edit all mysql table wo having index... ++ limit row
now i use model->setEditStrategy(QSqlTableModel::OnManualSubmit);

Question how i cann access to http://doc.trolltech.com/4.0/qsqltablemodel.html#isDirty to
make question to save submit?






/* discovery total row whitout limit mysql / to play next prev ... button */
void Search_on_Table::UpdateSumm()
{
QString grepprimary,grepauto;
/* reset index fieldname */
/* SHOW INDEX FROM USER_ASSO_0 */
INDEXFIELD = "";
FieldNameList.clear();
const QString info = QString("SHOW COLUMNS FROM %1").arg(table);
QSqlQuery query(info,db);
QSqlRecord rec = query.record();
////int sumcol = rec.count();
while (query.next()) {
grepprimary = query.value(3).toString();
grepprimary = grepprimary.toLower();
grepauto = query.value(5).toString();
grepauto = grepauto.toLower();
Q_ASSERT(grepauto.size() > 1); /* no mysql or not connect! or grand not...*/
if (grepprimary == "pri" && grepauto.contains("auto")) {
INDEXFIELD = query.value(0).toString();
qDebug() << "### INDEXFIELD have found " << INDEXFIELD;
}
FieldNameList.append(query.value(0).toString());
}
totfield = FieldNameList.size();
if (INDEXFIELD.size() < 1) {
haveindex = false;
} else {
haveindex = true;
}
totalrow = 0;
if (haveindex) {
const QString summitem = QString("SELECT COUNT(%2) FROM %1").arg(table).arg(INDEXFIELD);
query.exec(summitem);
while (query.next()) {
totalrow = query.value(0).toInt();
}
label_3->setText(tr("Name: %1 Tot.Row: %2 Index: %3").arg(table).arg(totalrow).arg(INDEXFIELD));
} else {
SqlError(false);
label_3->setText(tr("Name: %1 Not having index!").arg(table));
}
//////qDebug() << "### totalrow " << totalrow;
}

void Search_on_Table::initializeModel( int limitrow )
{
model->setFilter(QString("1 LIMIT %1, %2").arg(status).arg(limitrow));
if (INDEXFIELD.size() > 0) {
for (int i = 0; i < FieldNameList.size(); ++i) {
const QString af = FieldNameList.at(i);
if (af == INDEXFIELD) {
model->setHeaderData(i, Qt::Horizontal, tr("ID/%1").arg(INDEXFIELD));
} else {
model->setHeaderData(i, Qt::Horizontal,af);
}
}
}
SqlError(model->select()); /* pixmap-label green/red */
if (haveindex) {
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
}
tableView->setModel(model);
label_4->setText(tr("Status %1 - %2").arg(status).arg(limitrow));
PaintButton(); /* button enable or disable next prev */
}

wysota
12th April 2007, 17:46
What do you mean "how to access" it? Can't you just call it for the index you're interested in?

patrik08
12th April 2007, 18:30
What do you mean "how to access" it? Can't you just call it for the index you're interested in?

how connect a wake up to QModelIndex

connect(tableView, SIGNAL(activated(QModelIndex)), this, SLOT(WakeUpTable(QModelIndex)));
connect(tableView, SIGNAL(entered(QModelIndex)), this, SLOT(WakeUpTable(QModelIndex)));

model connect not run .... all other button run ..


not run....

to write a WakeUpTable( QModelIndex index )
bool QSqlTableModel::isDirty ( const QModelIndex & index ) const

I like only to know the area wo user update ... to tell question ..... on closeevent( e)
you like save if isDirty is true....?

patrik08
12th April 2007, 18:49
i found ...



connect(tableView->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(WakeUpTable(QModelIndex)));