mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 18:22:45 +00:00 
			
		
		
		
	LibGUI+DevTools+Applications: Use ModelIndex::data() in many places
This way you don't have to keep track of which model it came from.
This commit is contained in:
		
							parent
							
								
									96f98b1fc9
								
							
						
					
					
						commit
						9102b624ac
					
				
					 18 changed files with 56 additions and 57 deletions
				
			
		|  | @ -119,8 +119,8 @@ void BookmarksBarWidget::model_did_update(unsigned) | ||||||
|     int width = 0; |     int width = 0; | ||||||
|     for (int item_index = 0; item_index < model()->row_count(); ++item_index) { |     for (int item_index = 0; item_index < model()->row_count(); ++item_index) { | ||||||
| 
 | 
 | ||||||
|         auto title = model()->data(model()->index(item_index, 0)).to_string(); |         auto title = model()->index(item_index, 0).data().to_string(); | ||||||
|         auto url = model()->data(model()->index(item_index, 1)).to_string(); |         auto url = model()->index(item_index, 1).data().to_string(); | ||||||
| 
 | 
 | ||||||
|         Gfx::IntRect rect { width, 0, font().width(title) + 32, height() }; |         Gfx::IntRect rect { width, 0, font().width(title) + 32, height() }; | ||||||
| 
 | 
 | ||||||
|  | @ -192,8 +192,8 @@ bool BookmarksBarWidget::contains_bookmark(const String& url) | ||||||
| { | { | ||||||
|     for (int item_index = 0; item_index < model()->row_count(); ++item_index) { |     for (int item_index = 0; item_index < model()->row_count(); ++item_index) { | ||||||
| 
 | 
 | ||||||
|         auto item_title = model()->data(model()->index(item_index, 0)).to_string(); |         auto item_title = model()->index(item_index, 0).data().to_string(); | ||||||
|         auto item_url = model()->data(model()->index(item_index, 1)).to_string(); |         auto item_url = model()->index(item_index, 1).data().to_string(); | ||||||
|         if (item_url == url) { |         if (item_url == url) { | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|  | @ -205,8 +205,8 @@ bool BookmarksBarWidget::remove_bookmark(const String& url) | ||||||
| { | { | ||||||
|     for (int item_index = 0; item_index < model()->row_count(); ++item_index) { |     for (int item_index = 0; item_index < model()->row_count(); ++item_index) { | ||||||
| 
 | 
 | ||||||
|         auto item_title = model()->data(model()->index(item_index, 0)).to_string(); |         auto item_title = model()->index(item_index, 0).data().to_string(); | ||||||
|         auto item_url = model()->data(model()->index(item_index, 1)).to_string(); |         auto item_url = model()->index(item_index, 1).data().to_string(); | ||||||
|         if (item_url == url) { |         if (item_url == url) { | ||||||
|             auto& json_model = *static_cast<GUI::JsonArrayModel*>(model()); |             auto& json_model = *static_cast<GUI::JsonArrayModel*>(model()); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -326,7 +326,7 @@ void DirectoryView::update_statusbar() | ||||||
|     current_view().selection().for_each_index([&](auto& index) { |     current_view().selection().for_each_index([&](auto& index) { | ||||||
|         auto& model = *current_view().model(); |         auto& model = *current_view().model(); | ||||||
|         auto size_index = model.index(index.row(), GUI::FileSystemModel::Column::Size, model.parent_index(index)); |         auto size_index = model.index(index.row(), GUI::FileSystemModel::Column::Size, model.parent_index(index)); | ||||||
|         auto file_size = model.data(size_index).to_i32(); |         auto file_size = size_index.data().to_i32(); | ||||||
|         selected_byte_count += file_size; |         selected_byte_count += file_size; | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -438,7 +438,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio | ||||||
|         view.selection().for_each_index([&](const GUI::ModelIndex& index) { |         view.selection().for_each_index([&](const GUI::ModelIndex& index) { | ||||||
|             auto parent_index = model.parent_index(index); |             auto parent_index = model.parent_index(index); | ||||||
|             auto name_index = model.index(index.row(), GUI::FileSystemModel::Column::Name, parent_index); |             auto name_index = model.index(index.row(), GUI::FileSystemModel::Column::Name, parent_index); | ||||||
|             auto path = model.data(name_index, GUI::ModelRole::Custom).to_string(); |             auto path = name_index.data(GUI::ModelRole::Custom).to_string(); | ||||||
|             paths.append(path); |             paths.append(path); | ||||||
|         }); |         }); | ||||||
|         return paths; |         return paths; | ||||||
|  |  | ||||||
|  | @ -193,7 +193,7 @@ int main(int argc, char** argv) | ||||||
|         if (process_table_view.selection().is_empty()) |         if (process_table_view.selection().is_empty()) | ||||||
|             return -1; |             return -1; | ||||||
|         auto pid_index = process_table_view.model()->index(process_table_view.selection().first().row(), column); |         auto pid_index = process_table_view.model()->index(process_table_view.selection().first().row(), column); | ||||||
|         return process_table_view.model()->data(pid_index, GUI::ModelRole::Display).to_i32(); |         return pid_index.data().to_i32(); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     auto kill_action = GUI::Action::create("Kill process", { Mod_Ctrl, Key_K }, Gfx::Bitmap::load_from_file("/res/icons/kill16.png"), [&](const GUI::Action&) { |     auto kill_action = GUI::Action::create("Kill process", { Mod_Ctrl, Key_K }, Gfx::Bitmap::load_from_file("/res/icons/kill16.png"), [&](const GUI::Action&) { | ||||||
|  | @ -342,7 +342,7 @@ public: | ||||||
|         auto rect = a_rect.shrunken(2, 2); |         auto rect = a_rect.shrunken(2, 2); | ||||||
|         auto percentage = index.data(GUI::ModelRole::Custom).to_i32(); |         auto percentage = index.data(GUI::ModelRole::Custom).to_i32(); | ||||||
| 
 | 
 | ||||||
|         auto data = index.data(GUI::ModelRole::Display); |         auto data = index.data(); | ||||||
|         String text; |         String text; | ||||||
|         if (data.is_string()) |         if (data.is_string()) | ||||||
|             text = data.as_string(); |             text = data.as_string(); | ||||||
|  |  | ||||||
|  | @ -142,7 +142,7 @@ Locator::~Locator() | ||||||
| void Locator::open_suggestion(const GUI::ModelIndex& index) | void Locator::open_suggestion(const GUI::ModelIndex& index) | ||||||
| { | { | ||||||
|     auto filename_index = m_suggestion_view->model()->index(index.row(), LocatorSuggestionModel::Column::Name); |     auto filename_index = m_suggestion_view->model()->index(index.row(), LocatorSuggestionModel::Column::Name); | ||||||
|     auto filename = m_suggestion_view->model()->data(filename_index, GUI::ModelRole::Display).to_string(); |     auto filename = filename_index.data().to_string(); | ||||||
|     open_file(filename); |     open_file(filename); | ||||||
|     close(); |     close(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -225,7 +225,7 @@ int main(int argc, char** argv) | ||||||
|     auto selected_file_names = [&] { |     auto selected_file_names = [&] { | ||||||
|         Vector<String> files; |         Vector<String> files; | ||||||
|         g_project_tree_view->selection().for_each_index([&](const GUI::ModelIndex& index) { |         g_project_tree_view->selection().for_each_index([&](const GUI::ModelIndex& index) { | ||||||
|             files.append(g_project->model().data(index).as_string()); |             files.append(index.data().as_string()); | ||||||
|         }); |         }); | ||||||
|         return files; |         return files; | ||||||
|     }; |     }; | ||||||
|  | @ -478,7 +478,7 @@ int main(int argc, char** argv) | ||||||
|     toolbar.add_separator(); |     toolbar.add_separator(); | ||||||
| 
 | 
 | ||||||
|     g_project_tree_view->on_activation = [&](auto& index) { |     g_project_tree_view->on_activation = [&](auto& index) { | ||||||
|         auto filename = g_project_tree_view->model()->data(index, GUI::ModelRole::Custom).to_string(); |         auto filename = index.data(GUI::ModelRole::Custom).to_string(); | ||||||
|         open_file(filename); |         open_file(filename); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -94,7 +94,7 @@ VBPropertiesWindow::VBPropertiesWindow() | ||||||
|         if (!m_table_view->model()) |         if (!m_table_view->model()) | ||||||
|             return nullptr; |             return nullptr; | ||||||
|         auto type_index = m_table_view->model()->index(index.row(), VBWidgetPropertyModel::Column::Type); |         auto type_index = m_table_view->model()->index(index.row(), VBWidgetPropertyModel::Column::Type); | ||||||
|         auto type = m_table_view->model()->data(type_index, GUI::ModelRole::Custom).to_i32(); |         auto type = type_index.data(GUI::ModelRole::Custom).to_i32(); | ||||||
|         switch ((GUI::Variant::Type)type) { |         switch ((GUI::Variant::Type)type) { | ||||||
|         case GUI::Variant::Type::Bool: |         case GUI::Variant::Type::Bool: | ||||||
|             return make<BoolModelEditingDelegate>(); |             return make<BoolModelEditingDelegate>(); | ||||||
|  |  | ||||||
|  | @ -74,7 +74,7 @@ void AbstractTableView::update_column_sizes() | ||||||
|             header_width += font().width(" \xE2\xAC\x86"); // UPWARDS BLACK ARROW
 |             header_width += font().width(" \xE2\xAC\x86"); // UPWARDS BLACK ARROW
 | ||||||
|         int column_width = header_width; |         int column_width = header_width; | ||||||
|         for (int row = 0; row < row_count; ++row) { |         for (int row = 0; row < row_count; ++row) { | ||||||
|             auto cell_data = model.data(model.index(row, column)); |             auto cell_data = model.index(row, column).data(); | ||||||
|             int cell_width = 0; |             int cell_width = 0; | ||||||
|             if (cell_data.is_icon()) { |             if (cell_data.is_icon()) { | ||||||
|                 cell_width = item_height(); |                 cell_width = item_height(); | ||||||
|  |  | ||||||
|  | @ -134,7 +134,7 @@ void AbstractView::begin_editing(const ModelIndex& index) | ||||||
|     ASSERT(aid_create_editing_delegate); |     ASSERT(aid_create_editing_delegate); | ||||||
|     m_editing_delegate = aid_create_editing_delegate(index); |     m_editing_delegate = aid_create_editing_delegate(index); | ||||||
|     m_editing_delegate->bind(*model(), index); |     m_editing_delegate->bind(*model(), index); | ||||||
|     m_editing_delegate->set_value(model()->data(index, ModelRole::Display)); |     m_editing_delegate->set_value(index.data()); | ||||||
|     m_edit_widget = m_editing_delegate->widget(); |     m_edit_widget = m_editing_delegate->widget(); | ||||||
|     add_child(*m_edit_widget); |     add_child(*m_edit_widget); | ||||||
|     m_edit_widget->move_to_back(); |     m_edit_widget->move_to_back(); | ||||||
|  | @ -187,7 +187,7 @@ NonnullRefPtr<Gfx::Font> AbstractView::font_for_index(const ModelIndex& index) c | ||||||
|     if (!model()) |     if (!model()) | ||||||
|         return font(); |         return font(); | ||||||
| 
 | 
 | ||||||
|     auto font_data = model()->data(index, ModelRole::Font); |     auto font_data = index.data(ModelRole::Font); | ||||||
|     if (font_data.is_font()) |     if (font_data.is_font()) | ||||||
|         return font_data.as_font(); |         return font_data.as_font(); | ||||||
| 
 | 
 | ||||||
|  | @ -280,19 +280,19 @@ void AbstractView::mousemove_event(MouseEvent& event) | ||||||
|     StringBuilder data_builder; |     StringBuilder data_builder; | ||||||
|     bool first = true; |     bool first = true; | ||||||
|     m_selection.for_each_index([&](auto& index) { |     m_selection.for_each_index([&](auto& index) { | ||||||
|         auto text_data = m_model->data(index); |         auto text_data = index.data(); | ||||||
|         if (!first) |         if (!first) | ||||||
|             text_builder.append(", "); |             text_builder.append(", "); | ||||||
|         text_builder.append(text_data.to_string()); |         text_builder.append(text_data.to_string()); | ||||||
| 
 | 
 | ||||||
|         auto drag_data = m_model->data(index, ModelRole::DragData); |         auto drag_data = index.data(ModelRole::DragData); | ||||||
|         data_builder.append(drag_data.to_string()); |         data_builder.append(drag_data.to_string()); | ||||||
|         data_builder.append('\n'); |         data_builder.append('\n'); | ||||||
| 
 | 
 | ||||||
|         first = false; |         first = false; | ||||||
| 
 | 
 | ||||||
|         if (!bitmap) { |         if (!bitmap) { | ||||||
|             Variant icon_data = model()->data(index, ModelRole::Icon); |             Variant icon_data = index.data(ModelRole::Icon); | ||||||
|             if (icon_data.is_icon()) |             if (icon_data.is_icon()) | ||||||
|                 bitmap = icon_data.as_icon().bitmap_for_size(32); |                 bitmap = icon_data.as_icon().bitmap_for_size(32); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -125,7 +125,7 @@ void ColumnsView::paint_event(PaintEvent& event) | ||||||
|             Gfx::IntRect row_rect { column_x, row * item_height(), column.width, item_height() }; |             Gfx::IntRect row_rect { column_x, row * item_height(), column.width, item_height() }; | ||||||
|             painter.fill_rect(row_rect, background_color); |             painter.fill_rect(row_rect, background_color); | ||||||
| 
 | 
 | ||||||
|             auto icon = model()->data(index, ModelRole::Icon); |             auto icon = index.data(ModelRole::Icon); | ||||||
|             Gfx::IntRect icon_rect = { column_x + icon_spacing(), 0, icon_size(), icon_size() }; |             Gfx::IntRect icon_rect = { column_x + icon_spacing(), 0, icon_size(), icon_size() }; | ||||||
|             icon_rect.center_vertically_within(row_rect); |             icon_rect.center_vertically_within(row_rect); | ||||||
|             if (icon.is_icon()) { |             if (icon.is_icon()) { | ||||||
|  | @ -141,7 +141,7 @@ void ColumnsView::paint_event(PaintEvent& event) | ||||||
|                 icon_rect.right() + 1 + icon_spacing(), row * item_height(), |                 icon_rect.right() + 1 + icon_spacing(), row * item_height(), | ||||||
|                 column.width - icon_spacing() - icon_size() - icon_spacing() - icon_spacing() - s_arrow_bitmap_width - icon_spacing(), item_height() |                 column.width - icon_spacing() - icon_size() - icon_spacing() - icon_spacing() - s_arrow_bitmap_width - icon_spacing(), item_height() | ||||||
|             }; |             }; | ||||||
|             auto text = model()->data(index).to_string(); |             auto text = index.data().to_string(); | ||||||
|             painter.draw_text(text_rect, text, Gfx::TextAlignment::CenterLeft, text_color); |             painter.draw_text(text_rect, text, Gfx::TextAlignment::CenterLeft, text_color); | ||||||
| 
 | 
 | ||||||
|             bool expandable = model()->row_count(index) > 0; |             bool expandable = model()->row_count(index) > 0; | ||||||
|  | @ -203,7 +203,7 @@ void ColumnsView::update_column_sizes() | ||||||
|         for (int row = 0; row < row_count; row++) { |         for (int row = 0; row < row_count; row++) { | ||||||
|             ModelIndex index = model()->index(row, m_model_column, column.parent_index); |             ModelIndex index = model()->index(row, m_model_column, column.parent_index); | ||||||
|             ASSERT(index.is_valid()); |             ASSERT(index.is_valid()); | ||||||
|             auto text = model()->data(index).to_string(); |             auto text = index.data().to_string(); | ||||||
|             int row_width = icon_spacing() + icon_size() + icon_spacing() + font().width(text) + icon_spacing() + s_arrow_bitmap_width + icon_spacing(); |             int row_width = icon_spacing() + icon_size() + icon_spacing() + font().width(text) + icon_spacing() + s_arrow_bitmap_width + icon_spacing(); | ||||||
|             if (row_width > column.width) |             if (row_width > column.width) | ||||||
|                 column.width = row_width; |                 column.width = row_width; | ||||||
|  |  | ||||||
|  | @ -118,7 +118,7 @@ ComboBox::ComboBox() | ||||||
|     m_list_view->on_selection = [this](auto& index) { |     m_list_view->on_selection = [this](auto& index) { | ||||||
|         ASSERT(model()); |         ASSERT(model()); | ||||||
|         m_list_view->set_activates_on_selection(true); |         m_list_view->set_activates_on_selection(true); | ||||||
|         auto new_value = model()->data(index).to_string(); |         auto new_value = index.data().to_string(); | ||||||
|         m_editor->set_text(new_value); |         m_editor->set_text(new_value); | ||||||
|         if (!m_only_allow_values_from_model) |         if (!m_only_allow_values_from_model) | ||||||
|             m_editor->select_all(); |             m_editor->select_all(); | ||||||
|  | @ -178,7 +178,7 @@ void ComboBox::open() | ||||||
|     int longest_item_width = 0; |     int longest_item_width = 0; | ||||||
|     for (int i = 0; i < model()->row_count(); ++i) { |     for (int i = 0; i < model()->row_count(); ++i) { | ||||||
|         auto index = model()->index(i); |         auto index = model()->index(i); | ||||||
|         auto item_text = model()->data(index).to_string(); |         auto item_text = index.data().to_string(); | ||||||
|         longest_item_width = max(longest_item_width, m_list_view->font().width(item_text)); |         longest_item_width = max(longest_item_width, m_list_view->font().width(item_text)); | ||||||
|     } |     } | ||||||
|     Gfx::IntSize size { |     Gfx::IntSize size { | ||||||
|  |  | ||||||
|  | @ -61,7 +61,7 @@ Variant FilteringProxyModel::data(const ModelIndex& index, ModelRole role) const | ||||||
|     if ((size_t)index.row() > m_matching_indices.size() || index.row() < 0) |     if ((size_t)index.row() > m_matching_indices.size() || index.row() < 0) | ||||||
|         return 0; |         return 0; | ||||||
| 
 | 
 | ||||||
|     return m_model.data(m_matching_indices[index.row()], role); |     return m_matching_indices[index.row()].data(role); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void FilteringProxyModel::update() | void FilteringProxyModel::update() | ||||||
|  | @ -84,7 +84,7 @@ void FilteringProxyModel::filter() | ||||||
|             auto filter_matches = m_model.data_matches(index, m_filter_term); |             auto filter_matches = m_model.data_matches(index, m_filter_term); | ||||||
|             bool matches = filter_matches == TriState::True; |             bool matches = filter_matches == TriState::True; | ||||||
|             if (filter_matches == TriState::Unknown) { |             if (filter_matches == TriState::Unknown) { | ||||||
|                 auto data = m_model.data(index, ModelRole::Display); |                 auto data = index.data(); | ||||||
|                 if (data.is_string() && data.as_string().contains(m_filter_term)) |                 if (data.is_string() && data.as_string().contains(m_filter_term)) | ||||||
|                     matches = true; |                     matches = true; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | @ -95,7 +95,7 @@ void IconView::reinit_item_cache() const | ||||||
|         auto& item_data = m_item_data_cache[i]; |         auto& item_data = m_item_data_cache[i]; | ||||||
|         // TODO: It's unfortunate that we have no way to know whether any
 |         // TODO: It's unfortunate that we have no way to know whether any
 | ||||||
|         // data actually changed, so we have to invalidate *everyone*
 |         // data actually changed, so we have to invalidate *everyone*
 | ||||||
|         if (item_data.is_valid()/* && !model()->is_valid(item_data.index)*/) |         if (item_data.is_valid() /* && !model()->is_valid(item_data.index)*/) | ||||||
|             item_data.invalidate(); |             item_data.invalidate(); | ||||||
|         if (item_data.selected && i < (size_t)m_first_selected_hint) |         if (item_data.selected && i < (size_t)m_first_selected_hint) | ||||||
|             m_first_selected_hint = (int)i; |             m_first_selected_hint = (int)i; | ||||||
|  | @ -114,7 +114,7 @@ auto IconView::get_item_data(int item_index) const -> ItemData& | ||||||
|         return item_data; |         return item_data; | ||||||
| 
 | 
 | ||||||
|     item_data.index = model()->index(item_index, model_column()); |     item_data.index = model()->index(item_index, model_column()); | ||||||
|     item_data.data = model()->data(item_data.index); |     item_data.data = item_data.index.data(); | ||||||
|     get_item_rects(item_index, item_data, font_for_index(item_data.index)); |     get_item_rects(item_index, item_data, font_for_index(item_data.index)); | ||||||
|     item_data.valid = true; |     item_data.valid = true; | ||||||
|     return item_data; |     return item_data; | ||||||
|  | @ -338,7 +338,7 @@ void IconView::mousemove_event(MouseEvent& event) | ||||||
|                     scroll_out_of_view_timer_fired(); |                     scroll_out_of_view_timer_fired(); | ||||||
|                 }; |                 }; | ||||||
|             } |             } | ||||||
|              | 
 | ||||||
|             m_out_of_view_position = event.position(); |             m_out_of_view_position = event.position(); | ||||||
|             if (!m_out_of_view_timer->is_active()) |             if (!m_out_of_view_timer->is_active()) | ||||||
|                 m_out_of_view_timer->start(); |                 m_out_of_view_timer->start(); | ||||||
|  | @ -373,7 +373,7 @@ void IconView::scroll_out_of_view_timer_fired() | ||||||
|     else if (m_out_of_view_position.x() < in_view_rect.left()) |     else if (m_out_of_view_position.x() < in_view_rect.left()) | ||||||
|         adjust_x = -(SCROLL_OUT_OF_VIEW_HOT_MARGIN / 2) + max(-SCROLL_OUT_OF_VIEW_HOT_MARGIN, m_out_of_view_position.x() - in_view_rect.left()); |         adjust_x = -(SCROLL_OUT_OF_VIEW_HOT_MARGIN / 2) + max(-SCROLL_OUT_OF_VIEW_HOT_MARGIN, m_out_of_view_position.x() - in_view_rect.left()); | ||||||
| 
 | 
 | ||||||
|     ScrollableWidget::scroll_into_view({scroll_to.translated(adjust_x, adjust_y), {1, 1}}, true, true); |     ScrollableWidget::scroll_into_view({ scroll_to.translated(adjust_x, adjust_y), { 1, 1 } }, true, true); | ||||||
|     update_rubber_banding(m_out_of_view_position); |     update_rubber_banding(m_out_of_view_position); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -423,7 +423,7 @@ void IconView::paint_event(PaintEvent& event) | ||||||
|     Painter painter(*this); |     Painter painter(*this); | ||||||
|     painter.add_clip_rect(widget_inner_rect()); |     painter.add_clip_rect(widget_inner_rect()); | ||||||
|     painter.add_clip_rect(event.rect()); |     painter.add_clip_rect(event.rect()); | ||||||
|      | 
 | ||||||
|     if (fill_with_background_color()) |     if (fill_with_background_color()) | ||||||
|         painter.fill_rect(event.rect(), widget_background_color); |         painter.fill_rect(event.rect(), widget_background_color); | ||||||
|     painter.translate(frame_thickness(), frame_thickness()); |     painter.translate(frame_thickness(), frame_thickness()); | ||||||
|  | @ -438,8 +438,8 @@ void IconView::paint_event(PaintEvent& event) | ||||||
|             background_color = widget_background_color; |             background_color = widget_background_color; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         auto icon = model()->data(item_data.index, ModelRole::Icon); |         auto icon = item_data.index.data(ModelRole::Icon); | ||||||
|         auto item_text = model()->data(item_data.index, ModelRole::Display); |         auto item_text = item_data.index.data(); | ||||||
| 
 | 
 | ||||||
|         if (icon.is_icon()) { |         if (icon.is_icon()) { | ||||||
|             if (auto bitmap = icon.as_icon().bitmap_for_size(item_data.icon_rect.width())) { |             if (auto bitmap = icon.as_icon().bitmap_for_size(item_data.icon_rect.width())) { | ||||||
|  | @ -458,7 +458,7 @@ void IconView::paint_event(PaintEvent& event) | ||||||
|         if (item_data.selected) |         if (item_data.selected) | ||||||
|             text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); |             text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); | ||||||
|         else |         else | ||||||
|             text_color = model()->data(item_data.index, ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); |             text_color = item_data.index.data(ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); | ||||||
|         painter.fill_rect(item_data.text_rect, background_color); |         painter.fill_rect(item_data.text_rect, background_color); | ||||||
|         painter.draw_text(item_data.text_rect, item_text.to_string(), font_for_index(item_data.index), Gfx::TextAlignment::Center, text_color, Gfx::TextElision::Right); |         painter.draw_text(item_data.text_rect, item_text.to_string(), font_for_index(item_data.index), Gfx::TextAlignment::Center, text_color, Gfx::TextElision::Right); | ||||||
| 
 | 
 | ||||||
|  | @ -482,7 +482,7 @@ void IconView::did_update_selection() | ||||||
|     AbstractView::did_update_selection(); |     AbstractView::did_update_selection(); | ||||||
|     if (m_changing_selection) |     if (m_changing_selection) | ||||||
|         return; |         return; | ||||||
|      | 
 | ||||||
|     // Selection was modified externally, we need to synchronize our cache
 |     // Selection was modified externally, we need to synchronize our cache
 | ||||||
|     do_clear_selection(); |     do_clear_selection(); | ||||||
|     selection().for_each_index([&](const ModelIndex& index) { |     selection().for_each_index([&](const ModelIndex& index) { | ||||||
|  |  | ||||||
|  | @ -59,7 +59,7 @@ void ListView::update_content_size() | ||||||
| 
 | 
 | ||||||
|     int content_width = 0; |     int content_width = 0; | ||||||
|     for (int row = 0, row_count = model()->row_count(); row < row_count; ++row) { |     for (int row = 0, row_count = model()->row_count(); row < row_count; ++row) { | ||||||
|         auto text = model()->data(model()->index(row, m_model_column), ModelRole::Display); |         auto text = model()->index(row, m_model_column).data(); | ||||||
|         content_width = max(content_width, font().width(text.to_string())); |         content_width = max(content_width, font().width(text.to_string())); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -150,7 +150,7 @@ void ListView::paint_event(PaintEvent& event) | ||||||
|         Gfx::IntRect row_rect(0, y, content_width(), item_height()); |         Gfx::IntRect row_rect(0, y, content_width(), item_height()); | ||||||
|         painter.fill_rect(row_rect, background_color); |         painter.fill_rect(row_rect, background_color); | ||||||
|         auto index = model()->index(row_index, m_model_column); |         auto index = model()->index(row_index, m_model_column); | ||||||
|         auto data = model()->data(index); |         auto data = index.data(); | ||||||
|         auto font = font_for_index(index); |         auto font = font_for_index(index); | ||||||
|         if (data.is_bitmap()) { |         if (data.is_bitmap()) { | ||||||
|             painter.blit(row_rect.location(), data.as_bitmap(), data.as_bitmap().rect()); |             painter.blit(row_rect.location(), data.as_bitmap(), data.as_bitmap().rect()); | ||||||
|  | @ -162,11 +162,11 @@ void ListView::paint_event(PaintEvent& event) | ||||||
|             if (is_selected_row) |             if (is_selected_row) | ||||||
|                 text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); |                 text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); | ||||||
|             else |             else | ||||||
|                 text_color = model()->data(index, ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); |                 text_color = index.data(ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); | ||||||
|             auto text_rect = row_rect; |             auto text_rect = row_rect; | ||||||
|             text_rect.move_by(horizontal_padding(), 0); |             text_rect.move_by(horizontal_padding(), 0); | ||||||
|             text_rect.set_width(text_rect.width() - horizontal_padding() * 2); |             text_rect.set_width(text_rect.width() - horizontal_padding() * 2); | ||||||
|             auto text_alignment = model()->data(index, ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); |             auto text_alignment = index.data(ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); | ||||||
|             painter.draw_text(text_rect, data.to_string(), font, text_alignment, text_color); |             painter.draw_text(text_rect, data.to_string(), font, text_alignment, text_color); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -96,7 +96,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView& | ||||||
|     m_refresh_timer->on_timeout = [this] { |     m_refresh_timer->on_timeout = [this] { | ||||||
|         auto previous_selected_pid = -1; // Store the selection index to not to clear the selection upon update.
 |         auto previous_selected_pid = -1; // Store the selection index to not to clear the selection upon update.
 | ||||||
|         if (!m_table_view->selection().is_empty()) { |         if (!m_table_view->selection().is_empty()) { | ||||||
|             auto pid_as_variant = m_table_view->model()->data(m_table_view->selection().first(), GUI::ModelRole::Custom); |             auto pid_as_variant = m_table_view->selection().first().data(GUI::ModelRole::Custom); | ||||||
|             previous_selected_pid = pid_as_variant.as_i32(); |             previous_selected_pid = pid_as_variant.as_i32(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -111,7 +111,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView& | ||||||
|         auto column_index = 1; // Corresponds to PID column in the m_table_view.
 |         auto column_index = 1; // Corresponds to PID column in the m_table_view.
 | ||||||
|         for (int row_index = 0; row_index < row_count; ++row_index) { |         for (int row_index = 0; row_index < row_count; ++row_index) { | ||||||
|             auto cell_index = model->index(row_index, column_index); |             auto cell_index = model->index(row_index, column_index); | ||||||
|             auto pid_as_variant = model->data(cell_index, GUI::ModelRole::Custom); |             auto pid_as_variant = cell_index.data(GUI::ModelRole::Custom); | ||||||
|             if (previous_selected_pid == pid_as_variant.as_i32()) { |             if (previous_selected_pid == pid_as_variant.as_i32()) { | ||||||
|                 m_table_view->selection().set(cell_index); // Set only if PIDs are matched.
 |                 m_table_view->selection().set(cell_index); // Set only if PIDs are matched.
 | ||||||
|             } |             } | ||||||
|  | @ -121,8 +121,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView& | ||||||
| 
 | 
 | ||||||
| void ProcessChooser::set_pid_from_index_and_close(const ModelIndex& index) | void ProcessChooser::set_pid_from_index_and_close(const ModelIndex& index) | ||||||
| { | { | ||||||
|     auto pid_as_variant = m_table_view->model()->data(index, GUI::ModelRole::Custom); |     m_pid = index.data(GUI::ModelRole::Custom).as_i32(); | ||||||
|     m_pid = pid_as_variant.as_i32(); |  | ||||||
|     done(ExecOK); |     done(ExecOK); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -130,8 +130,8 @@ StringView SortingProxyModel::drag_data_type() const | ||||||
| 
 | 
 | ||||||
| bool SortingProxyModel::less_than(const ModelIndex& index1, const ModelIndex& index2) const | bool SortingProxyModel::less_than(const ModelIndex& index1, const ModelIndex& index2) const | ||||||
| { | { | ||||||
|     auto data1 = index1.model() ? index1.model()->data(index1, m_sort_role) : Variant(); |     auto data1 = index1.data(m_sort_role); | ||||||
|     auto data2 = index2.model() ? index2.model()->data(index2, m_sort_role) : Variant(); |     auto data2 = index2.data(m_sort_role); | ||||||
|     if (data1.is_string() && data2.is_string()) |     if (data1.is_string() && data2.is_string()) | ||||||
|         return data1.as_string().to_lowercase() < data2.as_string().to_lowercase(); |         return data1.as_string().to_lowercase() < data2.as_string().to_lowercase(); | ||||||
|     return data1 < data2; |     return data1 < data2; | ||||||
|  |  | ||||||
|  | @ -113,7 +113,7 @@ void TableView::paint_event(PaintEvent& event) | ||||||
|             if (auto* delegate = column_data(column_index).cell_painting_delegate.ptr()) { |             if (auto* delegate = column_data(column_index).cell_painting_delegate.ptr()) { | ||||||
|                 delegate->paint(painter, cell_rect, palette(), cell_index); |                 delegate->paint(painter, cell_rect, palette(), cell_index); | ||||||
|             } else { |             } else { | ||||||
|                 auto data = model()->data(cell_index); |                 auto data = cell_index.data(); | ||||||
|                 if (data.is_bitmap()) { |                 if (data.is_bitmap()) { | ||||||
|                     painter.blit(cell_rect.location(), data.as_bitmap(), data.as_bitmap().rect()); |                     painter.blit(cell_rect.location(), data.as_bitmap(), data.as_bitmap().rect()); | ||||||
|                 } else if (data.is_icon()) { |                 } else if (data.is_icon()) { | ||||||
|  | @ -128,13 +128,13 @@ void TableView::paint_event(PaintEvent& event) | ||||||
|                     if (is_selected_row) |                     if (is_selected_row) | ||||||
|                         text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); |                         text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); | ||||||
|                     else |                     else | ||||||
|                         text_color = model()->data(cell_index, ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); |                         text_color = cell_index.data(ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); | ||||||
|                     if (!is_selected_row) { |                     if (!is_selected_row) { | ||||||
|                         auto cell_background_color = model()->data(cell_index, ModelRole::BackgroundColor); |                         auto cell_background_color = cell_index.data(ModelRole::BackgroundColor); | ||||||
|                         if (cell_background_color.is_valid()) |                         if (cell_background_color.is_valid()) | ||||||
|                             painter.fill_rect(cell_rect_for_fill, cell_background_color.to_color(background_color)); |                             painter.fill_rect(cell_rect_for_fill, cell_background_color.to_color(background_color)); | ||||||
|                     } |                     } | ||||||
|                     auto text_alignment = model()->data(cell_index, ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); |                     auto text_alignment = cell_index.data(ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); | ||||||
|                     painter.draw_text(cell_rect, data.to_string(), font_for_index(cell_index), text_alignment, text_color, Gfx::TextElision::Right); |                     painter.draw_text(cell_rect, data.to_string(), font_for_index(cell_index), text_alignment, text_color, Gfx::TextElision::Right); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | @ -171,7 +171,7 @@ void TreeView::traverse_in_paint_order(Callback callback) const | ||||||
|         if (index.is_valid()) { |         if (index.is_valid()) { | ||||||
|             auto& metadata = ensure_metadata_for_index(index); |             auto& metadata = ensure_metadata_for_index(index); | ||||||
|             int x_offset = tree_column_x_offset + horizontal_padding() + indent_level * indent_width_in_pixels(); |             int x_offset = tree_column_x_offset + horizontal_padding() + indent_level * indent_width_in_pixels(); | ||||||
|             auto node_text = model.data(index, ModelRole::Display).to_string(); |             auto node_text = index.data().to_string(); | ||||||
|             Gfx::IntRect rect = { |             Gfx::IntRect rect = { | ||||||
|                 x_offset, y_offset, |                 x_offset, y_offset, | ||||||
|                 icon_size() + icon_spacing() + text_padding() + font_for_index(index)->width(node_text) + text_padding(), item_height() |                 icon_size() + icon_spacing() + text_padding() + font_for_index(index)->width(node_text) + text_padding(), item_height() | ||||||
|  | @ -293,7 +293,7 @@ void TreeView::paint_event(PaintEvent& event) | ||||||
|                 if (auto* delegate = column_data(column_index).cell_painting_delegate.ptr()) { |                 if (auto* delegate = column_data(column_index).cell_painting_delegate.ptr()) { | ||||||
|                     delegate->paint(painter, cell_rect, palette(), cell_index); |                     delegate->paint(painter, cell_rect, palette(), cell_index); | ||||||
|                 } else { |                 } else { | ||||||
|                     auto data = model.data(cell_index); |                     auto data = cell_index.data(); | ||||||
| 
 | 
 | ||||||
|                     if (data.is_bitmap()) { |                     if (data.is_bitmap()) { | ||||||
|                         painter.blit(cell_rect.location(), data.as_bitmap(), data.as_bitmap().rect()); |                         painter.blit(cell_rect.location(), data.as_bitmap(), data.as_bitmap().rect()); | ||||||
|  | @ -302,15 +302,15 @@ void TreeView::paint_event(PaintEvent& event) | ||||||
|                             painter.blit(cell_rect.location(), *bitmap, bitmap->rect()); |                             painter.blit(cell_rect.location(), *bitmap, bitmap->rect()); | ||||||
|                     } else { |                     } else { | ||||||
|                         if (!is_selected_row) |                         if (!is_selected_row) | ||||||
|                             text_color = model.data(cell_index, ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); |                             text_color = cell_index.data(ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); | ||||||
|                         auto text_alignment = model.data(cell_index, ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); |                         auto text_alignment = cell_index.data(ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); | ||||||
|                         painter.draw_text(cell_rect, data.to_string(), font_for_index(cell_index), text_alignment, text_color, Gfx::TextElision::Right); |                         painter.draw_text(cell_rect, data.to_string(), font_for_index(cell_index), text_alignment, text_color, Gfx::TextElision::Right); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } else { |             } else { | ||||||
|                 // It's the tree column!
 |                 // It's the tree column!
 | ||||||
|                 Gfx::IntRect icon_rect = { rect.x(), rect.y(), icon_size(), icon_size() }; |                 Gfx::IntRect icon_rect = { rect.x(), rect.y(), icon_size(), icon_size() }; | ||||||
|                 auto icon = model.data(index, ModelRole::Icon); |                 auto icon = index.data(ModelRole::Icon); | ||||||
|                 if (icon.is_icon()) { |                 if (icon.is_icon()) { | ||||||
|                     if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size())) { |                     if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size())) { | ||||||
|                         if (m_hovered_index.is_valid() && m_hovered_index.parent() == index.parent() && m_hovered_index.row() == index.row()) |                         if (m_hovered_index.is_valid() && m_hovered_index.parent() == index.parent() && m_hovered_index.row() == index.row()) | ||||||
|  | @ -323,7 +323,7 @@ void TreeView::paint_event(PaintEvent& event) | ||||||
|                     icon_rect.right() + 1 + icon_spacing(), rect.y(), |                     icon_rect.right() + 1 + icon_spacing(), rect.y(), | ||||||
|                     rect.width() - icon_size() - icon_spacing(), rect.height() |                     rect.width() - icon_size() - icon_spacing(), rect.height() | ||||||
|                 }; |                 }; | ||||||
|                 auto node_text = model.data(index, ModelRole::Display).to_string(); |                 auto node_text = index.data().to_string(); | ||||||
|                 painter.draw_text(text_rect, node_text, font_for_index(index), Gfx::TextAlignment::Center, text_color); |                 painter.draw_text(text_rect, node_text, font_for_index(index), Gfx::TextAlignment::Center, text_color); | ||||||
|                 auto index_at_indent = index; |                 auto index_at_indent = index; | ||||||
|                 for (int i = indent_level; i > 0; --i) { |                 for (int i = indent_level; i > 0; --i) { | ||||||
|  | @ -544,7 +544,7 @@ void TreeView::update_column_sizes() | ||||||
|         int column_width = header_width; |         int column_width = header_width; | ||||||
| 
 | 
 | ||||||
|         for (int row = 0; row < row_count; ++row) { |         for (int row = 0; row < row_count; ++row) { | ||||||
|             auto cell_data = model.data(model.index(row, column)); |             auto cell_data = model.index(row, column).data(); | ||||||
|             int cell_width = 0; |             int cell_width = 0; | ||||||
|             if (cell_data.is_bitmap()) { |             if (cell_data.is_bitmap()) { | ||||||
|                 cell_width = cell_data.as_bitmap().width(); |                 cell_width = cell_data.as_bitmap().width(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling