{
tas = ta;
}
{
/////////qDebug() << "### index-column " << index.column();
if (index.column() == 0) {
int xnummer = index.model()->data(index, Qt::DisplayRole).toInt();
this->createEditor(tas, option, index);
} else if (index.column() == 1) {
QString coder
= index.
model()->data
(index, Qt
::DisplayRole).
toString();
myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
myOption.
palette.
setColor( QPalette::Text , Qt
::red );
drawDisplay(painter, myOption, myOption.rect,coder);
drawFocus(painter, myOption, myOption.rect);
} else if (index.column() == 8) {
QString anno
= index.
model()->data
(index, Qt
::DisplayRole).
toString();
//////////////QString coda = BerufHuman(coder);
myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
if (anno !="0") {
myOption.
palette.
setColor( QPalette::Text , Qt
::gray );
} else {
myOption.
palette.
setColor( QPalette::Text , Qt
::white );
}
drawDisplay(painter, myOption, myOption.rect,anno);
drawFocus(painter, myOption, myOption.rect);
} else{
}
}
{
if (index.column() == 11 || index.column() == 7 ) {
editor->setDisplayFormat("dd.MM.yyyy");
editor->setCalendarPopup(true);
return editor;
} else if (index.column() == 0) {
Base_Button *editora = new Base_Button(parent);
return editora;
} else {
}
}
{
if (index.column() == 11 || index.column() == 7 ) {
QString dateuser
= index.
model()->data
(index, Qt
::DisplayRole).
toString();
QDateTimeEdit *editorrun
= qobject_cast<QDateTimeEdit
*>
(editor
);
if (editorrun) {
editorrun
->setDate
(QDate::fromString(index.
model()->data
(index, Qt
::EditRole).
toString(),
"dd.MM.yyyy"));
}
} else if (index.column() == 0) {
int xnummer = index.model()->data(index, Qt::DisplayRole).toInt();
Base_Button *editorax = qobject_cast<Base_Button *>(editor);
editorax->SetNummer(xnummer);
} else {
}
}
{
if (index.column() == 11 || index.column() == 7 ) {
QDateTimeEdit *dateEditor
= qobject_cast<QDateTimeEdit
*>
(editor
);
if (dateEditor) {
model->setData(index,dateEditor->date().toString("dd.MM.yyyy"));
}
} else if (index.column() == 0) {
Base_Button *editorax = qobject_cast<Base_Button *>(editor);
model->setData(index,editorax->GetNummer());
} else {
}
}
{
Q_OBJECT
//
public:
{
setAttribute(Qt::WA_WindowPropagation);
widgetLayout->setMargin(0);
widgetLayout->setSpacing(0);
pushButton->setText(tr("Edit Nr. 0"));
widgetLayout->addWidget(pushButton);
}
void SetNummer( int numero ) {
identificativo = numero;
pushButton->setText(tr("Edit Nr. %1").arg(identificativo));
}
int GetNummer() {
return identificativo;
}
private:
int identificativo;
protected:
signals:
public slots:
};
{
Q_OBJECT
public:
private slots:
private:
};
BaseDelegate::BaseDelegate( QTableView *ta , QObject *parent )
:QSqlRelationalDelegate(parent)
{
tas = ta;
}
void BaseDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
/////////qDebug() << "### index-column " << index.column();
if (index.column() == 0) {
int xnummer = index.model()->data(index, Qt::DisplayRole).toInt();
this->createEditor(tas, option, index);
} else if (index.column() == 1) {
QString coder = index.model()->data(index, Qt::DisplayRole).toString();
QStyleOptionViewItem myOption = option;
myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
myOption.palette.setColor( QPalette::Text , Qt::red );
drawDisplay(painter, myOption, myOption.rect,coder);
drawFocus(painter, myOption, myOption.rect);
} else if (index.column() == 8) {
QString anno = index.model()->data(index, Qt::DisplayRole).toString();
//////////////QString coda = BerufHuman(coder);
QStyleOptionViewItem myOption = option;
myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
if (anno !="0") {
myOption.palette.setColor( QPalette::Text , Qt::gray );
} else {
myOption.palette.setColor( QPalette::Text , Qt::white );
}
drawDisplay(painter, myOption, myOption.rect,anno);
drawFocus(painter, myOption, myOption.rect);
} else{
QItemDelegate::paint(painter, option, index);
}
}
QWidget *BaseDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.column() == 11 || index.column() == 7 ) {
QDateTimeEdit *editor = new QDateTimeEdit(parent);
editor->setDisplayFormat("dd.MM.yyyy");
editor->setCalendarPopup(true);
return editor;
} else if (index.column() == 0) {
Base_Button *editora = new Base_Button(parent);
return editora;
} else {
return QItemDelegate::createEditor(parent, option, index);
}
}
void BaseDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if (index.column() == 11 || index.column() == 7 ) {
QString dateuser = index.model()->data(index, Qt::DisplayRole).toString();
QDateTimeEdit *editorrun = qobject_cast<QDateTimeEdit *>(editor);
if (editorrun) {
editorrun->setDate(QDate::fromString(index.model()->data(index, Qt::EditRole).toString(), "dd.MM.yyyy"));
}
} else if (index.column() == 0) {
int xnummer = index.model()->data(index, Qt::DisplayRole).toInt();
Base_Button *editorax = qobject_cast<Base_Button *>(editor);
editorax->SetNummer(xnummer);
} else {
QItemDelegate::setEditorData(editor, index);
}
}
void BaseDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if (index.column() == 11 || index.column() == 7 ) {
QDateTimeEdit *dateEditor = qobject_cast<QDateTimeEdit *>(editor);
if (dateEditor) {
model->setData(index,dateEditor->date().toString("dd.MM.yyyy"));
}
} else if (index.column() == 0) {
Base_Button *editorax = qobject_cast<Base_Button *>(editor);
model->setData(index,editorax->GetNummer());
} else {
QItemDelegate::setModelData(editor, model, index);
}
}
class Base_Button: public QWidget
{
Q_OBJECT
//
public:
QPushButton *pushButton;
Base_Button( QWidget *parent )
: QWidget(parent)
{
setAttribute(Qt::WA_WindowPropagation);
QVBoxLayout *widgetLayout = new QVBoxLayout(this);
widgetLayout->setMargin(0);
widgetLayout->setSpacing(0);
pushButton = new QPushButton(this);
pushButton->setText(tr("Edit Nr. 0"));
widgetLayout->addWidget(pushButton);
}
void SetNummer( int numero ) {
identificativo = numero;
pushButton->setText(tr("Edit Nr. %1").arg(identificativo));
}
int GetNummer() {
return identificativo;
}
private:
int identificativo;
QSize sizebase;
protected:
signals:
public slots:
};
class BaseDelegate : public QSqlRelationalDelegate
{
Q_OBJECT
public:
BaseDelegate( QTableView *ta , QObject *parent );
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
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;
private slots:
private:
QTableView *tas;
QObject *sap;
};
To copy to clipboard, switch view to plain text mode
Bookmarks