From 31673b7e0777eafcfa80d92e3adbdf5404571167 Mon Sep 17 00:00:00 2001 From: wereturtle Date: Sat, 20 Nov 2021 16:01:01 -0800 Subject: [PATCH] Word count bug fix + changelog updates. --- CHANGELOG.md | 7 +++++-- src/documentmanager.cpp | 11 ++++------- src/documentstatistics.cpp | 16 +++++++++++++++- src/markdowndocument.cpp | 8 +++++++- src/markdowndocument.h | 12 +++++++++++- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5bafbdd8..19412eaeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [2.1.0] - 2021-11-20 + +#### Added * Untitled documents are now autosaved to a draft folder when autosave is enabled. * Added preferences button to open the draft folder location where untitled documents are autosaved. -* Added check box option to load last opened file on startup. If left unchecked, a new file will be opened on startup. +* Added check box option to load last opened file on startup. If left unchecked, a new file will be opened on startup +* Added ability to word count indicator in status bar to display a different statistic. (The indicator is now a combo box.) * Updated Brazilian Portuguese translation. ## [2.0.2] - 2021-06-27 diff --git a/src/documentmanager.cpp b/src/documentmanager.cpp index 5ea7a2060..0c93298f7 100644 --- a/src/documentmanager.cpp +++ b/src/documentmanager.cpp @@ -1,4 +1,4 @@ -/*********************************************************************** +/*********************************************************************** * * Copyright (C) 2014-2021 wereturtle * @@ -549,10 +549,9 @@ bool DocumentManager::close() cursor.setPosition(0); d->editor->setTextCursor(cursor); - d->document->blockSignals(true); - d->document->setPlainText(""); - d->document->blockSignals(false); + d->document->clear(); d->document->clearUndoRedoStacks(); + d->editor->setReadOnly(false); d->document->setReadOnly(false); d->setFilePath(QString()); @@ -729,9 +728,7 @@ bool DocumentManagerPrivate::loadFile(const QString &filePath) document->clearUndoRedoStacks(); document->setUndoRedoEnabled(false); - document->blockSignals(true); - document->setPlainText(""); - document->blockSignals(false); + document->clear(); QApplication::setOverrideCursor(Qt::WaitCursor); emit q->operationStarted(QObject::tr("opening %1").arg(filePath)); diff --git a/src/documentstatistics.cpp b/src/documentstatistics.cpp index 95aac2b40..7fd929b49 100644 --- a/src/documentstatistics.cpp +++ b/src/documentstatistics.cpp @@ -1,6 +1,6 @@ /*********************************************************************** * - * Copyright (C) 2016-2020 wereturtle + * Copyright (C) 2016-2021 wereturtle * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -87,14 +87,28 @@ DocumentStatistics::DocumentStatistics(MarkdownDocument *document, QObject *pare d->document = document; d->wordCount = 0; + d->totalWordCount = 0; d->wordCharacterCount = 0; d->sentenceCount = 0; d->paragraphCount = 0; d->pageCount = 0; d->lixLongWordCount = 0; + d->readTimeMinutes = 0; connect(d->document, SIGNAL(contentsChange(int, int, int)), this, SLOT(onTextChanged(int, int, int))); connect(d->document, SIGNAL(textBlockRemoved(const QTextBlock &)), this, SLOT(onTextBlockRemoved(const QTextBlock &))); + connect(d->document, + &MarkdownDocument::cleared, + [d]() { + d->wordCount = 0; + d->wordCharacterCount = 0; + d->sentenceCount = 0; + d->paragraphCount = 0; + d->pageCount = 0; + d->lixLongWordCount = 0; + d->readTimeMinutes = 0; + d->updateStatistics(); + }); } DocumentStatistics::~DocumentStatistics() diff --git a/src/markdowndocument.cpp b/src/markdowndocument.cpp index 1517b7e07..b19efdb4b 100644 --- a/src/markdowndocument.cpp +++ b/src/markdowndocument.cpp @@ -1,4 +1,4 @@ -/*********************************************************************** +/*********************************************************************** * * Copyright (C) 2014-2021 wereturtle * @@ -167,6 +167,12 @@ void MarkdownDocument::notifyTextBlockRemoved(const QTextBlock &block) emit textBlockRemoved(block); } +void MarkdownDocument::clear() +{ + QTextDocument::clear(); + emit cleared(); +} + void MarkdownDocumentPrivate::initializeUntitledDocument() { Q_Q(MarkdownDocument); diff --git a/src/markdowndocument.h b/src/markdowndocument.h index ca3eb4220..7fa8c7a9e 100644 --- a/src/markdowndocument.h +++ b/src/markdowndocument.h @@ -1,4 +1,4 @@ -/*********************************************************************** +/*********************************************************************** * * Copyright (C) 2014-2021 wereturtle * @@ -109,6 +109,11 @@ class MarkdownDocument : public QTextDocument */ void notifyTextBlockRemoved(const QTextBlock &block); + /** + * Overrides base class clear() method to send cleared() signal. + */ + void clear(); + signals: /** * Emitted when the file path changes. @@ -127,6 +132,11 @@ class MarkdownDocument : public QTextDocument */ void textBlockRemoved(const QTextBlock &block); + /** + * Emitted when the contents of the document is cleared. + */ + void cleared(); + private: QScopedPointer d_ptr; };