COPASI API  4.16.103
CQDateTimeEditDelegate.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 #include <QtGui/QDateTimeEdit>
12 #include <QtCore/QAbstractItemModel>
13 
14 #include "../copasi.h"
15 #include "CQDateTimeEditDelegate.h"
16 
18  : QItemDelegate(parent)
19 {}
20 
21 QWidget *CQDateTimeEditDelegate::createEditor(QWidget *parent,
22  const QStyleOptionViewItem & C_UNUSED(option),
23  const QModelIndex & C_UNUSED(index)) const
24 {
25  QDateTimeEdit *editor = new QDateTimeEdit(QDateTime::currentDateTime(), parent);
26  return editor;
27 }
28 
30  const QModelIndex &index) const
31 {
32  QString dtStr = index.model()->data(index, Qt::EditRole).toString();
33  QDateTimeEdit *dtEdit = static_cast<QDateTimeEdit*>(editor);
34 
35  dtEdit->setDateTime(QDateTime::fromString(dtStr, Qt::ISODate));
36 }
37 
38 void CQDateTimeEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
39  const QModelIndex &index) const
40 {
41  QDateTimeEdit *dtEdit = static_cast<QDateTimeEdit*>(editor);
42  QVariant value(dtEdit->dateTime().toString(Qt::ISODate));
43  model->setData(index, value, Qt::EditRole);
44 }
45 
47  const QStyleOptionViewItem &option, const QModelIndex & C_UNUSED(index)) const
48 {
49  editor->setGeometry(option.rect);
50 }
CQDateTimeEditDelegate(QObject *parent=0)
#define C_UNUSED(p)
Definition: copasi.h:220
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
void setEditorData(QWidget *editor, const QModelIndex &index) const
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const