Ver código fonte

Userland: Fix remaining smart pointer const-correctness issues

Andreas Kling 2 anos atrás
pai
commit
33e87d1627

+ 1 - 1
Userland/Applications/FontEditor/UndoSelection.h

@@ -13,7 +13,7 @@
 
 
 class UndoSelection : public RefCounted<UndoSelection> {
 class UndoSelection : public RefCounted<UndoSelection> {
 public:
 public:
-    explicit UndoSelection(int const start, int const size, u32 const active_glyph, Gfx::BitmapFont const& font, NonnullRefPtr<GUI::GlyphMapWidget> glyph_map_widget)
+    explicit UndoSelection(int const start, int const size, u32 const active_glyph, Gfx::BitmapFont& font, NonnullRefPtr<GUI::GlyphMapWidget> glyph_map_widget)
         : m_start(start)
         : m_start(start)
         , m_size(size)
         , m_size(size)
         , m_active_glyph(active_glyph)
         , m_active_glyph(active_glyph)

+ 1 - 1
Userland/Applications/Help/ManualModel.cpp

@@ -149,7 +149,7 @@ GUI::ModelIndex ManualModel::parent_index(const GUI::ModelIndex& index) const
         return {};
         return {};
     auto children = maybe_children.release_value();
     auto children = maybe_children.release_value();
     for (size_t row = 0; row < children.size(); row++) {
     for (size_t row = 0; row < children.size(); row++) {
-        Manual::Node* child_at_row = children[row];
+        Manual::Node const* child_at_row = children[row];
         if (child_at_row == parent)
         if (child_at_row == parent)
             return create_index(row, 0, parent);
             return create_index(row, 0, parent);
     }
     }

+ 1 - 1
Userland/Applications/ImageViewer/ViewWidget.h

@@ -66,7 +66,7 @@ private:
     Vector<DeprecatedString> load_files_from_directory(DeprecatedString const& path) const;
     Vector<DeprecatedString> load_files_from_directory(DeprecatedString const& path) const;
 
 
     DeprecatedString m_path;
     DeprecatedString m_path;
-    RefPtr<Gfx::Bitmap> m_bitmap;
+    RefPtr<Gfx::Bitmap const> m_bitmap;
     Optional<ImageDecoderClient::DecodedImage> m_decoded_image;
     Optional<ImageDecoderClient::DecodedImage> m_decoded_image;
 
 
     size_t m_current_frame_index { 0 };
     size_t m_current_frame_index { 0 };

+ 1 - 1
Userland/Applications/PixelPaint/Tools/TextTool.h

@@ -53,7 +53,7 @@ private:
     RefPtr<Core::Timer> m_cursor_blink_timer;
     RefPtr<Core::Timer> m_cursor_blink_timer;
     RefPtr<PixelPaint::TextToolEditor> m_text_editor;
     RefPtr<PixelPaint::TextToolEditor> m_text_editor;
     Gfx::IntPoint m_add_text_position { 0, 0 };
     Gfx::IntPoint m_add_text_position { 0, 0 };
-    RefPtr<Gfx::Font> m_selected_font;
+    RefPtr<Gfx::Font const> m_selected_font;
     bool m_text_input_is_active { false };
     bool m_text_input_is_active { false };
     bool m_cursor_blink_state { false };
     bool m_cursor_blink_state { false };
     bool m_mouse_is_over_text { false };
     bool m_mouse_is_over_text { false };

+ 2 - 2
Userland/Applications/TerminalSettings/TerminalSettingsWidget.h

@@ -47,13 +47,13 @@ private:
     TerminalSettingsViewWidget();
     TerminalSettingsViewWidget();
     void write_back_settings() const;
     void write_back_settings() const;
 
 
-    RefPtr<Gfx::Font> m_font;
+    RefPtr<Gfx::Font const> m_font;
     float m_opacity;
     float m_opacity;
     DeprecatedString m_color_scheme;
     DeprecatedString m_color_scheme;
     VT::CursorShape m_cursor_shape { VT::CursorShape::Block };
     VT::CursorShape m_cursor_shape { VT::CursorShape::Block };
     bool m_cursor_is_blinking_set { true };
     bool m_cursor_is_blinking_set { true };
 
 
-    RefPtr<Gfx::Font> m_original_font;
+    RefPtr<Gfx::Font const> m_original_font;
     float m_original_opacity;
     float m_original_opacity;
     DeprecatedString m_original_color_scheme;
     DeprecatedString m_original_color_scheme;
     VT::CursorShape m_original_cursor_shape;
     VT::CursorShape m_original_cursor_shape;

+ 1 - 1
Userland/Applications/ThemeEditor/PreviewWidget.cpp

@@ -39,7 +39,7 @@ public:
         return gallery;
         return gallery;
     }
     }
 
 
