[gtkmm/numericsorter] Add Gtk::NumericSorter
- From: Andreas Persson <andreasp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm/numericsorter] Add Gtk::NumericSorter
- Date: Sun, 4 Oct 2020 17:02:26 +0000 (UTC)
commit 81acea9226139d962ac7c44ab2b2fc1bab7df66a
Author: Andreas Persson <andreasp56 outlook com>
Date: Sun Oct 4 19:01:08 2020 +0200
Add Gtk::NumericSorter
Add binding for gtk_numeric_sorter. It is implemented as a template,
with the numeric type as a parameter, and a base class.
.gitignore | 2 +
gtk/gtkmm.h | 1 +
gtk/gtkmm/meson.build | 1 +
gtk/src/filelist.am | 1 +
gtk/src/gtk_signals.defs | 21 ++++
gtk/src/numericsorter.ccg | 17 ++++
gtk/src/numericsorter.hg | 157 ++++++++++++++++++++++++++++++
tools/extra_defs_gen/generate_defs_gtk.cc | 1 +
8 files changed, 201 insertions(+)
---
diff --git a/.gitignore b/.gitignore
index 0a309972..9ed4a33e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -433,6 +433,8 @@ gtk/gtkmm/notebook.cc
gtk/gtkmm/notebook.h
gtk/gtkmm/notebookpage.cc
gtk/gtkmm/notebookpage.h
+gtk/gtkmm/numericsorter.cc
+gtk/gtkmm/numericsorter.h
gtk/gtkmm/orientable.cc
gtk/gtkmm/orientable.h
gtk/gtkmm/overlay.cc
diff --git a/gtk/gtkmm.h b/gtk/gtkmm.h
index b26cb06e..9504f6fd 100644
--- a/gtk/gtkmm.h
+++ b/gtk/gtkmm.h
@@ -210,6 +210,7 @@ extern const int gtkmm_micro_version;
#include <gtkmm/multisorter.h>
#include <gtkmm/noselection.h>
#include <gtkmm/notebook.h>
+#include <gtkmm/numericsorter.h>
#include <gtkmm/object.h>
#include <gtkmm/overlay.h>
#include <gtkmm/padcontroller.h>
diff --git a/gtk/gtkmm/meson.build b/gtk/gtkmm/meson.build
index 169eebd8..bd3740de 100644
--- a/gtk/gtkmm/meson.build
+++ b/gtk/gtkmm/meson.build
@@ -172,6 +172,7 @@ gtkmm_any_hg_ccg_basenames = [
'noselection',
'notebook',
'notebookpage',
+ 'numericsorter',
'orientable',
'overlay',
'padactionentry',
diff --git a/gtk/src/filelist.am b/gtk/src/filelist.am
index e15d6763..49e8f7d1 100644
--- a/gtk/src/filelist.am
+++ b/gtk/src/filelist.am
@@ -157,6 +157,7 @@ gtkmm_files_any_hg = \
noselection.hg \
notebook.hg \
notebookpage.hg \
+ numericsorter.hg \
orientable.hg \
overlay.hg \
padactionentry.hg \
diff --git a/gtk/src/gtk_signals.defs b/gtk/src/gtk_signals.defs
index 007a03c8..4f7ff4e3 100644
--- a/gtk/src/gtk_signals.defs
+++ b/gtk/src/gtk_signals.defs
@@ -7410,6 +7410,27 @@
(construct-only #t)
)
+;; From GtkNumericSorter
+
+(define-property expression
+ (of-object "GtkNumericSorter")
+ (prop-type "GtkParamSpecExpression")
+ (docs "Expression to compare with")
+ (readable #t)
+ (writable #t)
+ (construct-only #f)
+)
+
+(define-property sort-order
+ (of-object "GtkNumericSorter")
+ (prop-type "GParamEnum")
+ (docs "Whether to sort smaller numbers first")
+ (readable #t)
+ (writable #t)
+ (construct-only #f)
+ (default-value "GTK_SORT_ASCENDING")
+)
+
;; From GtkOrientable
(define-property orientation
diff --git a/gtk/src/numericsorter.ccg b/gtk/src/numericsorter.ccg
new file mode 100644
index 00000000..57b87fdc
--- /dev/null
+++ b/gtk/src/numericsorter.ccg
@@ -0,0 +1,17 @@
+/* Copyright (C) 2020 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtk/gtk.h>
diff --git a/gtk/src/numericsorter.hg b/gtk/src/numericsorter.hg
new file mode 100644
index 00000000..b9ab39f0
--- /dev/null
+++ b/gtk/src/numericsorter.hg
@@ -0,0 +1,157 @@
+/* Copyright (C) 2020 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtkmm/sorter.h>
+#include <gtkmm/expression.h>
+
+_DEFS(gtkmm,gtk)
+_PINCLUDE(gtkmm/private/sorter_p.h)
+
+namespace Gtk
+{
+
+/** Base class for Gtk::NumericSorter.
+ *
+ * @see Gtk::NumericSorter
+ *
+ * @newin{3,98}
+ */
+class GTKMM_API NumericSorterBase : public Sorter
+{
+ _CLASS_GOBJECT(NumericSorterBase, GtkNumericSorter, GTK_NUMERIC_SORTER, Gtk::Sorter, GtkSorter, , ,
GTKMM_API)
+ _STRUCT_NOT_HIDDEN
+
+protected:
+#m4 _CONVERSION(`const Glib::RefPtr<ExpressionBase>&',`GtkExpression*',`(($3) ? ($3)->gobj() : nullptr)')
+ _WRAP_CTOR(NumericSorterBase(const Glib::RefPtr<ExpressionBase>& expression), gtk_numeric_sorter_new)
+
+public:
+ _IGNORE(gtk_numeric_sorter_get_expression, gtk_numeric_sorter_set_expression)
+
+ _WRAP_METHOD(SortType get_sort_order() const, gtk_numeric_sorter_get_sort_order)
+ _WRAP_METHOD(void set_sort_order(SortType sort_order), gtk_numeric_sorter_set_sort_order)
+
+ _IGNORE_PROPERTY(expression)
+ _WRAP_PROPERTY("sort-order", SortType)
+};
+
+/** Sort by comparing numbers.
+ *
+ * %Gtk::NumericSorter is a Gtk::Sorter that compares numbers.
+ *
+ * To obtain the numbers to compare, this sorter evaluates a Gtk::Expression.
+ *
+ * @see Gtk::Expression
+ * @newin{3,98}
+ */
+template<class T>
+class NumericSorter : public NumericSorterBase
+{
+ static_assert(std::is_arithmetic<T>::value);
+
+protected:
+ NumericSorter(const Glib::RefPtr<Expression<T>>& expression);
+
+public:
+ static Glib::RefPtr<NumericSorter> create(const Glib::RefPtr<Expression<T>>& expression);
+
+ /** Gets the expression that is evaluated to obtain numbers from items.
+ *
+ * @return A Gtk::Expression, or <tt>nullptr</tt>.
+ */
+ Glib::RefPtr<Expression<T>> get_expression();
+ /** @copydoc get_expression()
+ */
+ Glib::RefPtr<const Expression<T>> get_expression() const;
+
+ /** Sets the expression that is evaluated to obtain numbers from items.
+ *
+ * Unless an expression is set on the %Gtk::NumericSorter, the
+ * sorter will always compare items as invalid.
+ *
+ * The expression must have a return type that can be compared
+ * numerically, such as int or double.
+ *
+ * @param expression A Gtk::Expression, or <tt>nullptr</tt>.
+ */
+ void set_expression(const Glib::RefPtr<Expression<T>>& expression);
+
+ /** The expression to evalute on items to get a number to compare with
+ *
+ * @return A PropertyProxy that allows you to get or set the value of the property,
+ * or receive notification when the value of the property changes.
+ */
+ Glib::PropertyProxy<Glib::RefPtr<Expression<T>>> property_expression();
+
+ /** The expression to evalute on items to get a number to compare with
+ *
+ * @return A PropertyProxy_ReadOnly that allows you to get the value of the property,
+ * or receive notification when the value of the property changes.
+ */
+ Glib::PropertyProxy_ReadOnly<Glib::RefPtr<Expression<T>>> property_expression() const;
+};
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+
+template<class T>
+NumericSorter<T>::NumericSorter(const Glib::RefPtr<Expression<T>>& expression)
+:
+ NumericSorterBase(expression)
+{
+}
+
+template<class T>
+Glib::RefPtr<NumericSorter<T>> NumericSorter<T>::create(
+ const Glib::RefPtr<Expression<T>>& expression)
+{
+ return Glib::make_refptr_for_instance<NumericSorter>(new NumericSorter(expression));
+}
+
+template<class T>
+void NumericSorter<T>::set_expression(const Glib::RefPtr<Expression<T>>& expression)
+{
+ gtk_numeric_sorter_set_expression(gobj(), const_cast<GtkExpression*>(expression->gobj()));
+}
+
+template<class T>
+Glib::RefPtr<Expression<T>> NumericSorter<T>::get_expression()
+{
+ return Glib::wrap<T>(gtk_numeric_sorter_get_expression(gobj()), true);
+}
+
+template<class T>
+Glib::RefPtr<const Expression<T>> NumericSorter<T>::get_expression() const
+{
+ return Glib::wrap<T>(gtk_numeric_sorter_get_expression(const_cast<GtkNumericSorter*>(gobj())),
+ true);
+}
+
+template<class T>
+Glib::PropertyProxy<Glib::RefPtr<Expression<T>>> NumericSorter<T>::property_expression()
+{
+ return Glib::PropertyProxy<Glib::RefPtr<Expression<T>>>(this, "expression");
+}
+
+template<class T>
+Glib::PropertyProxy_ReadOnly<Glib::RefPtr<Expression<T>>>
+NumericSorter<T>::property_expression() const
+{
+ return Glib::PropertyProxy_ReadOnly<Glib::RefPtr<Expression<T>>>(this, "expression");
+}
+
+#endif
+
+} // namespace Gtk
diff --git a/tools/extra_defs_gen/generate_defs_gtk.cc b/tools/extra_defs_gen/generate_defs_gtk.cc
index 24e24c98..a6bc300a 100644
--- a/tools/extra_defs_gen/generate_defs_gtk.cc
+++ b/tools/extra_defs_gen/generate_defs_gtk.cc
@@ -171,6 +171,7 @@ int main(int /* argc */, char** /* argv */)
<< get_defs( GTK_TYPE_NO_SELECTION )
<< get_defs( GTK_TYPE_NOTEBOOK )
<< get_defs( GTK_TYPE_NOTEBOOK_PAGE )
+ << get_defs( GTK_TYPE_NUMERIC_SORTER )
<< get_defs( GTK_TYPE_ORIENTABLE )
<< get_defs( GTK_TYPE_OVERLAY )
<< get_defs( GTK_TYPE_OVERLAY_LAYOUT )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]