summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-10-23 21:59:55 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2024-10-24 09:09:26 +0200
commitc8ff967c4996318d25bcc0642b14cbc5e6d981bb (patch)
tree3f2426a51fe483ba357a2679607f4fb9211b967a /vcl
parentf0a90a0d3f9c0a200603ee69a42fddf461068a22 (diff)
tdf#130857 qt weld: Implement combobox entry sorting
Implement sorting for combobox entries by adding a QtInstanceComboBox::m_bSorted member that gets set to true when QtInstanceComboBox::make_sorted gets called, and sort entries then and whenever a new entry gets inserted afterwards. This is in preparation for upcoming Change-Id: I7806688102f690faa02fb5e712943d6ae216ff9a Author: Michael Weghorn <m.weghorn@posteo.de> tdf#130857 qt weld: Declare support for "Printer Settings" dialog Change-Id: I54140db4310c7b288fe3be0e73000860410068fb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175520 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/qt5/QtInstanceComboBox.hxx4
-rw-r--r--vcl/qt5/QtInstanceComboBox.cxx16
2 files changed, 18 insertions, 2 deletions
diff --git a/vcl/inc/qt5/QtInstanceComboBox.hxx b/vcl/inc/qt5/QtInstanceComboBox.hxx
index cc5bd2523eb3..53d81bc9aadc 100644
--- a/vcl/inc/qt5/QtInstanceComboBox.hxx
+++ b/vcl/inc/qt5/QtInstanceComboBox.hxx
@@ -16,6 +16,7 @@
class QtInstanceComboBox : public QtInstanceWidget, public virtual weld::ComboBox
{
QComboBox* m_pComboBox;
+ bool m_bSorted;
public:
QtInstanceComboBox(QComboBox* pComboBox);
@@ -79,6 +80,9 @@ public:
virtual void set_mru_entries(const OUString& rEntries) override;
virtual void set_max_drop_down_rows(int nRows) override;
+
+private:
+ void sortItems();
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtInstanceComboBox.cxx b/vcl/qt5/QtInstanceComboBox.cxx
index 1b12610aead0..e2284b33ef4a 100644
--- a/vcl/qt5/QtInstanceComboBox.cxx
+++ b/vcl/qt5/QtInstanceComboBox.cxx
@@ -12,6 +12,7 @@
QtInstanceComboBox::QtInstanceComboBox(QComboBox* pComboBox)
: QtInstanceWidget(pComboBox)
, m_pComboBox(pComboBox)
+ , m_bSorted(false)
{
assert(pComboBox);
}
@@ -23,7 +24,11 @@ void QtInstanceComboBox::insert(int nPos, const OUString& rStr, const OUString*
assert(false && "Handling for these not implemented yet");
SolarMutexGuard g;
- GetQtInstance().RunInMainThread([&] { m_pComboBox->insertItem(nPos, toQString(rStr)); });
+ GetQtInstance().RunInMainThread([&] {
+ m_pComboBox->insertItem(nPos, toQString(rStr));
+ if (m_bSorted)
+ sortItems();
+ });
}
void QtInstanceComboBox::insert_vector(const std::vector<weld::ComboBoxEntry>&, bool)
@@ -44,7 +49,12 @@ int QtInstanceComboBox::get_count() const
return nCount;
}
-void QtInstanceComboBox::make_sorted() { assert(false && "Not implemented yet"); }
+void QtInstanceComboBox::make_sorted()
+{
+ SolarMutexGuard g;
+ m_bSorted = true;
+ GetQtInstance().RunInMainThread([&] { sortItems(); });
+}
void QtInstanceComboBox::clear()
{
@@ -237,4 +247,6 @@ void QtInstanceComboBox::set_mru_entries(const OUString&)
void QtInstanceComboBox::set_max_drop_down_rows(int) { assert(false && "Not implemented yet"); }
+void QtInstanceComboBox::sortItems() { m_pComboBox->model()->sort(0, Qt::AscendingOrder); }
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */