creativity  v1.3.0
Agent-based model of creativity and piracy
LibraryStore.hpp
1 #pragma once
2 #include "creativity/gui/BookStore.hpp"
3 #include "creativity/state/BookState.hpp"
4 #include <eris/types.hpp>
5 #include <glibmm/object.h>
6 #include <glibmm/refptr.h>
7 #include <gtkmm/enums.h>
8 #include <gtkmm/treemodel.h>
9 #include <gtkmm/treemodelcolumn.h>
10 #include <memory>
11 
12 namespace Glib { class ValueBase; }
13 namespace Gtk { class TreeView; }
14 namespace creativity { namespace state { class State; } }
15 
16 namespace creativity { namespace gui {
17 
25 class LibraryStore : public BookStore, public virtual Glib::Object {
26  public:
28  static Glib::RefPtr<LibraryStore> create(std::shared_ptr<const state::State> state, eris::eris_id_t reader);
29 
31  class ColRec : public BookStore::ColRec {
32  public:
33  Gtk::TreeModelColumn<double> reader_quality;
34 
35  Gtk::TreeModelColumn<bool>
36  reader_pirated,
37  reader_purchased_market,
39 
40  Gtk::TreeModelColumn<unsigned int>
42 
43  protected:
44  ColRec() : BookStore::ColRec() {
45  add(reader_quality);
46  add(reader_pirated);
47  add(reader_purchased_market);
48  add(reader_purchased_public);
49  add(reader_acquired);
50  }
51  friend class LibraryStore;
52  };
53 
55  virtual void appendColumnsTo(Gtk::TreeView &v) const override;
56 
57  protected:
59  LibraryStore(std::shared_ptr<const state::State> &&state, eris::eris_id_t reader);
60 
68  virtual void get_value_vfunc(const iterator &iter, int column, Glib::ValueBase &value) const override;
69 
70  // TreeSortable overrides:
71 
83  virtual void set_sort_column_id_vfunc(int sort_column_id, Gtk::SortType order) override;
84 
85  private:
86  // The reader whose library this Store represents
87  const eris::eris_id_t reader_;
88 
89  // The various comparison functions; one of these gets passed to std::stable_sort.
90 #define LESS_GREATER_METHODS(col) \
91  bool less_##col(const state::BookState &a, const state::BookState &b); \
92  bool greater_##col(const state::BookState &a, const state::BookState &b);
93  LESS_GREATER_METHODS(reader_quality)
94  LESS_GREATER_METHODS(reader_purchased_market)
95  LESS_GREATER_METHODS(reader_purchased_public)
96  LESS_GREATER_METHODS(reader_pirated)
97  LESS_GREATER_METHODS(reader_acquired)
98 #undef LESS_GREATER_METHODS
99 };
100 
101 }}
Gtk::TreeModel::ColumnRecord subclass for handling Book information in the list of books in the main ...
Definition: BookStore.hpp:24
Definition: BookStore.hpp:14
Primary namespace for all Creativity library code.
Definition: config.hpp:4
Gtk::TreeModelColumn< unsigned int > reader_acquired
Simulation period when this copy of the book was acquired.
Definition: LibraryStore.hpp:41
Definition: BookInfoWindow.hpp:6
Gtk::TreeModelColumn< double > reader_quality
This reader&#39;s quality draw for the book.
Definition: LibraryStore.hpp:33
BookStore::ColRec extension to add reader-specific fields.
Definition: LibraryStore.hpp:31
Gtk::TreeModelColumn< bool > reader_purchased_public
True if the book was purchased from the public provider.
Definition: LibraryStore.hpp:36
Class extending BookStore that lists a reader&#39;s library books (excluding self-written works); it incl...
Definition: LibraryStore.hpp:25
ColumnRecord object for a BookStore.
Definition: BookStore.hpp:65