Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. class CorrespondenceModel
  2.     :   public QStandardItemModel
  3. {
  4. public:
  5.     CorrespondenceModel( QObject * parent = 0 )
  6.         :   QStandardItemModel( 0, 2, parent )
  7.     {
  8.         setHeaderData( 0, Qt::Horizontal, tr( "Excel file" ) );
  9.         setHeaderData( 1, Qt::Horizontal, tr( "Format" ) );
  10.     }
  11.  
  12.     Qt::ItemFlags flags( const QModelIndex & index ) const
  13.     {
  14.         if( !index.isValid() )
  15.             return 0;
  16.  
  17.         if( index.column() == 1 )
  18.             return Qt::ItemIsEditable | Qt::ItemIsSelectable |
  19.                 Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
  20.         else
  21.             return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable |
  22.                 Qt::ItemIsEnabled;
  23.     }
  24.  
  25.     void insertRow( const QString & excelFile,
  26.         const QString & format )
  27.     {
  28.         beginInsertRows( QModelIndex(), 0, 0 );
  29.  
  30.         QStandardItemModel::insertRow( 0 );
  31.  
  32.         setData( index( 0, 0, QModelIndex() ),
  33.             excelFile, Qt::DisplayRole );
  34.         setData( index( 0, 1, QModelIndex() ),
  35.             format, Qt::DisplayRole );
  36.  
  37.         endInsertRows();
  38.     }
  39.  
  40.     QString excelFile( int row ) const
  41.     {
  42.         return data( index( row, 0 ) ).toString();
  43.     }
  44.  
  45.     QString format( int row ) const
  46.     {
  47.         return data( index( row, 1 ) ).toString();
  48.     }
  49. }; // class CorrespondenceModel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement