summaryrefslogtreecommitdiff
path: root/libopie2/opieui
Unidiff
Diffstat (limited to 'libopie2/opieui') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opieui/olistview.cpp89
-rw-r--r--libopie2/opieui/olistview.h35
2 files changed, 115 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
@@ -468,2 +468,64 @@ void ONamedListView::addColumns( const QStringList& columns )
468 468
469int 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
481ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const
482{
483 return find( (ONamedListViewItem*) firstChild(), column, text, recurse );
484}
485
486
487ONamedListViewItem* 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
511ONamedListViewItem* 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
521ONamedListViewItem* 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/*======================================================================================
@@ -522,11 +584,24 @@ void ONamedListViewItem::setText( const QString& column, const QString& text )
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;
529 } 590 }
591
592
593ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const
594{
595 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse );
530 } 596 }
531 qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); 597
598
599ONamedListViewItem* 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;
532} 606}
607
diff --git a/libopie2/opieui/olistview.h b/libopie2/opieui/olistview.h
index 99770bf..1bbdd5b 100644
--- a/libopie2/opieui/olistview.h
+++ b/libopie2/opieui/olistview.h
@@ -243,2 +243,4 @@ QDataStream& operator>>( QDataStream& stream, OListViewItem& item );
243 243
244class ONamedListViewItem;
245
244/** 246/**
@@ -246,3 +248,3 @@ QDataStream& operator>>( QDataStream& stream, OListViewItem& item );
246 * 248 *
247 * This class provides a higher-level interface to the columns in an OListView. 249 * This class provides a higher-level interface to an OListView.
248 * 250 *
@@ -268,2 +270,20 @@ class ONamedListView: public OListView
268 virtual void addColumns( const QStringList& columns ); 270 virtual void addColumns( const QStringList& columns );
271 /**
272 * @returns the column index matching to @a text or -1 if not found.
273 */
274 virtual int findColumn( const QString& text ) const;
275 /**
276 * @returns the first item which has a @a text in column @a column.
277 * Set @a recurse to indicate how much subchild levels to search, e.g.<ul>
278 * <li>set it to 0 to search only among direct childs,
279 * <li>set it to 1 to search direct childs and all 1st order subchilds
280 * <li>set it to -1 for maximum recursion.
281 * </ul>
282 * @sa ONamedListViewItem::find()
283 */
284 virtual ONamedListViewItem* find( ONamedListViewItem* start, int column, const QString& text, int recurse = -1 ) const;
285 virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const;
286
287 virtual ONamedListViewItem* find( ONamedListViewItem* start, const QString& column, const QString& text, int recurse = -1 ) const;
288 virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const;
269}; 289};
@@ -277,3 +297,3 @@ class ONamedListView: public OListView
277 * 297 *
278 * This class provides a higher-level interface to the columns in an OListViewItem. 298 * This class provides a higher-level interface to an OListViewItem.
279 * 299 *
@@ -306,2 +326,13 @@ class ONamedListViewItem: public OListViewItem
306 virtual void setText( const QStringList& texts ); 326 virtual void setText( const QStringList& texts );
327 /**
328 * @returns the first child which has a @a text in column @a column.
329 * Set @a recurse to indicate how much subchild levels to search, e.g.<ul>
330 * <li>set it to 0 to search only among direct childs,
331 * <li>set it to 1 to search direct childs and all 1st order subchilds
332 * <li>set it to -1 for maximum recursion.
333 * </ul>
334 * @sa ONamedListView::find()
335 */
336 virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const;
337 virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const;
307}; 338};