23 #include "ui_historydialog.h"
27 #include <QItemDelegate>
28 #include <KDateTimeWidget>
29 #include <KMessageBox>
32 class HistoryWidgetDelegate :
public QItemDelegate
36 HistoryWidgetDelegate(
QObject *parent = 0 ) : QItemDelegate( parent ) {}
38 QWidget *createEditor(
QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &)
const
40 KDateTimeWidget *editor =
new KDateTimeWidget( parent );
41 editor->setAutoFillBackground(
true );
42 editor->setPalette( option.palette );
43 editor->setBackgroundRole( QPalette::Background );
47 void setEditorData(
QWidget *editor,
const QModelIndex &index )
const
49 QDateTime dateTime = QDateTime::fromString( index.model()->data( index, Qt::DisplayRole ).toString(),
"yyyy-MM-dd HH:mm:ss" );
50 KDateTimeWidget *dateTimeWidget =
static_cast<KDateTimeWidget*
>( editor );
51 dateTimeWidget->setDateTime( dateTime );
54 void setModelData(
QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index)
const
56 KDateTimeWidget *dateTimeWidget =
static_cast<KDateTimeWidget*
>( editor );
57 QDateTime dateTime = dateTimeWidget->dateTime();
58 model->setData( index, dateTime.toString(
"yyyy-MM-dd HH:mm:ss" ), Qt::EditRole );
61 void updateEditorGeometry(
QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex &)
const
63 editor->setGeometry( option.rect );
74 HistoryWidgetDelegate *historyWidgetDelegate =
new HistoryWidgetDelegate( m_ui->historytablewidget );
75 m_ui->historytablewidget->setItemDelegateForColumn( 1, historyWidgetDelegate );
76 m_ui->historytablewidget->setItemDelegateForColumn( 2, historyWidgetDelegate );
78 m_ui->historytablewidget->setEditTriggers( QAbstractItemView::AllEditTriggers );
79 m_ui->historytablewidget->setColumnCount(5);
80 m_ui->historytablewidget->setHorizontalHeaderLabels(
81 QStringList() << i18n(
"Task" ) << i18n(
"StartTime" ) << i18n(
"EndTime" )
82 << i18n(
"Comment" ) << QString(
"event UID" ) );
83 m_ui->historytablewidget->horizontalHeader()->setStretchLastSection(
true );
84 m_ui->historytablewidget->setColumnHidden( 4,
true );
86 m_ui->historytablewidget->setSortingEnabled(
true );
87 m_ui->historytablewidget->sortItems( 1, Qt::DescendingOrder );
88 m_ui->historytablewidget->resizeColumnsToContents();
98 QString err=QString();
100 bool old_sortingenabled=m_ui->historytablewidget->isSortingEnabled();
101 m_ui->historytablewidget->setSortingEnabled(
false );
102 connect( m_ui->historytablewidget, SIGNAL(cellChanged(
int,
int)),
103 this, SLOT(historyWidgetCellChanged(
int,
int)) );
107 for ( KCalCore::Event::List::iterator i = eventList.begin();
108 i != eventList.end(); ++i )
110 int row = m_ui->historytablewidget->rowCount();
111 m_ui->historytablewidget->insertRow( row );
112 QTableWidgetItem* item=0;
113 if ( !(*i)->relatedTo().isEmpty() )
115 KCalCore::Incidence::Ptr parent = calendar ? calendar->incidence( (*i)->relatedTo() ) : KCalCore::Incidence::Ptr();
116 item =
new QTableWidgetItem( parent ? parent->summary() : (*i)->summary() );
117 item->setFlags( Qt::ItemIsEnabled );
118 item->setWhatsThis( i18n(
"You can change this task's comment, start time and end time." ) );
119 m_ui->historytablewidget->setItem( row, 0, item );
123 QDateTime start = QDateTime::fromTime_t( (*i)->dtStart().toTime_t() );
124 QDateTime end = QDateTime::fromString( (*i)->dtEnd().toString(), Qt::ISODate );
125 kDebug() <<
"start =" << start <<
"; end =" << end;
126 m_ui->historytablewidget->setItem( row, 1,
new QTableWidgetItem( start.toString(
"yyyy-MM-dd HH:mm:ss" ) ) );
127 m_ui->historytablewidget->setItem( row, 2,
new QTableWidgetItem( end.toString(
"yyyy-MM-dd HH:mm:ss" ) ) );
128 m_ui->historytablewidget->setItem( row, 4,
new QTableWidgetItem( (*i)->uid() ) );
129 kDebug() <<
"(*i)->comments.count() =" << (*i)->comments().count();
130 if ( (*i)->comments().count() > 0 )
132 m_ui->historytablewidget->setItem( row, 3,
new QTableWidgetItem( (*i)->comments().last() ) );
137 kDebug(5970) <<
"There is no 'relatedTo' entry for " << (*i)->summary();
138 err=
"NoRelatedToForEvent";
141 m_ui->historytablewidget->resizeColumnsToContents();
142 m_ui->historytablewidget->setColumnWidth( 1, 300 );
143 m_ui->historytablewidget->setColumnWidth( 2, 300 );
144 setMinimumSize( m_ui->historytablewidget->columnWidth( 0 )
145 + m_ui->historytablewidget->columnWidth( 1 )
146 + m_ui->historytablewidget->columnWidth( 2 )
147 + m_ui->historytablewidget->columnWidth( 3 ), height() );
148 m_ui->historytablewidget->setSortingEnabled(old_sortingenabled);
154 QDialog::changeEvent(e);
157 case QEvent::LanguageChange:
158 m_ui->retranslateUi(
this);
165 void historydialog::historyWidgetCellChanged(
int row,
int col )
167 kDebug( 5970 ) <<
"Entering function";
168 kDebug( 5970 ) <<
"row =" << row <<
" col =" << col;
169 if ( m_ui->historytablewidget->item( row, 4 ) )
173 kDebug( 5970 ) <<
"user changed StartDate to" << m_ui->historytablewidget->item( row, col )->text();
174 QString uid = m_ui->historytablewidget->item( row, 4 )->text();
176 for( KCalCore::Event::List::iterator i = eventList.begin(); i != eventList.end(); ++i )
178 kDebug(5970) <<
"row=" << row <<
" col=" << col;
179 if ( (*i)->uid() == uid )
181 if ( KDateTime::fromString( m_ui->historytablewidget->item( row, col )->text() ).isValid() )
183 QDateTime datetime = QDateTime::fromString( m_ui->historytablewidget->item( row, col )->text(),
"yyyy-MM-dd HH:mm:ss" );
184 KDateTime kdatetime = KDateTime::fromString( datetime.toString( Qt::ISODate ) );
185 (*i)->setDtStart( kdatetime );
187 kDebug(5970) <<
"Program SetDtStart to" << m_ui->historytablewidget->item( row, col )->text();
190 KMessageBox::information( 0, i18n(
"This is not a valid Date/Time." ) );
196 kDebug( 5970 ) <<
"user changed EndDate to" << m_ui->historytablewidget->item(row,col)->text();
197 QString uid = m_ui->historytablewidget->item( row, 4 )->text();
199 for( KCalCore::Event::List::iterator i = eventList.begin(); i != eventList.end(); ++i)
201 kDebug() <<
"row=" << row <<
" col=" << col;
202 if ( (*i)->uid() == uid )
204 if ( KDateTime::fromString( m_ui->historytablewidget->item( row, col )->text() ).isValid() )
206 QDateTime datetime = QDateTime::fromString( m_ui->historytablewidget->item( row, col )->text(),
"yyyy-MM-dd HH:mm:ss" );
207 KDateTime kdatetime = KDateTime::fromString( datetime.toString( Qt::ISODate ) );
208 (*i)->setDtEnd( kdatetime );
210 kDebug(5970) <<
"Program SetDtEnd to" << m_ui->historytablewidget->item( row, col )->text();
213 KMessageBox::information( 0, i18n(
"This is not a valid Date/Time." ) );
219 kDebug( 5970 ) <<
"user changed Comment to" << m_ui->historytablewidget->item(row,col)->text();
220 QString uid = m_ui->historytablewidget->item( row, 4 )->text();
221 kDebug() <<
"uid =" << uid;
223 for ( KCalCore::Event::List::iterator i = eventList.begin(); i != eventList.end(); ++i )
225 kDebug() <<
"row=" << row <<
" col=" << col;
226 if ( (*i)->uid() == uid )
228 (*i)->addComment( m_ui->historytablewidget->item( row, col )->text() );
229 kDebug() <<
"added" << m_ui->historytablewidget->item( row, col )->text();
239 while (m_ui->historytablewidget->rowCount()>0)
240 m_ui->historytablewidget->removeRow(0);
245 #include "historydialog.moc"
247 void historydialog::on_deletepushbutton_clicked()
249 if (m_ui->historytablewidget->item( m_ui->historytablewidget->currentRow(), 4))
251 QString uid = m_ui->historytablewidget->item( m_ui->historytablewidget->currentRow(), 4 )->text();
252 kDebug() <<
"uid =" << uid;
254 for ( KCalCore::Event::List::iterator i = eventList.begin(); i != eventList.end(); ++i )
256 if ( (*i)->uid() == uid )
258 kDebug(5970) <<
"removing uid " << (*i)->uid();
265 else KMessageBox::information(
this, i18n(
"Please select a task to delete."));
268 void historydialog::on_okpushbutton_clicked()
270 m_ui->historytablewidget->setCurrentCell(0,0);
historydialog(TaskView *parent)
QSharedPointer< KTimeTracker::KTTCalendar > Ptr
QString reFreshTimes()
Refresh the times of the tasks, e.g.
void changeEvent(QEvent *e)
timetrackerstorage * storage()
Returns a pointer to storage object.
KCalCore::Event::List rawevents()
list of all events
KTimeTracker::KTTCalendar::Ptr calendar() const
QString removeEvent(QString uid)
Container and interface for the tasks.