-    void set_preview_palette(Gfx::Palette const& palette)
+    void set_preview_palette(Gfx::Palette& palette)
     {
     {
         set_palette(palette);
         set_palette(palette);
         Function<void(GUI::Widget&)> recurse = [&](GUI::Widget& parent_widget) {
         Function<void(GUI::Widget&)> recurse = [&](GUI::Widget& parent_widget) {

+ 1 - 2
Userland/Applications/VideoPlayer/VideoFrameWidget.h

@@ -26,7 +26,6 @@ public:
     virtual ~VideoFrameWidget() override = default;
     virtual ~VideoFrameWidget() override = default;
 
 
     void set_bitmap(Gfx::Bitmap const*);
     void set_bitmap(Gfx::Bitmap const*);
-    Gfx::Bitmap* bitmap() { return m_bitmap.ptr(); }
     Gfx::Bitmap const* bitmap() const { return m_bitmap.ptr(); }
     Gfx::Bitmap const* bitmap() const { return m_bitmap.ptr(); }
 
 
     void set_sizing_mode(VideoSizingMode value) { m_sizing_mode = value; }
     void set_sizing_mode(VideoSizingMode value) { m_sizing_mode = value; }
@@ -44,7 +43,7 @@ protected:
     virtual void paint_event(GUI::PaintEvent&) override;
     virtual void paint_event(GUI::PaintEvent&) override;
 
 
 private:
 private:
-    RefPtr<Gfx::Bitmap> m_bitmap;
+    RefPtr<Gfx::Bitmap const> m_bitmap;
     VideoSizingMode m_sizing_mode { VideoSizingMode::Fit };
     VideoSizingMode m_sizing_mode { VideoSizingMode::Fit };
     bool m_auto_resize { false };
     bool m_auto_resize { false };
 };
 };

+ 1 - 1
Userland/Demos/WidgetGallery/GalleryWidget.cpp

@@ -306,7 +306,7 @@ GalleryWidget::GalleryWidget()
 
 
     m_cursors_tableview->on_activation = [&](const GUI::ModelIndex& index) {
     m_cursors_tableview->on_activation = [&](const GUI::ModelIndex& index) {
         auto icon_index = index.model()->index(index.row(), MouseCursorModel::Column::Bitmap);
         auto icon_index = index.model()->index(index.row(), MouseCursorModel::Column::Bitmap);
-        m_cursors_tableview->set_override_cursor(NonnullRefPtr<Gfx::Bitmap>(icon_index.data().as_bitmap()));
+        m_cursors_tableview->set_override_cursor(NonnullRefPtr<Gfx::Bitmap const>(icon_index.data().as_bitmap()));
     };
     };
 
 
     auto icons_tab = tab_widget.try_add_tab<GUI::Widget>("Icons").release_value_but_fixme_should_propagate_errors();
     auto icons_tab = tab_widget.try_add_tab<GUI::Widget>("Icons").release_value_but_fixme_should_propagate_errors();

+ 2 - 1
Userland/DevTools/HackStudio/EditorWrapper.cpp

@@ -50,7 +50,8 @@ void EditorWrapper::set_mode_displayable()
 {
 {
     editor().set_mode(GUI::TextEditor::Editable);
     editor().set_mode(GUI::TextEditor::Editable);
     editor().set_background_role(Gfx::ColorRole::Base);
     editor().set_background_role(Gfx::ColorRole::Base);
-    editor().set_palette(GUI::Application::the()->palette());
+    auto palette = GUI::Application::the()->palette();
+    editor().set_palette(palette);
 }
 }
 
 
 void EditorWrapper::set_mode_non_displayable()
 void EditorWrapper::set_mode_non_displayable()

+ 2 - 2
Userland/DevTools/HackStudio/HackStudioWidget.cpp

@@ -1837,7 +1837,7 @@ void HackStudioWidget::update_history_actions()
         m_locations_history_forward_action->set_enabled(true);
         m_locations_history_forward_action->set_enabled(true);
 }
 }
 
 
