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/qsqltab...l.html#isDirty to
make question to save submit?



Qt Code:
  1. /* discovery total row whitout limit mysql / to play next prev ... button */
  2. void Search_on_Table::UpdateSumm()
  3. {
  4. QString grepprimary,grepauto;
  5. /* reset index fieldname */
  6. /* SHOW INDEX FROM USER_ASSO_0 */
  7. INDEXFIELD = "";
  8. FieldNameList.clear();
  9. const QString info = QString("SHOW COLUMNS FROM %1").arg(table);
  10. QSqlQuery query(info,db);
  11. QSqlRecord rec = query.record();
  12. ////int sumcol = rec.count();
  13. while (query.next()) {
  14. grepprimary = query.value(3).toString();
  15. grepprimary = grepprimary.toLower();
  16. grepauto = query.value(5).toString();
  17. grepauto = grepauto.toLower();
  18. Q_ASSERT(grepauto.size() > 1); /* no mysql or not connect! or grand not...*/
  19. if (grepprimary == "pri" && grepauto.contains("auto")) {
  20. INDEXFIELD = query.value(0).toString();
  21. qDebug() << "### INDEXFIELD have found " << INDEXFIELD;
  22. }
  23. FieldNameList.append(query.value(0).toString());
  24. }
  25. totfield = FieldNameList.size();
  26. if (INDEXFIELD.size() < 1) {
  27. haveindex = false;
  28. } else {
  29. haveindex = true;
  30. }
  31. totalrow = 0;
  32. if (haveindex) {
  33. const QString summitem = QString("SELECT COUNT(%2) FROM %1").arg(table).arg(INDEXFIELD);
  34. query.exec(summitem);
  35. while (query.next()) {
  36. totalrow = query.value(0).toInt();
  37. }
  38. label_3->setText(tr("Name: %1 Tot.Row: %2 Index: %3").arg(table).arg(totalrow).arg(INDEXFIELD));
  39. } else {
  40. SqlError(false);
  41. label_3->setText(tr("Name: %1 Not having index!").arg(table));
  42. }
  43. //////qDebug() << "### totalrow " << totalrow;
  44. }
  45.  
  46. void Search_on_Table::initializeModel( int limitrow )
  47. {
  48. model->setFilter(QString("1 LIMIT %1, %2").arg(status).arg(limitrow));
  49. if (INDEXFIELD.size() > 0) {
  50. for (int i = 0; i < FieldNameList.size(); ++i) {
  51. const QString af = FieldNameList.at(i);
  52. if (af == INDEXFIELD) {
  53. model->setHeaderData(i, Qt::Horizontal, tr("ID/%1").arg(INDEXFIELD));
  54. } else {
  55. model->setHeaderData(i, Qt::Horizontal,af);
  56. }
  57. }
  58. }
  59. SqlError(model->select()); /* pixmap-label green/red */
  60. if (haveindex) {
  61. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
  62. }
  63. tableView->setModel(model);
  64. label_4->setText(tr("Status %1 - %2").arg(status).arg(limitrow));
  65. PaintButton(); /* button enable or disable next prev */
  66. }
To copy to clipboard, switch view to plain text mode