author | zecke <zecke> | 2002-10-19 00:10:15 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-19 00:10:15 (UTC) |
commit | e869be9990c0db11288bd196778cadd0ad6976a9 (patch) (unidiff) | |
tree | ee3474f8e5498466896e830bbeee68d618f7aff2 /core/pim/todo/tableview.cpp | |
parent | 549472ef07703ef27dc5f58a37e8f16c714fb2a1 (diff) | |
download | opie-e869be9990c0db11288bd196778cadd0ad6976a9.zip opie-e869be9990c0db11288bd196778cadd0ad6976a9.tar.gz opie-e869be9990c0db11288bd196778cadd0ad6976a9.tar.bz2 |
MainWindow setReadAhead added
Tableview we now try to read ahead in timerEvent..
the TodoView interface needs an update on this matter too...
besides that I'm quite happy with the speed and go on to implement new
features
-rw-r--r-- | core/pim/todo/tableview.cpp | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp index 5d82eb2..f4b898f 100644 --- a/core/pim/todo/tableview.cpp +++ b/core/pim/todo/tableview.cpp | |||
@@ -81,131 +81,139 @@ TableView::TableView( MainWindow* window, QWidget* wid ) | |||
81 | connect((QTable*)this, SIGNAL(currentChanged(int, int) ), | 81 | connect((QTable*)this, SIGNAL(currentChanged(int, int) ), |
82 | this, SLOT( slotCurrentChanged(int, int) ) ); | 82 | this, SLOT( slotCurrentChanged(int, int) ) ); |
83 | 83 | ||
84 | m_menuTimer = new QTimer( this ); | 84 | m_menuTimer = new QTimer( this ); |
85 | connect( m_menuTimer, SIGNAL(timeout()), | 85 | connect( m_menuTimer, SIGNAL(timeout()), |
86 | this, SLOT(slotShowMenu()) ); | 86 | this, SLOT(slotShowMenu()) ); |
87 | 87 | ||
88 | m_enablePaint = true; | 88 | m_enablePaint = true; |
89 | setUpdatesEnabled( true ); | 89 | setUpdatesEnabled( true ); |
90 | viewport()->setUpdatesEnabled( true ); | 90 | viewport()->setUpdatesEnabled( true ); |
91 | viewport()->update(); | 91 | viewport()->update(); |
92 | setSortOrder( 0 ); | 92 | setSortOrder( 0 ); |
93 | setAscending( TRUE ); | 93 | setAscending( TRUE ); |
94 | m_first = true; | 94 | m_first = true; |
95 | } | 95 | } |
96 | /* a new day has started | 96 | /* a new day has started |
97 | * update the day | 97 | * update the day |
98 | */ | 98 | */ |
99 | void TableView::newDay() { | 99 | void TableView::newDay() { |
100 | clear(); | 100 | clear(); |
101 | updateView(); | 101 | updateView(); |
102 | } | 102 | } |
103 | TableView::~TableView() { | 103 | TableView::~TableView() { |
104 | 104 | ||
105 | } | 105 | } |
106 | void TableView::slotShowMenu() { | 106 | void TableView::slotShowMenu() { |
107 | QPopupMenu *menu = todoWindow()->contextMenu( current() ); | 107 | QPopupMenu *menu = todoWindow()->contextMenu( current() ); |
108 | menu->exec(QCursor::pos() ); | 108 | menu->exec(QCursor::pos() ); |
109 | delete menu; | 109 | delete menu; |
110 | } | 110 | } |
111 | QString TableView::type() const { | 111 | QString TableView::type() const { |
112 | return QString::fromLatin1( tr("Table View") ); | 112 | return QString::fromLatin1( tr("Table View") ); |
113 | } | 113 | } |
114 | int TableView::current() { | 114 | int TableView::current() { |
115 | int uid = sorted().uidAt(currentRow() ); | 115 | int uid = sorted().uidAt(currentRow() ); |
116 | qWarning("uid %d", uid ); | 116 | qWarning("uid %d", uid ); |
117 | return uid; | 117 | return uid; |
118 | } | 118 | } |
119 | QString TableView::currentRepresentation() { | 119 | QString TableView::currentRepresentation() { |
120 | return text( currentRow(), 2); | 120 | return text( currentRow(), 2); |
121 | } | 121 | } |
122 | /* show overdue */ | 122 | /* show overdue */ |
123 | void TableView::showOverDue( bool ) { | 123 | void TableView::showOverDue( bool ) { |
124 | clear(); | 124 | clear(); |
125 | updateView(); | 125 | updateView(); |
126 | } | 126 | } |
127 | 127 | ||
128 | void TableView::updateView( ) { | 128 | void TableView::updateView( ) { |
129 | m_row = false; | ||
130 | startTimer( 2000 ); | ||
131 | /* FIXME we want one page to be read! | ||
132 | * | ||
133 | * Calculate that screensize | ||
134 | */ | ||
135 | todoWindow()->setReadAhead( 4 ); | ||
129 | sort(); | 136 | sort(); |
130 | OTodoAccess::List::Iterator it, end; | 137 | OTodoAccess::List::Iterator it, end; |
131 | it = sorted().begin(); | 138 | it = sorted().begin(); |
132 | end = sorted().end(); | 139 | end = sorted().end(); |
133 | 140 | ||
134 | qWarning("setTodos"); | 141 | qWarning("setTodos"); |
135 | QTime time; | 142 | QTime time; |
136 | time.start(); | 143 | time.start(); |
137 | m_enablePaint = false; | 144 | m_enablePaint = false; |
138 | setUpdatesEnabled( false ); | 145 | setUpdatesEnabled( false ); |
139 | viewport()->setUpdatesEnabled( false ); | 146 | viewport()->setUpdatesEnabled( false ); |
140 | 147 | ||
141 | QTime t; | 148 | QTime t; |
142 | t.start(); | 149 | t.start(); |
143 | setNumRows( it.count() ); | 150 | setNumRows( it.count() ); |
144 | int elc = time.elapsed(); | 151 | int elc = time.elapsed(); |
145 | qWarning("Adding took %d", elc/1000 ); | 152 | qWarning("Adding took %d", elc/1000 ); |
146 | setUpdatesEnabled( true ); | 153 | setUpdatesEnabled( true ); |
147 | viewport()->setUpdatesEnabled( true ); | 154 | viewport()->setUpdatesEnabled( true ); |
148 | viewport()->update(); | 155 | viewport()->update(); |
149 | 156 | ||
150 | m_enablePaint = true; | 157 | m_enablePaint = true; |
151 | int el = time.elapsed(); | 158 | int el = time.elapsed(); |
152 | qWarning("adding took %d", el/1000 ); | 159 | qWarning("adding took %d", el/1000 ); |
153 | } | 160 | } |
154 | void TableView::setTodo( int, const OTodo&) { | 161 | void TableView::setTodo( int, const OTodo&) { |
155 | sort(); | 162 | sort(); |
156 | 163 | ||
157 | /* repaint */ | 164 | /* repaint */ |
158 | QTable::update(); | 165 | QTable::update(); |
159 | } | 166 | } |
160 | void TableView::addEvent( const OTodo&) { | 167 | void TableView::addEvent( const OTodo&) { |
161 | sort(); | 168 | sort(); |
162 | 169 | ||
163 | QTable::update(); | 170 | /* fix problems of not showing the 'Haken' */ |
171 | QTable::repaint(); | ||
164 | } | 172 | } |
165 | /* | 173 | /* |
166 | * find the event | 174 | * find the event |
167 | * and then replace the complete row | 175 | * and then replace the complete row |
168 | */ | 176 | */ |
169 | void TableView::replaceEvent( const OTodo& ev) { | 177 | void TableView::replaceEvent( const OTodo& ev) { |
170 | addEvent( ev ); | 178 | addEvent( ev ); |
171 | } | 179 | } |
172 | /* | 180 | /* |
173 | * re aligning table can be slow too | 181 | * re aligning table can be slow too |
174 | * FIXME: look what performs better | 182 | * FIXME: look what performs better |
175 | * either this or the old align table | 183 | * either this or the old align table |
176 | */ | 184 | */ |
177 | void TableView::removeEvent( int ) { | 185 | void TableView::removeEvent( int ) { |
178 | updateView(); | 186 | updateView(); |
179 | } | 187 | } |
180 | void TableView::setShowCompleted( bool b) { | 188 | void TableView::setShowCompleted( bool b) { |
181 | qWarning("Show Completed %d" + b ); | 189 | qWarning("Show Completed %d" + b ); |
182 | updateView(); | 190 | updateView(); |
183 | } | 191 | } |
184 | void TableView::setShowDeadline( bool b) { | 192 | void TableView::setShowDeadline( bool b) { |
185 | qWarning("Show DeadLine %d" + b ); | 193 | qWarning("Show DeadLine %d" + b ); |
186 | if (b) | 194 | if (b) |
187 | showColumn(3 ); | 195 | showColumn(3 ); |
188 | else | 196 | else |
189 | hideColumn(3 ); | 197 | hideColumn(3 ); |
190 | } | 198 | } |
191 | void TableView::setShowCategory( const QString& str) { | 199 | void TableView::setShowCategory( const QString& str) { |
192 | qWarning("setShowCategory"); | 200 | qWarning("setShowCategory"); |
193 | if ( str != m_oleCat || m_first ) | 201 | if ( str != m_oleCat || m_first ) |
194 | updateView(); | 202 | updateView(); |
195 | 203 | ||
196 | m_oleCat = str; | 204 | m_oleCat = str; |
197 | m_first = false; | 205 | m_first = false; |
198 | 206 | ||
199 | } | 207 | } |
200 | void TableView::clear() { | 208 | void TableView::clear() { |
201 | setNumRows(0); | 209 | setNumRows(0); |
202 | } | 210 | } |
203 | void TableView::slotClicked(int row, int col, int, | 211 | void TableView::slotClicked(int row, int col, int, |
204 | const QPoint& point) { | 212 | const QPoint& point) { |
205 | if ( !cellGeometry(row, col ).contains(point ) ) | 213 | if ( !cellGeometry(row, col ).contains(point ) ) |
206 | return; | 214 | return; |
207 | 215 | ||
208 | int ui= sorted().uidAt( row ); | 216 | int ui= sorted().uidAt( row ); |
209 | 217 | ||
210 | 218 | ||
211 | switch( col ) { | 219 | switch( col ) { |
@@ -308,93 +316,135 @@ void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool | |||
308 | int x = 0; | 316 | int x = 0; |
309 | int y = ( cr.height() - BoxSize ) / 2; | 317 | int y = ( cr.height() - BoxSize ) / 2; |
310 | p->setPen( QPen( cg.text() ) ); | 318 | p->setPen( QPen( cg.text() ) ); |
311 | p->drawRect( x + marg, y, BoxSize, BoxSize ); | 319 | p->drawRect( x + marg, y, BoxSize, BoxSize ); |
312 | p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); | 320 | p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); |
313 | p->setPen( darkGreen ); | 321 | p->setPen( darkGreen ); |
314 | x += 1; | 322 | x += 1; |
315 | y += 1; | 323 | y += 1; |
316 | if ( task.isCompleted() ) { | 324 | if ( task.isCompleted() ) { |
317 | QPointArray a( 9*2 ); | 325 | QPointArray a( 9*2 ); |
318 | int i, xx, yy; | 326 | int i, xx, yy; |
319 | xx = x+2+marg; | 327 | xx = x+2+marg; |
320 | yy = y+4; | 328 | yy = y+4; |
321 | for ( i=0; i<4; i++ ) { | 329 | for ( i=0; i<4; i++ ) { |
322 | a.setPoint( 2*i, xx, yy ); | 330 | a.setPoint( 2*i, xx, yy ); |
323 | a.setPoint( 2*i+1, xx, yy+2 ); | 331 | a.setPoint( 2*i+1, xx, yy+2 ); |
324 | xx++; yy++; | 332 | xx++; yy++; |
325 | } | 333 | } |
326 | yy -= 2; | 334 | yy -= 2; |
327 | for ( i=4; i<9; i++ ) { | 335 | for ( i=4; i<9; i++ ) { |
328 | a.setPoint( 2*i, xx, yy ); | 336 | a.setPoint( 2*i, xx, yy ); |
329 | a.setPoint( 2*i+1, xx, yy+2 ); | 337 | a.setPoint( 2*i+1, xx, yy+2 ); |
330 | xx++; yy--; | 338 | xx++; yy--; |
331 | } | 339 | } |
332 | p->drawLineSegments( a ); | 340 | p->drawLineSegments( a ); |
333 | } | 341 | } |
334 | } | 342 | } |
335 | break; | 343 | break; |
336 | case 1: | 344 | case 1: |
337 | // priority field | 345 | // priority field |
338 | { | 346 | { |
339 | QString text = QString::number(task.priority()); | 347 | QString text = QString::number(task.priority()); |
340 | p->drawText(2,2 + fm.ascent(), text); | 348 | p->drawText(2,2 + fm.ascent(), text); |
341 | } | 349 | } |
342 | break; | 350 | break; |
343 | case 2: | 351 | case 2: |
344 | // description field | 352 | // description field |
345 | { | 353 | { |
346 | QString text = task.summary().isEmpty() ? | 354 | QString text = task.summary().isEmpty() ? |
347 | task.description() : | 355 | task.description() : |
348 | task.summary(); | 356 | task.summary(); |
349 | p->drawText(2,2 + fm.ascent(), text); | 357 | p->drawText(2,2 + fm.ascent(), text); |
350 | } | 358 | } |
351 | break; | 359 | break; |
352 | case 3: | 360 | case 3: |
353 | { | 361 | { |
354 | QString text; | 362 | QString text; |
355 | if (task.hasDueDate()) { | 363 | if (task.hasDueDate()) { |
356 | text = "HAS"; | 364 | int off = QDate::currentDate().daysTo( task.dueDate() ); |
365 | text = QString::number(off) + tr(" day(s)"); | ||
366 | /* | ||
367 | * set color if not completed | ||
368 | */ | ||
369 | if (!task.isCompleted() ) { | ||
370 | QColor color = Qt::black; | ||
371 | if ( off < 0 ) | ||
372 | color = Qt::red; | ||
373 | else if ( off == 0 ) | ||
374 | color = Qt::yellow; | ||
375 | else if ( off > 0 ) | ||
376 | color = Qt::green; | ||
377 | p->setPen(color ); | ||
378 | } | ||
357 | } else { | 379 | } else { |
358 | text = tr("None"); | 380 | text = tr("None"); |
359 | } | 381 | } |
360 | p->drawText(2,2 + fm.ascent(), text); | 382 | p->drawText(2,2 + fm.ascent(), text); |
361 | } | 383 | } |
362 | break; | 384 | break; |
363 | } | 385 | } |
364 | p->restore(); | 386 | p->restore(); |
365 | } | 387 | } |
366 | QWidget* TableView::createEditor(int row, int col, bool )const { | 388 | QWidget* TableView::createEditor(int row, int col, bool )const { |
367 | switch( col ) { | 389 | switch( col ) { |
368 | case 1: { | 390 | case 1: { |
369 | /* the priority stuff */ | 391 | /* the priority stuff */ |
370 | QComboBox* combo = new QComboBox( viewport() ); | 392 | QComboBox* combo = new QComboBox( viewport() ); |
371 | combo->insertItem( "1" ); | 393 | combo->insertItem( "1" ); |
372 | combo->insertItem( "2" ); | 394 | combo->insertItem( "2" ); |
373 | combo->insertItem( "3" ); | 395 | combo->insertItem( "3" ); |
374 | combo->insertItem( "4" ); | 396 | combo->insertItem( "4" ); |
375 | combo->insertItem( "5" ); | 397 | combo->insertItem( "5" ); |
376 | combo->setCurrentItem( sorted()[row].priority()-1 ); | 398 | combo->setCurrentItem( sorted()[row].priority()-1 ); |
377 | return combo; | 399 | return combo; |
378 | } | 400 | } |
379 | case 0: | 401 | case 0: |
380 | default: | 402 | default: |
381 | return 0l; | 403 | return 0l; |
382 | } | 404 | } |
383 | } | 405 | } |
384 | void TableView::setCellContentFromEditor(int row, int col ) { | 406 | void TableView::setCellContentFromEditor(int row, int col ) { |
385 | if ( col == 1 ) { | 407 | if ( col == 1 ) { |
386 | QWidget* wid = cellWidget(row, 1 ); | 408 | QWidget* wid = cellWidget(row, 1 ); |
387 | if ( wid->inherits("QComboBox") ) { | 409 | if ( wid->inherits("QComboBox") ) { |
388 | int pri = ((QComboBox*)wid)->currentItem() + 1; | 410 | int pri = ((QComboBox*)wid)->currentItem() + 1; |
389 | OTodo todo = sorted()[row]; | 411 | OTodo todo = sorted()[row]; |
390 | if ( todo.priority() != pri ) { | 412 | if ( todo.priority() != pri ) { |
391 | todo.setPriority( pri ); | 413 | todo.setPriority( pri ); |
392 | TodoView::update( todo.uid(), todo ); | 414 | TodoView::update( todo.uid(), todo ); |
393 | updateView(); | 415 | updateView(); |
394 | } | 416 | } |
395 | } | 417 | } |
396 | } | 418 | } |
397 | } | 419 | } |
398 | void TableView::slotPriority() { | 420 | void TableView::slotPriority() { |
399 | setCellContentFromEditor( currentRow(), currentColumn() ); | 421 | setCellContentFromEditor( currentRow(), currentColumn() ); |
400 | } | 422 | } |
423 | /* | ||
424 | * We'll use the TimerEvent to read ahead or to keep the cahce always | ||
425 | * filled enough. | ||
426 | * We will try to read ahead 4 items in both ways | ||
427 | * up and down. On odd or even we will currentRow()+-4 or +-9 | ||
428 | * | ||
429 | */ | ||
430 | void TableView::timerEvent( QTimerEvent* ev ) { | ||
431 | int row = currentRow(); | ||
432 | qWarning("TimerEvent %d", row); | ||
433 | if ( m_row ) { | ||
434 | int ro = row-4; | ||
435 | if (ro < 0 ) ro = 0; | ||
436 | sorted()[ro]; | ||
437 | |||
438 | ro = row+4; | ||
439 | sorted()[ro]; | ||
440 | } else { | ||
441 | int ro = row + 8; | ||
442 | sorted()[ro]; | ||
443 | |||
444 | ro = row-8; | ||
445 | if (ro < 0 ) ro = 0; | ||
446 | sorted()[ro]; | ||
447 | } | ||
448 | |||
449 | m_row = !m_row; | ||
450 | } | ||