Back to index

easystroke  0.5.5.1
Classes | Public Member Functions | Private Member Functions | Private Attributes
Stats Class Reference

#include <win.h>

Collaboration diagram for Stats:
Collaboration graph
[legend]

List of all members.

Classes

class  ModelColumns

Public Member Functions

 Stats ()
bool on_stroke (boost::shared_ptr< Ranking >)

Private Member Functions

void on_pdf ()
void on_cursor_changed ()

Private Attributes

ModelColumns cols
Gtk::TreeView * recent_view
Glib::RefPtr< Gtk::ListStore > recent_store
Gtk::TreeView * ranking_view

Detailed Description

Definition at line 80 of file win.h.


Constructor & Destructor Documentation

Definition at line 23 of file stats.cc.

             {
       Gtk::Button *button_matrix;
       widgets->get_widget("button_matrix", button_matrix);
       widgets->get_widget("treeview_recent", recent_view);
       widgets->get_widget("treeview_ranking", ranking_view);

       button_matrix->signal_clicked().connect(sigc::mem_fun(*this, &Stats::on_pdf));

       recent_store = Gtk::ListStore::create(cols);
       recent_view->set_model(recent_store);
       recent_view->append_column(_("Stroke"), cols.stroke);
       recent_view->append_column(_("Name"), cols.name);
       recent_view->append_column(_("Score"), cols.score);
       recent_view->signal_cursor_changed().connect(sigc::mem_fun(*this, &Stats::on_cursor_changed));

       ranking_view->set_model(Gtk::ListStore::create(cols));
       ranking_view->append_column(_("Stroke"), cols.stroke);
       if (verbosity >= 4)
              ranking_view->append_column("Debug", cols.debug);
       ranking_view->append_column(_("Name"), cols.name);
       ranking_view->append_column(_("Score"), cols.score);
}

Here is the call graph for this function:


Member Function Documentation

void Stats::on_cursor_changed ( ) [private]

Definition at line 46 of file stats.cc.

                              {
       Gtk::TreePath path;
       Gtk::TreeViewColumn *col;
       recent_view->get_cursor(path, col);
       Gtk::TreeRow row(*recent_store->get_iter(path));

       Glib::RefPtr<Gtk::ListStore> ranking_store = row[cols.child];
       ranking_view->set_model(ranking_store);
}

Here is the caller graph for this function:

void Stats::on_pdf ( ) [private]

Definition at line 210 of file stats.cc.

                   {
       struct timeval tv1, tv2;
       if (verbosity >= 1)
              gettimeofday(&tv1, 0);
       const int S = 32;
       const int B = 1;
       std::list<RStroke> strokes;
       actions.get_root()->all_strokes(strokes);
       const int n = strokes.size();
       Cairo::RefPtr<Cairo::PdfSurface> surface = Cairo::PdfSurface::create("/tmp/strokes.pdf", (n+1)*S, (n+1)*S);
       const Cairo::RefPtr<Cairo::Context> ctx = Cairo::Context::create(surface);
       int k = 1;
       for (std::list<RStroke>::iterator i = strokes.begin(); i != strokes.end(); i++, k++) {
              (*i)->draw(surface, k*S+B, B, S-2*B, S-2*B);
              (*i)->draw(surface, B, k*S+B, S-2*B, S-2*B);

              ctx->set_source_rgba(0,0,0,1);
              ctx->set_line_width(1);
              ctx->move_to(k*S, B);
              ctx->line_to(k*S, (n+1)*S-B);
              ctx->move_to(B, k*S);
              ctx->line_to((n+1)*S-B, k*S);
              ctx->stroke();

              int l = 1;
              for (std::list<RStroke>::iterator j = strokes.begin(); j != strokes.end(); j++, l++) {
                     double score;
                      int match = Stroke::compare(*i, *j, score);
                     if (match < 0)
                            continue;
                     if (match) {
                            ctx->save();
                            ctx->set_source_rgba(0,0,1,score-0.6);
                            ctx->rectangle(l*S, k*S, S, S);
                            ctx->fill();
                            ctx->restore();
                     }
                     Glib::ustring str = format_float(score);
                     Cairo::TextExtents te;
                     ctx->get_text_extents(str, te);
                     ctx->move_to(l*S+S/2 - te.x_bearing - te.width/2, k*S+S/2 - te.y_bearing - te.height/2);
                     ctx->show_text(str);
              }
       }
       if (verbosity >= 1) {
              gettimeofday(&tv2, 0);
              printf("creating table took %ld us\n", (tv2.tv_sec - tv1.tv_sec)*1000000 + tv2.tv_usec - tv1.tv_usec);
       }
       if (!fork()) {
              execlp("xdg-open", "xdg-open", "/tmp/strokes.pdf", NULL);
              exit(EXIT_FAILURE);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool Stats::on_stroke ( boost::shared_ptr< Ranking r)

Definition at line 180 of file stats.cc.

                                {
       Gtk::TreeModel::Row row = *(recent_store->prepend());
       row[cols.stroke] = r->stroke->draw(STROKE_SIZE);
       row[cols.name] = r->name;
       row[cols.score] = format_float(r->score*100) + "%";
       Glib::RefPtr<Gtk::ListStore> ranking_store = Gtk::ListStore::create(cols);
       row[cols.child] = ranking_store;

       Gtk::TreePath path = recent_store->get_path(row);
       recent_view->scroll_to_row(path);

       Gtk::TreeModel::Children ch = recent_store->children();
       if (ch.size() > 8) {
              Gtk::TreeIter last = ch.end();
              last--;
              recent_store->erase(last);

       }

       for (std::multimap<double, std::pair<std::string, RStroke> >::iterator i = r->r.begin(); i != r->r.end(); i++) {
              Gtk::TreeModel::Row row2 = *(ranking_store->prepend());
              row2[cols.stroke] = i->second.second->draw(STROKE_SIZE);
              if (verbosity >= 4)
                     row2[cols.debug] = Stroke::drawDebug(r->stroke, i->second.second, STROKE_SIZE);
              row2[cols.name] = i->second.first;
              row2[cols.score] = format_float(i->first * 100) + "%";
       }
       return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 98 of file win.h.

Gtk::TreeView* Stats::ranking_view [private]

Definition at line 103 of file win.h.

Glib::RefPtr<Gtk::ListStore> Stats::recent_store [private]

Definition at line 101 of file win.h.

Gtk::TreeView* Stats::recent_view [private]

Definition at line 100 of file win.h.


The documentation for this class was generated from the following files: