author | mickeyl <mickeyl> | 2003-05-01 23:06:29 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-05-01 23:06:29 (UTC) |
commit | 49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6 (patch) (unidiff) | |
tree | 503a7fe9fba8e297b15c07398fbf2ee215294f1c /libopie2/opieui/olistview.cpp | |
parent | 8266da96576ad43a768da37000cef4e8eba000ac (diff) | |
download | opie-49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6.zip opie-49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6.tar.gz opie-49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6.tar.bz2 |
more work on a higher level listview interface
Diffstat (limited to 'libopie2/opieui/olistview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opieui/olistview.cpp | 93 |
1 files changed, 84 insertions, 9 deletions
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp index 8f97cc6..8f290d3 100644 --- a/libopie2/opieui/olistview.cpp +++ b/libopie2/opieui/olistview.cpp | |||
@@ -466,6 +466,68 @@ void ONamedListView::addColumns( const QStringList& columns ) | |||
466 | } | 466 | } |
467 | 467 | ||
468 | 468 | ||
469 | int ONamedListView::findColumn( const QString& text ) const | ||
470 | { | ||
471 | //FIXME: If used excessively, this will slow down performance of updates | ||
472 | //FIXME: because of the linear search over all column texts. | ||
473 | //FIXME: I will optimize later by using a hash map. | ||
474 | for ( int i = 0; i < columns(); ++i ) | ||
475 | if ( columnText( i ) == text ) | ||
476 | return i; | ||
477 | return -1; | ||
478 | } | ||
479 | |||
480 | |||
481 | ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const | ||
482 | { | ||
483 | return find( (ONamedListViewItem*) firstChild(), column, text, recurse ); | ||
484 | } | ||
485 | |||
486 | |||
487 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const | ||
488 | { | ||
489 | ONamedListViewItem* result; | ||
490 | while ( item && item->text( column ) != text ) | ||
491 | { | ||
492 | qDebug( "checked %s", (const char*) item->text( column ) ); | ||
493 | |||
494 | if ( recurse < 0 || recurse > 0 ) | ||
495 | { | ||
496 | qDebug( "recursion is %d - recursing into...", recurse ); | ||
497 | result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 ); | ||
498 | if ( result ) return result; | ||
499 | } | ||
500 | |||
501 | |||
502 | item = (ONamedListViewItem*) item->itemBelow(); | ||
503 | } | ||
504 | if ( item && item->text( column ) == text ) | ||
505 | return item; | ||
506 | else | ||
507 | return 0; | ||
508 | } | ||
509 | |||
510 | |||
511 | ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const | ||
512 | { | ||
513 | int col = findColumn( column ); | ||
514 | if ( col != -1 ) | ||
515 | return find( (ONamedListViewItem*) firstChild(), col, text, recurse ); | ||
516 | else | ||
517 | return 0; | ||
518 | } | ||
519 | |||
520 | |||
521 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const | ||
522 | { | ||
523 | int col = findColumn( column ); | ||
524 | if ( col != -1 ) | ||
525 | return find( item, col, text, recurse ); | ||
526 | else | ||
527 | return 0; | ||
528 | } | ||
529 | |||
530 | |||
469 | /*====================================================================================== | 531 | /*====================================================================================== |
470 | * ONamedListViewItem | 532 | * ONamedListViewItem |
471 | *======================================================================================*/ | 533 | *======================================================================================*/ |
@@ -520,13 +582,26 @@ void ONamedListViewItem::setText( const QString& column, const QString& text ) | |||
520 | //FIXME: If used excessively, this will slow down performance of updates | 582 | //FIXME: If used excessively, this will slow down performance of updates |
521 | //FIXME: because of the linear search over all column texts. | 583 | //FIXME: because of the linear search over all column texts. |
522 | //FIXME: I will optimize later by using a hash map. | 584 | //FIXME: I will optimize later by using a hash map. |
523 | for ( int i = 0; i < listView()->columns(); ++i ) | 585 | int col = ( (ONamedListView*) listView() )->findColumn( column ); |
524 | { | 586 | if ( col != -1 ) |
525 | if ( listView()->columnText( i ) == column ) | 587 | OListViewItem::setText( col, text ); |
526 | { | 588 | else |
527 | OListViewItem::setText( i, text ); | 589 | qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); |
528 | return; | 590 | } |
529 | } | 591 | |
530 | } | 592 | |
531 | qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); | 593 | ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const |
594 | { | ||
595 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse ); | ||
532 | } | 596 | } |
597 | |||
598 | |||
599 | ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const | ||
600 | { | ||
601 | int col = ( (ONamedListView*) listView() )->findColumn( column ); | ||
602 | if ( col != -1 ) | ||
603 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse ); | ||
604 | else | ||
605 | return 0; | ||
606 | } | ||
607 | |||