-RefPtr<Gfx::Font> HackStudioWidget::read_editor_font_from_config()
+RefPtr<Gfx::Font const> HackStudioWidget::read_editor_font_from_config()
 {
 {
     auto font_family = Config::read_string("HackStudio"sv, "EditorFont"sv, "Family"sv, "Csilla"sv);
     auto font_family = Config::read_string("HackStudio"sv, "EditorFont"sv, "Family"sv, "Csilla"sv);
     auto font_variant = Config::read_string("HackStudio"sv, "EditorFont"sv, "Variant"sv, "Regular"sv);
     auto font_variant = Config::read_string("HackStudio"sv, "EditorFont"sv, "Variant"sv, "Regular"sv);
@@ -1850,7 +1850,7 @@ RefPtr<Gfx::Font> HackStudioWidget::read_editor_font_from_config()
     return font;
     return font;
 }
 }
 
 
-void HackStudioWidget::change_editor_font(RefPtr<Gfx::Font> font)
+void HackStudioWidget::change_editor_font(RefPtr<Gfx::Font const> font)
 {
 {
     m_editor_font = move(font);
     m_editor_font = move(font);
     for (auto& editor_wrapper : m_all_editor_wrappers) {
     for (auto& editor_wrapper : m_all_editor_wrappers) {

+ 3 - 3
Userland/DevTools/HackStudio/HackStudioWidget.h

@@ -248,9 +248,9 @@ private:
     RefPtr<GUI::Action> m_toggle_semantic_highlighting_action;
     RefPtr<GUI::Action> m_toggle_semantic_highlighting_action;
     RefPtr<GUI::Action> m_open_project_configuration_action;
     RefPtr<GUI::Action> m_open_project_configuration_action;
 
 
-    RefPtr<Gfx::Font> read_editor_font_from_config();
-    void change_editor_font(RefPtr<Gfx::Font>);
-    RefPtr<Gfx::Font> m_editor_font;
+    RefPtr<Gfx::Font const> read_editor_font_from_config();
+    void change_editor_font(RefPtr<Gfx::Font const>);
+    RefPtr<Gfx::Font const> m_editor_font;
     RefPtr<GUI::Action> m_editor_font_action;
     RefPtr<GUI::Action> m_editor_font_action;
 
 
     GUI::TextEditor::WrappingMode m_wrapping_mode { GUI::TextEditor::NoWrap };
     GUI::TextEditor::WrappingMode m_wrapping_mode { GUI::TextEditor::NoWrap };

+ 1 - 1
Userland/DevTools/Profiler/TimelineHeader.h

@@ -32,7 +32,7 @@ private:
 
 
     Profile& m_profile;
     Profile& m_profile;
     Process const& m_process;
     Process const& m_process;
-    RefPtr<Gfx::Bitmap> m_icon;
+    RefPtr<Gfx::Bitmap const> m_icon;
     DeprecatedString m_text;
     DeprecatedString m_text;
     bool m_selected;
     bool m_selected;
 };
 };

+ 1 - 1
Userland/Games/Chess/ChessWidget.cpp

@@ -421,7 +421,7 @@ Chess::Square ChessWidget::mouse_to_square(GUI::MouseEvent& event) const
     }
     }
 }
 }
 
 
-RefPtr<Gfx::Bitmap> ChessWidget::get_piece_graphic(Chess::Piece const& piece) const
+RefPtr<Gfx::Bitmap const> ChessWidget::get_piece_graphic(Chess::Piece const& piece) const
 {
 {
     return m_pieces.get(piece).value();
     return m_pieces.get(piece).value();
 }
 }

