Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • new-money
  • dev
  • serial
  • plot
  • stast
  • acquisition-dialog
  • multiacc
  • v1.18
  • v1.17.4
  • v1.17.3
  • v1.17.2
  • v1.17.1
  • v1.17
  • v1.16
  • v1.15
  • v1.14.1
  • v1.14
  • v1.13.42
  • v1.13.41
  • v1.13
  • v1.12
  • v1.11
  • v1.10
  • v1.9
  • acquisition
  • v1.8
  • v1.7
28 results

disablingmodel.h

Blame
  • disablingmodel.h 1.55 KiB
    #ifndef DISABLINGVIEW_H
    #define DISABLINGVIEW_H
    
    #include <QSqlRelationalTableModel>
    #include <QSqlDatabase>
    
    /*
     * An extension of QSqlRelationalTableModel where some columns can be
     * set to be non editing
     */
    /**
     * @brief A QSqlRelationalTableModel where specific columns can be disabled.
     *
     * Generally the only the whole table can be enabled or disabled. This allows creating
     * a model where some columns are disabled for editing, while the remaining allow editing.
     *
     * The set of Qt::ItemFlags used for the active and inactive columns can be changed by
     * simply setting the fields.
     */
    class DisablingModel : public QSqlRelationalTableModel
    {
    public:
        /**
         * @brief Constructs the model
         * @param disabledColumns Indexes which shouldn't be editable.
         * @param parent For Qt Cleanup.
         * @param db Active connection for underlying QSqlTableModel
         */
        DisablingModel(QList<int> disabledColumns, QObject* parent = nullptr, QSqlDatabase db = QSqlDatabase());
    
        /**
         * @brief Flags used for active columns.
         */
        Qt::ItemFlags activeFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
        /**
         * @brief Flags used for inactive columns.
         */
        Qt::ItemFlags inactiveFlags = Qt::ItemIsSelectable | Qt::ItemIsEditable;
    
        /**
         * @brief Flags for the given index.
         * @param index row and column to index.
         * @return either activeFlags, or inactiveFlags
         */
        virtual Qt::ItemFlags flags (const QModelIndex &index) const override;
    
    private:
        QList<int> disabledColumns;
    };
    #endif // DISABLINGVIEW_H