Sfoglia il codice sorgente

LibGUI: Add ComboBox::selected_index()

This returns the currently selected index. It was a bit strange that
we had set_selected_index() but not a way to read it back. :^)
Andreas Kling 5 anni fa
parent
commit
8055813ecf
2 ha cambiato i file con 6 aggiunte e 0 eliminazioni
  1. 5 0
      Libraries/LibGUI/ComboBox.cpp
  2. 1 0
      Libraries/LibGUI/ComboBox.h

+ 5 - 0
Libraries/LibGUI/ComboBox.cpp

@@ -163,6 +163,11 @@ void ComboBox::set_selected_index(size_t index)
         this->m_list_view->selection().set(model_index);
 }
 
+size_t ComboBox::selected_index() const
+{
+    return m_list_view->selection().first().row();
+}
+
 void ComboBox::select_all()
 {
     m_editor->select_all();

+ 1 - 0
Libraries/LibGUI/ComboBox.h

@@ -49,6 +49,7 @@ public:
     const Model* model() const;
     void set_model(NonnullRefPtr<Model>);
 
+    size_t selected_index() const;
     void set_selected_index(size_t index);
 
     bool only_allow_values_from_model() const { return m_only_allow_values_from_model; }