summaryrefslogtreecommitdiff
path: root/core/pim/todo/tableview.cpp
authorzecke <zecke>2002-10-07 23:37:48 (UTC)
committer zecke <zecke>2002-10-07 23:37:48 (UTC)
commit626183d58f43f010f5cfb055f8582be0227ff59c (patch) (side-by-side diff)
treead219a64b642fe63480f04cca7c37de4795c5e84 /core/pim/todo/tableview.cpp
parentcdc6cad191b866d481085da1d05806afb5602b2c (diff)
downloadopie-626183d58f43f010f5cfb055f8582be0227ff59c.zip
opie-626183d58f43f010f5cfb055f8582be0227ff59c.tar.gz
opie-626183d58f43f010f5cfb055f8582be0227ff59c.tar.bz2
We're now using a home made painting of cells
This will theoretically speed up things Currently it's noticeable slower on SQL Cause we do up to 80 queries for 10 different items. As you see a cache could be the answer to these problems. The reason for custom drawing is speed and memory consumption. Take the unlikely case of 10.000 items We would have 40.000 QTableItem but would only show 40 of them at a time. The rest seems to be wasted
Diffstat (limited to 'core/pim/todo/tableview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/tableview.cpp233
1 files changed, 112 insertions, 121 deletions
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp
index eaaf1bc..5594b13 100644
--- a/core/pim/todo/tableview.cpp
+++ b/core/pim/todo/tableview.cpp
@@ -38,2 +38,7 @@ using namespace Todo;
+namespace {
+ static const int BoxSize = 14;
+ static const int RowHeight = 20;
+}
+
@@ -102,23 +107,2 @@ void TableView::slotShowMenu() {
}
-OTodo TableView::find(int uid ) {
- OTodo ev = TodoView::event( uid );
- return ev;
-}
-void TableView::updateFromTable( const OTodo& ev, CheckItem* item ) {
- TodoView::update( ev.uid(), ev );
-
- /* update the other columns */
- /* if completed or not we need to update
- * the table
- *
- * We've two cases
- * either item or !item
- * this makes cases more easy
- */
- if ( !item ) {
- item = m_cache[ev.uid()];
- }
- DueTextItem *due = dueItem( item->row() );
- due->setCompleted( ev.isCompleted() );
-}
QString TableView::type() const {
@@ -128,6 +112,3 @@ int TableView::current() {
int cur = 0;
- CheckItem* i = checkItem( currentRow() );
- if (i )
- cur = i->uid();
-
+ // FIXME
return cur;
@@ -150,2 +131,3 @@ void TableView::updateView( ) {
end = sorted().end();
+
qWarning("setTodos");
@@ -156,8 +138,3 @@ void TableView::updateView( ) {
viewport()->setUpdatesEnabled( false );
- clear();
- QString currentCat = todoWindow()->currentCategory();
- bool showCompleted = todoWindow()->showCompleted();
- bool showOverDue = todoWindow()->showOverDue();
- qWarning( "Current Category:" + todoWindow()->currentCategory() );
- int id = todoWindow()->currentCatId();
+
QTime t;
@@ -165,24 +142,2 @@ void TableView::updateView( ) {
setNumRows( it.count() );
- uint i = 0;
- for (; it != end; ++it ) {
- OTodo todo = (*it);
- /* test if the categories match */
- if ( !currentCat.isEmpty() &&
- !todo.categories().contains( id ) ) {
- continue;
- }
- /* the item is completed but we shouldn't show it */
- if ( !showCompleted && todo.isCompleted() ) {
- qWarning("isCompleted ");
- continue;
- }
- /* the item is not overdue but we should only show overdue */
- if ( showOverDue && !todo.isOverdue() ) {
- continue;
- }
- /* now it's fine to add it */
- insertTodo( todo, i );
- i++;
- }
- setNumRows( i );
int elc = time.elapsed();
@@ -192,2 +147,3 @@ void TableView::updateView( ) {
viewport()->update();
+
m_enablePaint = true;
@@ -196,31 +152,12 @@ void TableView::updateView( ) {
}
-void TableView::setTodo( int uid, const OTodo& ev ) {
- QMap<int, CheckItem*>::Iterator it = m_cache.find( uid );
-
- if ( it != m_cache.end() ) {
- int row = it.data()->row();
-
- /* update checked */
- CheckItem* check = checkItem(row );
- if (check)
- check->setChecked( ev.isCompleted() );
-
- /* update the text */
- QString sum = ev.summary();
- setText(row, 2, sum.isEmpty() ?
- ev.description().left(40).simplifyWhiteSpace() :
- sum );
-
- /* update priority */
- setText(row, 1, QString::number( ev.priority() ) );
+void TableView::setTodo( int, const OTodo&) {
+ sort();
- /* update DueDate */
- DueTextItem *due = dueItem( row );
- due->setToDoEvent( ev );
- }
+ /* repaint */
+ QTable::update();
}
-void TableView::addEvent( const OTodo& ev) {
- int row= numRows();
- setNumRows( row + 1 );
- insertTodo( ev, row );
+void TableView::addEvent( const OTodo&) {
+ sort();
+
+ QTable::update();
}
@@ -231,3 +168,3 @@ void TableView::addEvent( const OTodo& ev) {
void TableView::replaceEvent( const OTodo& ev) {
- setTodo( ev.uid(), ev );
+ addEvent( ev );
}
@@ -239,3 +176,2 @@ void TableView::replaceEvent( const OTodo& ev) {
void TableView::removeEvent( int ) {
- clear();
updateView();
@@ -258,27 +194,3 @@ void TableView::setShowCategory( const QString& ) {
void TableView::clear() {
- m_cache.clear();
- int rows = numRows();
- for (int r = 0; r < rows; r++ ) {
- for (int c = 0; c < numCols(); c++ ) {
- if ( cellWidget(r, c) )
- clearCellWidget(r, c );
- clearCell(r, c);
- }
- }
- setNumRows( 0);
-}
-QArray<int> TableView::completed() {
- int row = numRows();
- QArray<int> ids( row );
-
- int j=0;
- for (int i = 0; i < row; i++ ) {
- CheckItem* item = checkItem(i );
- if (item->isChecked() ) {
- ids[j] = item->uid();
- j++;
- }
- }
- ids.resize( j );
- return ids;
+ setNumRows(0);
}
@@ -288,2 +200,3 @@ void TableView::slotClicked(int row, int col, int,
return;
+ int ui=0; // FIXME = uid(row);
@@ -292,3 +205,4 @@ void TableView::slotClicked(int row, int col, int,
case 0: {
- CheckItem* item = checkItem( row );
+ // FIXME
+ CheckItem* item = 0l;
/*
@@ -315,3 +229,3 @@ void TableView::slotClicked(int row, int col, int,
m_menuTimer->stop();
- showTodo( checkItem(row)->uid() );
+ showTodo( ui );
break;
@@ -320,3 +234,3 @@ void TableView::slotClicked(int row, int col, int,
m_menuTimer->stop();
- TodoView::edit( checkItem(row)->uid() );
+ TodoView::edit( ui );
break;
@@ -340,13 +254,2 @@ void TableView::slotCurrentChanged(int, int ) {
}
-/*
- * hardcode to column 0
- */
-CheckItem* TableView::checkItem( int row ) {
- CheckItem *i = static_cast<CheckItem*>( item( row, 0 ) );
- return i;
-}
-DueTextItem* TableView::dueItem( int row ) {
- DueTextItem* i = static_cast<DueTextItem*> ( item(row, 3 ) );
- return i;
-}
QWidget* TableView::widget() {
@@ -358,2 +261,4 @@ QWidget* TableView::widget() {
* based
+ * We event want to set the setOrder
+ * to a sort() and update()
*/
@@ -368 +273,87 @@ void TableView::viewportPaintEvent( QPaintEvent* e) {
}
+/*
+ * This segment is copyrighted by TT
+ * it was taken from their todolist
+ * application this code is GPL
+ */
+void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) {
+ const QColorGroup &cg = colorGroup();
+
+ p->save();
+
+ OTodo task = sorted()[row];
+
+ p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
+
+ QPen op = p->pen();
+ p->setPen(cg.mid());
+ p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 );
+ p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 );
+ p->setPen(op);
+
+ QFont f = p->font();
+ QFontMetrics fm(f);
+
+ switch(col) {
+ case 0:
+ {
+ // completed field
+ int marg = ( cr.width() - BoxSize ) / 2;
+ int x = 0;
+ int y = ( cr.height() - BoxSize ) / 2;
+ p->setPen( QPen( cg.text() ) );
+ p->drawRect( x + marg, y, BoxSize, BoxSize );
+ p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
+ p->setPen( darkGreen );
+ x += 1;
+ y += 1;
+ if ( task.isCompleted() ) {
+ QPointArray a( 9*2 );
+ int i, xx, yy;
+ xx = x+2+marg;
+ yy = y+4;
+ for ( i=0; i<4; i++ ) {
+ a.setPoint( 2*i, xx, yy );
+ a.setPoint( 2*i+1, xx, yy+2 );
+ xx++; yy++;
+ }
+ yy -= 2;
+ for ( i=4; i<9; i++ ) {
+ a.setPoint( 2*i, xx, yy );
+ a.setPoint( 2*i+1, xx, yy+2 );
+ xx++; yy--;
+ }
+ p->drawLineSegments( a );
+ }
+ }
+ break;
+ case 1:
+ // priority field
+ {
+ QString text = QString::number(task.priority());
+ p->drawText(2,2 + fm.ascent(), text);
+ }
+ break;
+ case 2:
+ // description field
+ {
+ QString text = task.summary().isEmpty() ?
+ task.description() :
+ task.summary();
+ p->drawText(2,2 + fm.ascent(), text);
+ }
+ break;
+ case 3:
+ {
+ QString text;
+ if (task.hasDueDate()) {
+ text = "HAS";
+ } else {
+ text = tr("None");
+ }
+ p->drawText(2,2 + fm.ascent(), text);
+ }
+ break;
+ }
+ p->restore();
+}