#include <boost/mpl/find.hpp>
#include <boost/mpl/pop_front.hpp>
#include <boost/foreach.hpp>
-#include <boost/integer_traits.hpp>
+#include <boost/function.hpp>
namespace dialektos {
} // namespace model_column
-namespace {
-struct CompareNumber {
- bool operator()(const ModelColumns& lhs, const ModelColumns& rhs) const {
- int left_num = model_column::field<model_column::Number>(lhs);
- int right_num = model_column::field<model_column::Number>(rhs);
-
- if (left_num == 0) left_num = boost::integer_traits<int>::const_max;
- if (right_num == 0) right_num = boost::integer_traits<int>::const_max;
-
- return left_num < right_num;
- }
-};
-}
-
Glib::RefPtr<ThreadListModel> ThreadListModel::create() {
return Glib::RefPtr<ThreadListModel>(new ThreadListModel());
ThreadListModel::ThreadListModel():
Glib::ObjectBase(typeid(ThreadListModel)),
Glib::Object(),
- list_(), order_() {
+ list_(), order_(), sort_function_(Compare<model_column::Number>()) {
}
ThreadListModel::~ThreadListModel() {}
append(cols);
}
- OrderType old_order = order_;
-
- std::sort(list_.begin(), list_.end(), CompareNumber());
+ sort();
+}
- for (size_t i = 0; i != list_.size(); i++) {
- const model_column::ID::type& id =
- model_column::field<model_column::ID>(list_[i]);
- order_[id] = i;
- }
+void ThreadListModel::sort() {
+ std::sort(list_.begin(), list_.end(), sort_function_);
+ do_after_sort();
+}
+void ThreadListModel::do_after_sort() {
+ // for informing to the tree view.
std::vector<int> new_order;
new_order.reserve(order_.size());
- BOOST_FOREACH(const ModelColumns& record, list_) {
+ // set new order.
+ for (size_t i = 0; i != list_.size(); i++) {
const model_column::ID::type& id =
- model_column::field<model_column::ID>(record);
- new_order.push_back(old_order[id]);
+ model_column::field<model_column::ID>(list_[i]);
+ new_order.push_back(order_[id]);
+ order_[id] = i;
}
+ // inform new order to the tree view.
if (!new_order.empty())
rows_reordered(Gtk::TreeModel::Path(), &(new_order[0]));
}