Skip to content
Snippets Groups Projects
Select Git revision
  • 76a79e300e592d29ca47c2f90d121547c0d45a23
  • master default protected
  • 9.0
  • 8.0
  • nt-tools
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2020
  • v8.0.2018
  • v8.0.2016
  • v8.0.2014
  • v8.0.2012
  • v8.0.2008
  • v8.0.2006
  • v8.0.2004
  • v8.0.2002
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
41 results

dynamic_buffer.h

Blame
  • comboboxitemdelegate.cpp 1.69 KiB
    #include "comboboxitemdelegate.h"
    
    #include <QComboBox>
    #include <QtCore>
    
    #include <QTableView>
    
    static QString get_index_string(int);
    
    ComboBoxItemDelegate::ComboBoxItemDelegate(QObject* parent) : QStyledItemDelegate(parent) {}
    
    // TODO should the destructor actually do anything
    ComboBoxItemDelegate::~ComboBoxItemDelegate() {}
    
    // initialises initial data
    QWidget* ComboBoxItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const
    {
        QComboBox* cb = new QComboBox(parent);
        for (int i = 0; i < 3; i++)
            cb->addItem(get_index_string(i));
        return cb;
    }
    
    // Sets data when clicked
    void ComboBoxItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    {
        if (QComboBox* cb = qobject_cast<QComboBox*>(editor)) {
            cb->setCurrentIndex(index.data().toInt());
        } else
            QStyledItemDelegate::setEditorData(editor, index);
    }
    
    // sets return data
    void ComboBoxItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
    {
        if (QComboBox* cb = qobject_cast<QComboBox*>(editor))
            model->setData(index, cb->currentIndex(), Qt::EditRole);
        else
            QStyledItemDelegate::setModelData(editor, model, index);
    }
    
    // sets what's displayed when not in edit mode
    QString ComboBoxItemDelegate::displayText(const QVariant &value, const QLocale& /*locale*/) const
    {
        return get_index_string(value.toInt());
    }
    
    static QString get_index_string(int index) {
        switch (index) {
            case 0:
                return "Till salu";
            case 1:
                return "Ej till salu";
            case 2:
                return "Dold";
            default:
                return "ERROR";
        }
    }