Skip to content

Commit

Permalink
Word count bug fix + changelog updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
wereturtle committed Nov 21, 2021
1 parent fe28881 commit 31673b7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions src/documentmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/***********************************************************************
/***********************************************************************
*
* Copyright (C) 2014-2021 wereturtle
*
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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));
Expand Down
16 changes: 15 additions & 1 deletion src/documentstatistics.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion src/markdowndocument.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/***********************************************************************
/***********************************************************************
*
* Copyright (C) 2014-2021 wereturtle
*
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion src/markdowndocument.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/***********************************************************************
/***********************************************************************
*
* Copyright (C) 2014-2021 wereturtle
*
Expand Down Expand Up @@ -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.
Expand All @@ -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<MarkdownDocumentPrivate> d_ptr;
};
Expand Down

0 comments on commit 31673b7

Please sign in to comment.