| 131 | } |
| 132 | |
| 133 | Float UITableView::getMaxColumnContentWidth( const size_t& colIndex, bool bestGuess ) { |
| 134 | Float lWidth = 0; |
| 135 | ConditionalLock l( getModel() != nullptr, getModel() ? &getModel()->resourceMutex() : nullptr ); |
| 136 | if ( nullptr == getModel() || !getModel()->hasChildren() ) |
| 137 | return lWidth; |
| 138 | ScopedOp op( [this] { mUISceneNode->setIsLoading( true ); }, |
| 139 | [this] { mUISceneNode->setIsLoading( false ); } ); |
| 140 | Float yOffset = getHeaderHeight(); |
| 141 | auto worstCaseFunc = [&]( const ModelIndex& index ) { |
| 142 | UIWidget* widget = updateCell( { (Int64)0, (Int64)0 }, index, 0, yOffset ); |
| 143 | if ( widget->isType( UI_TYPE_PUSHBUTTON ) ) { |
| 144 | Float w = widget->asType<UIPushButton>()->getContentSize().getWidth(); |
| 145 | if ( w > lWidth ) |
| 146 | lWidth = w; |
| 147 | } |
| 148 | }; |
| 149 | // TODO: Improve best guess |
| 150 | if ( bestGuess && getItemCount() > 10 ) { |
| 151 | Variant dataTest( getModel()->data( getModel()->index( 0, colIndex ) ) ); |
| 152 | if ( dataTest.isString() ) { |
| 153 | std::map<size_t, ModelIndex> lengths; |
| 154 | for ( size_t i = 0; i < getItemCount(); i++ ) { |
| 155 | ModelIndex index( getModel()->index( i, colIndex ) ); |
| 156 | Variant data( getModel()->data( index ) ); |
| 157 | if ( !data.isValid() ) |
| 158 | continue; |
| 159 | size_t length = data.size(); |
| 160 | if ( lengths.empty() || length > lengths.rbegin()->first ) |
| 161 | lengths[length] = index; |
| 162 | } |
| 163 | size_t i = 0; |
| 164 | auto it = lengths.rbegin(); |
| 165 | for ( ; it != lengths.rend() && i < 10; it++, i++ ) |
| 166 | worstCaseFunc( it->second ); |
| 167 | } else { |
| 168 | for ( size_t i = 0; i < getItemCount(); i++ ) |
| 169 | worstCaseFunc( getModel()->index( i, colIndex ) ); |
| 170 | } |
| 171 | } else { |
| 172 | for ( size_t i = 0; i < getItemCount(); i++ ) |
| 173 | worstCaseFunc( getModel()->index( i, colIndex ) ); |
| 174 | } |
| 175 | return lWidth; |
| 176 | } |
| 177 | |
| 178 | void UITableView::createOrUpdateColumns( bool resetColumnData ) { |
| 179 | if ( !getModel() ) { |
nothing calls this directly
no test coverage detected