+void GuiView::showStats()
+{
+ if (!statsEnabled())
+ return;
+
+ d.time_to_update -= d.timer_rate;
+
+ BufferView * bv = currentBufferView();
+ Buffer * buf = bv ? &bv->buffer() : nullptr;
+ if (!buf) {
+ stat_counts_->hide();
+ return;
+ }
+
+ Cursor const & cur = bv->cursor();
+
+ // we start new selection and need faster update
+ if (!d.already_in_selection_ && cur.selection())
+ d.time_to_update = 0;
+
+ if (d.time_to_update > 0)
+ return;
+
+ DocIterator from, to;
+ if (cur.selection()) {
+ from = cur.selectionBegin();
+ to = cur.selectionEnd();
+ d.already_in_selection_ = true;
+ } else {
+ from = doc_iterator_begin(buf);
+ to = doc_iterator_end(buf);
+ d.already_in_selection_ = false;
+ }
+
+ buf->updateStatistics(from, to);
+
+ QStringList stats;
+ if (word_count_enabled_) {
+ int const words = buf->wordCount();
+ if (words == 1)
+ stats << toqstr(bformat(_("%1$d Word"), words));
+ else
+ stats << toqstr(bformat(_("%1$d Words"), words));
+ }
+ int const chars_with_blanks = buf->charCount(true);
+ if (char_count_enabled_) {
+ if (chars_with_blanks == 1)
+ stats << toqstr(bformat(_("%1$d Character"), chars_with_blanks));
+ else
+ stats << toqstr(bformat(_("%1$d Characters"), chars_with_blanks));
+ }
+ if (char_nb_count_enabled_) {
+ int const chars = buf->charCount(false);
+ if (chars == 1)
+ stats << toqstr(bformat(_("%1$d Character (no Blanks)"), chars));
+ else
+ stats << toqstr(bformat(_("%1$d Characters (no Blanks)"), chars));
+ }
+ stat_counts_->setText(stats.join(qt_(", [[stats separator]]")));
+ stat_counts_->show();
+
+ d.time_to_update = d.default_stats_rate;
+ // fast updates for small selections
+ if (chars_with_blanks < d.max_sel_chars && cur.selection())
+ d.time_to_update = d.timer_rate;
+}
+