| 25 | } |
| 26 | |
| 27 | QWidget * CMakeCacheDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const |
| 28 | { |
| 29 | QWidget *ret=nullptr; |
| 30 | if(index.column()==2) |
| 31 | { |
| 32 | QModelIndex typeIdx=index.sibling(index.row(), 1); |
| 33 | QString type=typeIdx.model()->data(typeIdx, Qt::DisplayRole).toString(); |
| 34 | if(type==QLatin1String("BOOL")) |
| 35 | { |
| 36 | auto* box=new QCheckBox(parent); |
| 37 | connect(box, &QCheckBox::toggled, this, &CMakeCacheDelegate::checkboxToggled); |
| 38 | ret = box; |
| 39 | } |
| 40 | else if(type==QLatin1String("STRING")) |
| 41 | { |
| 42 | QModelIndex stringsIdx=index.sibling(index.row(), 5); |
| 43 | QString strings=typeIdx.model()->data(stringsIdx, Qt::DisplayRole).toString(); |
| 44 | if (!strings.isEmpty()) { |
| 45 | auto* comboBox = new QComboBox(parent); |
| 46 | comboBox->setEditable(true); |
| 47 | comboBox->addItems(strings.split(QLatin1Char(';'))); |
| 48 | ret = comboBox; |
| 49 | } else { |
| 50 | ret=QItemDelegate::createEditor(parent, option, index); |
| 51 | } |
| 52 | } |
| 53 | else if(type==QLatin1String("PATH") || type==QLatin1String("FILEPATH")) |
| 54 | { |
| 55 | auto *r=new KUrlRequester(parent); |
| 56 | if(type==QLatin1String("FILEPATH")) |
| 57 | r->setMode(KFile::File); |
| 58 | else |
| 59 | r->setMode(KFile::Directory | KFile::ExistingOnly); |
| 60 | emit const_cast<CMakeCacheDelegate*>(this)->sizeHintChanged ( index ); |
| 61 | qCDebug(CMAKE) << "EMITINT!" << index; |
| 62 | ret=r; |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | ret=QItemDelegate::createEditor(parent, option, index); |
| 67 | } |
| 68 | |
| 69 | if(!ret) qCDebug(CMAKE) << "Did not recognize type " << type; |
| 70 | } |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | void CMakeCacheDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const |
| 75 | { |