+ 2 - 2
Userland/Games/Chess/ChessWidget.h

@@ -48,7 +48,7 @@ public:
 
 
     bool drag_enabled() const { return m_drag_enabled; }
     bool drag_enabled() const { return m_drag_enabled; }
     void set_drag_enabled(bool e) { m_drag_enabled = e; }
     void set_drag_enabled(bool e) { m_drag_enabled = e; }
-    RefPtr<Gfx::Bitmap> get_piece_graphic(Chess::Piece const& piece) const;
+    RefPtr<Gfx::Bitmap const> get_piece_graphic(Chess::Piece const& piece) const;
 
 
     bool show_available_moves() const { return m_show_available_moves; }
     bool show_available_moves() const { return m_show_available_moves; }
     void set_show_available_moves(bool e) { m_show_available_moves = e; }
     void set_show_available_moves(bool e) { m_show_available_moves = e; }
@@ -128,7 +128,7 @@ private:
     Color m_marking_alternate_color { Color::from_argb(0x66ffaa00) };
     Color m_marking_alternate_color { Color::from_argb(0x66ffaa00) };
     Color m_marking_secondary_color { Color::from_argb(0x6655dd55) };
     Color m_marking_secondary_color { Color::from_argb(0x6655dd55) };
     Chess::Color m_side { Chess::Color::White };
     Chess::Color m_side { Chess::Color::White };
-    HashMap<Chess::Piece, RefPtr<Gfx::Bitmap>> m_pieces;
+    HashMap<Chess::Piece, RefPtr<Gfx::Bitmap const>> m_pieces;
     DeprecatedString m_piece_set;
     DeprecatedString m_piece_set;
     Chess::Square m_moving_square { 50, 50 };
     Chess::Square m_moving_square { 50, 50 };
     Gfx::IntPoint m_drag_point;
     Gfx::IntPoint m_drag_point;

+ 1 - 1
Userland/Games/ColorLines/ColorLines.cpp

@@ -40,7 +40,7 @@ ColorLines::BitmapArray ColorLines::build_marble_color_bitmaps()
 ColorLines::BitmapArray ColorLines::build_marble_trace_bitmaps()
 ColorLines::BitmapArray ColorLines::build_marble_trace_bitmaps()
 {
 {
     // Use "Paw Prints" Unicode Character (U+1F43E)
     // Use "Paw Prints" Unicode Character (U+1F43E)
-    auto trace_bitmap = NonnullRefPtr<Gfx::Bitmap>(*Gfx::Emoji::emoji_for_code_point(0x1F43E));
+    auto trace_bitmap = NonnullRefPtr<Gfx::Bitmap const>(*Gfx::Emoji::emoji_for_code_point(0x1F43E));
     BitmapArray result;
     BitmapArray result;
     result.ensure_capacity(number_of_marble_trace_bitmaps);
     result.ensure_capacity(number_of_marble_trace_bitmaps);
     result.append(trace_bitmap);
     result.append(trace_bitmap);

+ 1 - 1
Userland/Games/ColorLines/ColorLines.h

@@ -47,7 +47,7 @@ private:
     void restart_timer(int milliseconds);
     void restart_timer(int milliseconds);
 
 
     using Point = Gfx::IntPoint;
     using Point = Gfx::IntPoint;
-    using BitmapArray = Vector<NonnullRefPtr<Gfx::Bitmap>>;
+    using BitmapArray = Vector<NonnullRefPtr<Gfx::Bitmap const>>;
 
 
     StringView const m_app_name;
     StringView const m_app_name;
     GameState m_game_state { GameState::Idle };
     GameState m_game_state { GameState::Idle };

+ 1 - 1
Userland/Games/Hearts/Player.cpp

@@ -162,7 +162,7 @@ void Player::remove_cards(NonnullRefPtrVector<Card> const& cards)
 {
 {
     for (auto& card : cards) {
     for (auto& card : cards) {
         hand.remove_first_matching([&card](auto& other_card) {
         hand.remove_first_matching([&card](auto& other_card) {
-            return other_card == card;
+            return other_card.ptr() == &card;
         });
         });
     }
     }
 }
 }