-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bool delegate for True,False parameters for BlueSky
- Loading branch information
Arthur Glowacki
committed
Dec 17, 2024
1 parent
64a80d9
commit a5f63dc
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/*----------------------------------------------------------------------------- | ||
* Copyright (c) 2012, UChicago Argonne, LLC | ||
* See LICENSE file. | ||
*---------------------------------------------------------------------------*/ | ||
|
||
#include <mvc/ComboBoxBoolDelegate.h> | ||
#include <QComboBox> | ||
#include <QWidget> | ||
#include <QModelIndex> | ||
#include <QApplication> | ||
#include <QString> | ||
|
||
#include <iostream> | ||
|
||
//--------------------------------------------------------------------------- | ||
|
||
ComboBoxBoolDelegate::ComboBoxBoolDelegate(QObject *parent) : QItemDelegate(parent) | ||
{ | ||
Items = {"False", "True"}; | ||
_custom_col = -1; | ||
} | ||
|
||
//--------------------------------------------------------------------------- | ||
|
||
QWidget *ComboBoxBoolDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const | ||
{ | ||
QComboBox* editor = new QComboBox(parent); | ||
for(unsigned int i = 0; i < Items.size(); ++i) | ||
{ | ||
editor->addItem(Items[i].c_str()); | ||
} | ||
return editor; | ||
} | ||
|
||
//--------------------------------------------------------------------------- | ||
|
||
void ComboBoxBoolDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const | ||
{ | ||
QComboBox *comboBox = static_cast<QComboBox*>(editor); | ||
QString value = index.model()->data(index, Qt::EditRole).toString(); | ||
if(value == "False") | ||
{ | ||
comboBox->setCurrentIndex(0); | ||
} | ||
else | ||
{ | ||
comboBox->setCurrentIndex(1); | ||
} | ||
} | ||
|
||
//--------------------------------------------------------------------------- | ||
|
||
void ComboBoxBoolDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const | ||
{ | ||
QComboBox *comboBox = static_cast<QComboBox*>(editor); | ||
model->setData(index, comboBox->currentIndex(), Qt::EditRole); | ||
} | ||
|
||
//--------------------------------------------------------------------------- | ||
|
||
void ComboBoxBoolDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const | ||
{ | ||
editor->setGeometry(option.rect); | ||
} | ||
|
||
//--------------------------------------------------------------------------- | ||
|
||
void ComboBoxBoolDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const | ||
{ | ||
QStyleOptionViewItem myOption = option; | ||
myOption.text = index.data().toString(); | ||
if(_custom_col > -1 ) | ||
{ | ||
if(_custom_col == index.column()) | ||
{ | ||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOption, painter); | ||
} | ||
else | ||
{ | ||
QItemDelegate::paint(painter, option, index); | ||
} | ||
} | ||
else | ||
{ | ||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOption, painter); | ||
} | ||
} | ||
|
||
//--------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*----------------------------------------------------------------------------- | ||
* Copyright (c) 2012, UChicago Argonne, LLC | ||
* See LICENSE file. | ||
*---------------------------------------------------------------------------*/ | ||
|
||
#ifndef COMBO_BOX_BOOL_DELEGATE_H | ||
#define COMBO_BOX_BOOL_DELEGATE_H | ||
|
||
//--------------------------------------------------------------------------- | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include <QItemDelegate> | ||
#include <QModelIndex> | ||
#include <QWidget> | ||
#include <QVariant> | ||
|
||
class ComboBoxBoolDelegate : public QItemDelegate | ||
{ | ||
Q_OBJECT | ||
public: | ||
ComboBoxBoolDelegate(QObject *parent = 0); | ||
|
||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; | ||
void setEditorData(QWidget *editor, const QModelIndex &index) const; | ||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; | ||
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const; | ||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; | ||
|
||
void setCustomCol(int col) {_custom_col = col;} | ||
|
||
private: | ||
std::vector<std::string> Items; | ||
int _custom_col; | ||
}; | ||
|
||
//--------------------------------------------------------------------------- | ||
|
||
#endif | ||
|
||
//--------------------------------------------------------------------------- |