| 381 | } |
| 382 | |
| 383 | ModelIndex UITableView::findRowWithText( const std::string& text, const bool& caseSensitive, |
| 384 | FindRowWithTextMatchKind matchKind ) const { |
| 385 | const Model* model = getModel(); |
| 386 | ConditionalLock l( getModel() != nullptr, |
| 387 | getModel() ? &const_cast<Model*>( getModel() )->resourceMutex() : nullptr ); |
| 388 | if ( !model || !model->hasChildren() ) |
| 389 | return {}; |
| 390 | size_t rc = model->rowCount(); |
| 391 | for ( size_t i = 0; i < rc; i++ ) { |
| 392 | ModelIndex index = model->index( |
| 393 | i, model->keyColumn() != -1 ? model->keyColumn() |
| 394 | : ( model->treeColumn() >= 0 ? model->treeColumn() : 0 ) ); |
| 395 | Variant var = model->data( index ); |
| 396 | if ( var.isValid() ) { |
| 397 | bool matches = false; |
| 398 | switch ( matchKind ) { |
| 399 | case Abstract::UIAbstractView::FindRowWithTextMatchKind::Equals: |
| 400 | matches = var.toString() == text; |
| 401 | break; |
| 402 | case Abstract::UIAbstractView::FindRowWithTextMatchKind::StartsWith: |
| 403 | matches = String::startsWith( caseSensitive ? var.toString() |
| 404 | : String::toLower( var.toString() ), |
| 405 | caseSensitive ? text : String::toLower( text ) ); |
| 406 | break; |
| 407 | case Abstract::UIAbstractView::FindRowWithTextMatchKind::Contains: |
| 408 | matches = caseSensitive ? String::contains( var.toString(), text ) |
| 409 | : String::icontains( var.toString(), text ); |
| 410 | break; |
| 411 | } |
| 412 | |
| 413 | if ( matches ) |
| 414 | return model->index( index.row(), 0 ); |
| 415 | } |
| 416 | } |
| 417 | return {}; |
| 418 | } |
| 419 | |
| 420 | }} // namespace EE::UI |
nothing calls this directly
no test coverage detected