Results 1 to 8 of 8

Thread: QsqlQueryModel Subclass

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Apr 2013
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QsqlQueryModel Subclass

    Thanks for your replay,

    I implemented data and setdata from your example. But the data in the proxy column is not editable.
    Even when i reimplemented flags the column stayed gray and did not call setdata.
    EDIT sloved graynes by returning Qt::ItemIsEnabled flag EDIT
    What I'm doing wrong?

    compiling the code with qt 5 i got an error on row 74.

    return createIndex(row, column, 0);
    call of overloaded 'createIndex(int&, int&, int)' is ambiguous
    so i used the default. createIndex(int&, int&)


    Qt Code:
    1. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
    2. {
    3. if((index.column() <= 0) and (role == Qt::DisplayRole)){
    4.  
    5. //return QString("Proxy Data - Row:%1").arg(index.row());
    6.  
    7. for (int i = 0; i < LastColumn.count();++i){
    8.  
    9. if (LastColumn[i].first == index.row())
    10. return LastColumn[i].second;
    11. }
    12.  
    13. return QString("temp");
    14.  
    15. }
    16.  
    17. return sourceModel()->data(mapToSource(index), role);
    18. }
    19.  
    20. bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
    21. {
    22. qDebug() << "setdata";
    23.  
    24. if((index.column() <= 0) and (role == Qt::EditRole))
    25. {
    26. // TODO: store data into ProxyModel
    27. for ( int i = 0; i < LastColumn.count();++i){
    28.  
    29. if (LastColumn[i].first == index.row()){
    30. LastColumn.removeAt(i);
    31. LastColumn.append(qMakePair(index.row(),value.toString()));
    32. return true;
    33. }
    34. }
    35.  
    36. LastColumn.append(qMakePair(index.row(),value.toString()));
    37. return true;
    38. }
    39. return sourceModel()->setData(mapToSource(index), role);
    40. }
    41.  
    42. Qt::ItemFlags flags ( const QModelIndex & index ) const{
    43.  
    44. if (index.column() <= 0){
    45.  
    46. return (Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    47.  
    48. }
    49.  
    50. return QAbstractProxyModel::flags(index);
    51.  
    52. }
    53.  
    54. private:
    55. QList<QPair<int,QString> > LastColumn;
    To copy to clipboard, switch view to plain text mode 
    Last edited by Delphi; 15th May 2013 at 12:44.

Similar Threads

  1. Replies: 2
    Last Post: 15th April 2013, 06:33
  2. QSqlQueryModel
    By StefanLatsch in forum Qt Programming
    Replies: 1
    Last Post: 7th December 2010, 11:09
  3. Does 'QSqlQueryModel' have a bug?
    By nuntawat in forum Qt Programming
    Replies: 8
    Last Post: 6th April 2010, 17:45
  4. Replies: 8
    Last Post: 12th February 2010, 02:41
  5. QSqlQueryModel write subclass
    By skuda in forum Qt Programming
    Replies: 6
    Last Post: 29th October 2007, 16:18

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.