2 ******************************************************************************
4 * @file notifyitemdelegate.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
7 * @see The GNU Public License (GPL) Version 3
8 * @defgroup notifyplugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <QtWidgets/QWidget>
33 #include <QTableWidget>
34 #include "notifyitemdelegate.h"
35 #include "notifytablemodel.h"
36 #include "notifylogging.h"
37 #include "notificationitem.h"
39 NotifyItemDelegate::NotifyItemDelegate(QObject
*parent
)
40 : QItemDelegate(parent
)
44 QWidget
*NotifyItemDelegate::createEditor(QWidget
*parent
, const QStyleOptionViewItem
& /*none*/,
45 const QModelIndex
& index
) const
47 if (eRepeatValue
== index
.column()) {
48 QComboBox
*editor
= new QComboBox(parent
);
50 editor
->addItems(NotificationItem::retryValues
);
53 if (eExpireTimer
== index
.column()) {
54 QSpinBox
*editor
= new QSpinBox(parent
);
55 connect(editor
, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
58 if (eTurnOn
== index
.column()) {
59 QCheckBox
*editor
= new QCheckBox(parent
);
60 connect(editor
, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
65 QLineEdit
*editor
= new QLineEdit(parent
);
69 void NotifyItemDelegate::commitAndCloseEditor()
71 QLineEdit
*editor
= qobject_cast
<QLineEdit
*>(sender());
74 emit
commitData(editor
);
75 emit
closeEditor(editor
);
77 QComboBox
*editor
= qobject_cast
<QComboBox
*>(sender());
79 emit
commitData(editor
);
80 emit
closeEditor(editor
);
82 QSpinBox
*editor
= qobject_cast
<QSpinBox
*>(sender());
84 emit
commitData(editor
);
85 emit
closeEditor(editor
);
87 QCheckBox
*editor
= qobject_cast
<QCheckBox
*>(sender());
89 emit
commitData(editor
);
90 emit
closeEditor(editor
);
97 void NotifyItemDelegate::setEditorData(QWidget
*editor
, const QModelIndex
&index
) const
99 QLineEdit
*edit
= qobject_cast
<QLineEdit
*>(editor
);
102 edit
->setText(index
.model()->data(index
, Qt::EditRole
).toString());
104 QComboBox
*repeatEditor
= qobject_cast
<QComboBox
*>(editor
);
106 repeatEditor
->setCurrentIndex(repeatEditor
->findText(index
.model()->data(index
, Qt::EditRole
).toString()));
108 QSpinBox
*expireEditor
= qobject_cast
<QSpinBox
*>(editor
);
110 expireEditor
->setValue(index
.model()->data(index
, Qt::EditRole
).toInt());
112 QCheckBox
*enablePlayEditor
= qobject_cast
<QCheckBox
*>(editor
);
113 if (enablePlayEditor
) {
114 enablePlayEditor
->setChecked(index
.model()->data(index
, Qt::EditRole
).toBool());
121 void NotifyItemDelegate::setModelData(QWidget
*editor
, QAbstractItemModel
*model
, const QModelIndex
&index
) const
123 QLineEdit
*edit
= qobject_cast
<QLineEdit
*>(editor
);
126 model
->setData(index
, edit
->text());
128 QComboBox
*repeatEditor
= qobject_cast
<QComboBox
*>(editor
);
130 model
->setData(index
, repeatEditor
->currentText());
132 QSpinBox
*expireEditor
= qobject_cast
<QSpinBox
*>(editor
);
134 model
->setData(index
, expireEditor
->value(), Qt::EditRole
);
136 QCheckBox
*enablePlayEditor
= qobject_cast
<QCheckBox
*>(editor
);
137 if (enablePlayEditor
) {
138 model
->setData(index
, enablePlayEditor
->isChecked(), Qt::EditRole
);
145 void NotifyItemDelegate::selectRow(const QString
& text
)
148 QComboBox
*combo
= qobject_cast
<QComboBox
*>(sender());
149 QTableWidget
*table
= new QTableWidget
;
151 table
= (QTableWidget
*)(combo
->parent());
153 qNotifyDebug() << table
->columnCount();
154 qNotifyDebug() << table
->rowCount();
155 qNotifyDebug() << table
->currentRow();
158 QSize
NotifyItemDelegate::sizeHint(const QStyleOptionViewItem
& option
, const QModelIndex
& index
) const
160 QSize s
= QItemDelegate::sizeHint(option
, index
);