From 200989e46141db7326e8fecaff1b7cc22a8f0d28 Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Mon, 13 Jul 2020 18:33:08 +0200 Subject: [PATCH 01/15] Named magic const --- edbee-lib/edbee/models/textautocompleteprovider.cpp | 10 +++++++--- edbee-lib/edbee/models/textautocompleteprovider.h | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/edbee-lib/edbee/models/textautocompleteprovider.cpp b/edbee-lib/edbee/models/textautocompleteprovider.cpp index d7d08e3..46ba0e8 100644 --- a/edbee-lib/edbee/models/textautocompleteprovider.cpp +++ b/edbee-lib/edbee/models/textautocompleteprovider.cpp @@ -8,6 +8,10 @@ namespace edbee { +// We don't have lang-server support, but for future support, the constants of langserver are used +const int LANG_COMPLETION_ITEM_KIND_KEYWORD = 14; + +/// @param kind the kind of autocomplete items (Use a Langserver constant) TextAutoCompleteItem::TextAutoCompleteItem(const QString &label, const int kind, const QString &detail, const QString &documentation) : label_(label), kind_(kind), @@ -55,7 +59,7 @@ int TextAutoCompleteItem::matchLabelScore(TextDocument*, const TextRange&, const /// We probably need to calculate a score if( word.length() < 3 ) return 0; - if( label_ == word ) { + if( label_ == word ) { return 1; } else if ( label_.toLower().startsWith(word.toLower()) ) { return 2; @@ -84,10 +88,10 @@ QList StringTextAutoCompleteProvider::findAutoCompleteIt foreach( TextAutoCompleteItem* item, itemList_ ) { int match = item->matchLabelScore(document,range,word); - if( match && match == 1 && item->kind() == 14 ) { + if( match && match == 1 && item->kind() == LANG_COMPLETION_ITEM_KIND_KEYWORD ) { items.clear(); return items.values(); - } else if( match && item->kind() != 14 ) { + } else if( match && item->kind() != LANG_COMPLETION_ITEM_KIND_KEYWORD ) { items.insert(match, item); } } diff --git a/edbee-lib/edbee/models/textautocompleteprovider.h b/edbee-lib/edbee/models/textautocompleteprovider.h index 4816331..eb55143 100644 --- a/edbee-lib/edbee/models/textautocompleteprovider.h +++ b/edbee-lib/edbee/models/textautocompleteprovider.h @@ -19,7 +19,7 @@ class TextRange; /// It's placed in a seperate class for future extentions (LSP: https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#textDocument_completion) class EDBEE_EXPORT TextAutoCompleteItem { public: - TextAutoCompleteItem( const QString& label, const int kind, const QString& detail, const QString& documentation ); + TextAutoCompleteItem( const QString& label, const int kind = 0, const QString& detail = "", const QString& documentation = ""); QString label() const; int kind() const; QString detail() const; @@ -50,7 +50,7 @@ class EDBEE_EXPORT StringTextAutoCompleteProvider : public TextAutoCompleteProvi virtual ~StringTextAutoCompleteProvider(); virtual QList findAutoCompleteItemsForRange( TextDocument* document, const TextRange& range, const QString& word ) ; - virtual void add(const QString& label, const int kind, const QString& detail = "", const QString& documentation = ""); + virtual void add(const QString& label, const int kind = 0, const QString& detail = "", const QString& documentation = ""); virtual void give(TextAutoCompleteItem* item); protected: QList itemList_; From 1b4f0f6d9f8b14326e7e5cd83b8031fbac7d0fe5 Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Tue, 14 Jul 2020 10:12:59 +0200 Subject: [PATCH 02/15] Memory leak fix, hide hint if not used. Added langserver constants --- .../edbee/models/textautocompleteprovider.cpp | 12 +++---- .../edbee/models/textautocompleteprovider.h | 34 +++++++++++++++++++ edbee-lib/edbee/models/texteditorconfig.cpp | 12 +++++++ edbee-lib/edbee/models/texteditorconfig.h | 4 +++ .../texteditorautocompletecomponent.cpp | 23 ++++++++----- 5 files changed, 70 insertions(+), 15 deletions(-) diff --git a/edbee-lib/edbee/models/textautocompleteprovider.cpp b/edbee-lib/edbee/models/textautocompleteprovider.cpp index 46ba0e8..96b7981 100644 --- a/edbee-lib/edbee/models/textautocompleteprovider.cpp +++ b/edbee-lib/edbee/models/textautocompleteprovider.cpp @@ -1,5 +1,6 @@ #include "textautocompleteprovider.h" +#include "edbee/models/texteditorconfig.h" #include "edbee/models/textdocument.h" #include "edbee/models/textdocumentscopes.h" #include "edbee/models/textgrammar.h" @@ -8,9 +9,6 @@ namespace edbee { -// We don't have lang-server support, but for future support, the constants of langserver are used -const int LANG_COMPLETION_ITEM_KIND_KEYWORD = 14; - /// @param kind the kind of autocomplete items (Use a Langserver constant) TextAutoCompleteItem::TextAutoCompleteItem(const QString &label, const int kind, const QString &detail, const QString &documentation) : label_(label), @@ -50,14 +48,14 @@ QString TextAutoCompleteItem::documentation() const to Unicode using the fromUtf8() function. \sa fromLatin1(), fromLocal8Bit(), fromUtf8(), QByteArray::fromStdString() */ -int TextAutoCompleteItem::matchLabelScore(TextDocument*, const TextRange&, const QString &word) +int TextAutoCompleteItem::matchLabelScore(TextDocument* doc, const TextRange&, const QString &word) { /// For now a simple prefix-prefix search. Later fuzzy search. /// Inspiration: /// - https://www.quora.com/How-is-the-fuzzy-search-algorithm-in-Sublime-Text-designed-How-would-you-design-something-similar) /// - https://github.com/renstrom/fuzzysearch /// We probably need to calculate a score - if( word.length() < 3 ) + if( word.length() < doc->config()->autocompleteMinimalCharacters()) return 0; if( label_ == word ) { return 1; @@ -88,10 +86,10 @@ QList StringTextAutoCompleteProvider::findAutoCompleteIt foreach( TextAutoCompleteItem* item, itemList_ ) { int match = item->matchLabelScore(document,range,word); - if( match && match == 1 && item->kind() == LANG_COMPLETION_ITEM_KIND_KEYWORD ) { + if( match && match == 1 && item->kind() == edbee::TextAutoCompleteKind::Keyword ) { items.clear(); return items.values(); - } else if( match && item->kind() != LANG_COMPLETION_ITEM_KIND_KEYWORD ) { + } else if( match && item->kind() != edbee::TextAutoCompleteKind::Keyword ) { items.insert(match, item); } } diff --git a/edbee-lib/edbee/models/textautocompleteprovider.h b/edbee-lib/edbee/models/textautocompleteprovider.h index eb55143..34d66b6 100644 --- a/edbee-lib/edbee/models/textautocompleteprovider.h +++ b/edbee-lib/edbee/models/textautocompleteprovider.h @@ -14,6 +14,40 @@ namespace edbee { class TextDocument; class TextRange; + +// We don't have lang-server support, but for future support, the constants of langserver are used +// https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_completion +namespace TextAutoCompleteKind { + enum TextAutoCompleteKindEnum { + Text = 1, + Method = 2, + Function = 3, + Constructor = 4, + Field = 5, + Variable = 6, + Class = 7, + Interface = 8, + Module = 9, + Property = 10, + Unit = 11, + Value = 12, + Enum = 13, + Keyword = 14, + Snippet = 15, + Color = 16, + File = 17, + Reference = 18, + Folder = 19, + EnumMember = 20, + Constant = 21, + Struct = 22, + Event = 23, + Operator = 24, + TypeParameter = 25 + }; +} + + /// An autocomplete item that's being returned /// Currently simply a string. /// It's placed in a seperate class for future extentions (LSP: https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#textDocument_completion) diff --git a/edbee-lib/edbee/models/texteditorconfig.cpp b/edbee-lib/edbee/models/texteditorconfig.cpp index 40c164c..48c2cdf 100644 --- a/edbee-lib/edbee/models/texteditorconfig.cpp +++ b/edbee-lib/edbee/models/texteditorconfig.cpp @@ -33,6 +33,8 @@ TextEditorConfig::TextEditorConfig( QObject* parent ) , themeName_("Monokai") , scrollPastEnd_(false) , showWhitespaceMode_(HideWhitespaces) + , autocompleteAutoShow_(true) + , autocompleteMinimalCharacters_(0) { charGroups_.append( QStringLiteral("./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}`~?")); } @@ -415,6 +417,16 @@ void TextEditorConfig::setAutocompleteAutoShow(bool enable) } } +int TextEditorConfig::autocompleteMinimalCharacters() const +{ + return autocompleteMinimalCharacters_; +} + +void TextEditorConfig::setAutocompleteMinimalCharacters(int amount) +{ + autocompleteMinimalCharacters_ = amount; +} + /// Show autocomplete automatically, or only manually(manual isn't implemented yet) bool TextEditorConfig::autocompleteAutoShow() const { diff --git a/edbee-lib/edbee/models/texteditorconfig.h b/edbee-lib/edbee/models/texteditorconfig.h index 51763ad..7693437 100644 --- a/edbee-lib/edbee/models/texteditorconfig.h +++ b/edbee-lib/edbee/models/texteditorconfig.h @@ -92,6 +92,9 @@ Q_OBJECT bool autocompleteAutoShow() const; void setAutocompleteAutoShow( bool enable ); + int autocompleteMinimalCharacters() const; + void setAutocompleteMinimalCharacters( int amount ); + signals: void configChanged(); @@ -125,6 +128,7 @@ Q_OBJECT int showWhitespaceMode_; ///< The current whitespace mode to make bool autocompleteAutoShow_; ///< Show autocomplete automatically, or only when manually triggered + int autocompleteMinimalCharacters_; ///< How manu characters need to be entered before autocomplete kicks in }; } // edbee diff --git a/edbee-lib/edbee/views/components/texteditorautocompletecomponent.cpp b/edbee-lib/edbee/views/components/texteditorautocompletecomponent.cpp index 45eac45..a92d0e9 100644 --- a/edbee-lib/edbee/views/components/texteditorautocompletecomponent.cpp +++ b/edbee-lib/edbee/views/components/texteditorautocompletecomponent.cpp @@ -41,7 +41,7 @@ TextEditorAutoCompleteComponent::TextEditorAutoCompleteComponent(TextEditorContr layout->setSpacing(0); layout->setMargin(0); - menuRef_ = new QMenu(); + menuRef_ = new QMenu(this); listWidgetRef_ = new QListWidget(menuRef_); listWidgetRef_->installEventFilter(this); menuRef_->installEventFilter(this); @@ -130,7 +130,7 @@ void TextEditorAutoCompleteComponent::showInfoTip() QString infoTip = current.data(Qt::UserRole).toString(); if( infoTip.isEmpty() ) { - infoTip = "No tooltip data found!"; +// infoTip = "No tooltip data found!"; } if( infoTipRef_.isNull() ) { @@ -166,8 +166,12 @@ void TextEditorAutoCompleteComponent::showInfoTip() } } - menuRef_->resize(QSize(maxWidth + 2, ( qMin(listWidgetRef_->count(), 10) * fm.height() ) + 6 )); - listWidgetRef_->resize(QSize(maxWidth + 0, ( qMin(listWidgetRef_->count(), 10) * fm.height() + 4 ))); + int spacing = 0; + menuRef_->resize(QSize(maxWidth + spacing + 2, ( qMin(listWidgetRef_->count(), 10) * fm.height() ) + 6 )); + listWidgetRef_->resize(QSize(maxWidth + spacing, ( qMin(listWidgetRef_->count(), 10) * fm.height() + 4 ))); +// menuRef_->resize(QSize(maxWidth + spacing + 2, ( qMin(listWidgetRef_->count(), 10) * fm.height() ) )); +// listWidgetRef_->resize(QSize(maxWidth + spacing, ( qMin(listWidgetRef_->count(), 10) * fm.height() ))); + QRect r = listWidgetRef_->visualItemRect(listWidgetRef_->currentItem()); int xOffset; @@ -193,10 +197,12 @@ void TextEditorAutoCompleteComponent::showInfoTip() newLoc.setX(menuRef_->x() - infoTipRef_->width() - 1); } - infoTipRef_->repaint(); - infoTipRef_->move(newLoc); - infoTipRef_->show(); - infoTipRef_->raise(); + if(!infoTip.isEmpty()) { + infoTipRef_->repaint(); + infoTipRef_->move(newLoc); + infoTipRef_->show(); + infoTipRef_->raise(); + } } void TextEditorAutoCompleteComponent::hideInfoTip() @@ -327,6 +333,7 @@ bool TextEditorAutoCompleteComponent::eventFilter(QObject *obj, QEvent *event) menuRef_->close(); return true; } + break; case Qt::Key_Backspace: QApplication::sendEvent(editorComponentRef_, event); From 1cb5bc5cdab2ee5217c8373b9289579c5489191b Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Sun, 19 Jul 2020 07:25:00 +0200 Subject: [PATCH 03/15] Compile fix for README example --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a29fb1..9340e14 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,8 @@ Of course it would also be nice to fill the editor with a file. you can use the edbee::TextEditorWidget* widget = new edbee::TextEditorWidget(); edbee::TextDocumentSerializer serializer( widget->textDocument() ); -if( !serializer.load( "your-filename.rb" ) ) { +QFile file( QStringLiteral("your-filename.rb") ); +if( !serializer.load( &file ) ) { QMessageBox::warning(this, tr("Error opening file"), tr("Error opening file!\n%1").arg(serializer.errorString()) ); } From de349a080609f6c1bdbabb52d1abf36e0d5bd922 Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Mon, 20 Jul 2020 08:19:34 +0200 Subject: [PATCH 04/15] fix #101, Support for JSON based grammar files. --- CHANGELOG.md | 1 + edbee-lib/edbee/io/baseplistparser.h | 1 - edbee-lib/edbee/io/tmlanguageparser.cpp | 91 +++++++++++++++++++------ edbee-lib/edbee/io/tmlanguageparser.h | 19 ++++-- edbee-lib/edbee/models/textgrammar.cpp | 14 ++-- 5 files changed, 92 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9741bdf..fe3fa85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ edbee.lib: +- add #101, Support for JSON based grammar files. - fix #67, PlacholderText support via TextEditorWidget::setPlaceholderText. (uses 70% opacity of foreground color) - fix #98, Missing header include in Qt 5.15rc - fix #94 (partial), Resource delete fix in TextDocumentscopes diff --git a/edbee-lib/edbee/io/baseplistparser.h b/edbee-lib/edbee/io/baseplistparser.h index 7599fc0..e1c99d3 100644 --- a/edbee-lib/edbee/io/baseplistparser.h +++ b/edbee-lib/edbee/io/baseplistparser.h @@ -25,7 +25,6 @@ class EDBEE_EXPORT BasePListParser { QString lastErrorMessage() const; -protected: void setLastErrorMessage( const QString& str ); bool beginParsing( QIODevice* device ); diff --git a/edbee-lib/edbee/io/tmlanguageparser.cpp b/edbee-lib/edbee/io/tmlanguageparser.cpp index e95a1e8..a2007f6 100644 --- a/edbee-lib/edbee/io/tmlanguageparser.cpp +++ b/edbee-lib/edbee/io/tmlanguageparser.cpp @@ -6,11 +6,14 @@ #include "tmlanguageparser.h" #include +#include #include #include #include #include +#include "edbee/io/baseplistparser.h" +#include "edbee/io/jsonparser.h" #include "edbee/models/textgrammar.h" #include "edbee/edbee.h" @@ -23,22 +26,33 @@ TmLanguageParser::TmLanguageParser() { } +/// returns the last error message +QString TmLanguageParser::lastErrorMessage() const +{ + return lastErrorMessage_; +} -/// reads the content of a single file -/// @param device the device to read from. The device NEEDS to be open!! -/// @return the language grammar or 0 on error -TextGrammar* TmLanguageParser::parse(QIODevice* device) +/// Sets the last error message +void TmLanguageParser::setLastErrorMessage(const QString &str) { - TextGrammar* result=0; + lastErrorMessage_ = str; +} - if( beginParsing(device) ) { - QVariant plist = readNextPlistType( ); + +/// Parses a PList (XML Grammar file definition) +TextGrammar *TmLanguageParser::parsePlist(QIODevice *device) +{ + TextGrammar* result = nullptr; + + BasePListParser plistParser; + if( plistParser.beginParsing(device) ) { + QVariant plist = plistParser.readNextPlistType( ); result = createLanguage( plist ); } - if( !endParsing() ) { + if( !plistParser.endParsing() ) { delete result; - result = 0; + result = nullptr; } // returns the language @@ -46,20 +60,58 @@ TextGrammar* TmLanguageParser::parse(QIODevice* device) } -/// parses the given grammar file -/// @param file the file to read -/// @return the language grammar or 0 on error -TextGrammar* TmLanguageParser::parse(const QString& fileName) +/// Parses a JSON grammar file definition +TextGrammar *TmLanguageParser::parseJson(QIODevice *device) +{ + TextGrammar* result = nullptr; + + JsonParser jsonParser; + if( jsonParser.parse(device) ) { + //QVariant plist = readNextPlistType( ); + QVariant parseResult = jsonParser.result(); + result = createLanguage( parseResult ); + } + + return result; +} + + +/// reads the content of a single file +/// @param device the device to read from. The device NEEDS to be open!! +/// @param json use the json parser +/// @return the language grammar or nullptr on error +TextGrammar* TmLanguageParser::parse(QIODevice* device, bool json) +{ + if( json ) { + return parseJson(device); + } else { + return parsePlist(device); + } + +} + +/// Parses the given file +TextGrammar *TmLanguageParser::parse(QFile &file) { - QFile file(fileName); if( file.open( QIODevice::ReadOnly ) ) { - TextGrammar* result = parse( &file ); + TextGrammar* result = parse( &file, file.fileName().endsWith(".json")); file.close(); return result; } else { setLastErrorMessage( file.errorString() ); - return 0; + return nullptr; } + +} + + +/// parses the given grammar file +/// @param file the file to read +/// @return the language grammar or 0 on error +TextGrammar* TmLanguageParser::parse(const QString& fileName) +{ + QFile file(fileName); + return parse(file); } @@ -181,12 +233,12 @@ TextGrammar* TmLanguageParser::createLanguage(QVariant& data) QString uuid = hashMap.value("uuid").toString(); if( name.isEmpty() || scopeName.isEmpty() ) { - raiseError("Name or scope is empty. Cannot parse language!"); - return 0; + setLastErrorMessage("Name or scope is empty. Cannot parse language!"); + return nullptr; } // construct the grammar - TextGrammar* grammar = new TextGrammar( scopeName, name ); + TextGrammar* grammar = new TextGrammar(scopeName, name); // and get the main patterns // construct the main rule @@ -216,7 +268,6 @@ TextGrammar* TmLanguageParser::createLanguage(QVariant& data) grammar->addFileExtension( fileType ); } - return grammar; } diff --git a/edbee-lib/edbee/io/tmlanguageparser.h b/edbee-lib/edbee/io/tmlanguageparser.h index d118ddd..4c8480f 100644 --- a/edbee-lib/edbee/io/tmlanguageparser.h +++ b/edbee-lib/edbee/io/tmlanguageparser.h @@ -12,8 +12,6 @@ #include #include -#include "baseplistparser.h" - class QFile; class QIODevice; class QXmlStreamReader; @@ -25,15 +23,21 @@ class TextGrammarManager; class TextGrammarRule; /// For parsing a Textmate Language -class EDBEE_EXPORT TmLanguageParser : public BasePListParser +class EDBEE_EXPORT TmLanguageParser { public: TmLanguageParser(); - TextGrammar* parse( QIODevice* device ); - TextGrammar* parse(const QFile& file ); - TextGrammar* parse( const QString& fileName ); + TextGrammar* parsePlist(QIODevice* device); + TextGrammar* parseJson(QIODevice* device); + + TextGrammar* parse(QIODevice* device, bool json=false); + TextGrammar* parse(QFile& file); + TextGrammar* parse(const QString& fileName); + + QString lastErrorMessage() const; protected: + void setLastErrorMessage( const QString& str ); void addCapturesToGrammarRule( TextGrammarRule* rule, QHash captures, bool endCapture=false ); void addPatternsToGrammarRule( TextGrammarRule* rule, QList patterns ); @@ -41,7 +45,8 @@ class EDBEE_EXPORT TmLanguageParser : public BasePListParser TextGrammarRule* createGrammarRule(TextGrammar *grammar, const QVariant &data ); TextGrammar* createLanguage(QVariant& data ); - +private: + QString lastErrorMessage_; ///< The last error message }; } // edbee diff --git a/edbee-lib/edbee/models/textgrammar.cpp b/edbee-lib/edbee/models/textgrammar.cpp index d8ddf73..6d25d7c 100644 --- a/edbee-lib/edbee/models/textgrammar.cpp +++ b/edbee-lib/edbee/models/textgrammar.cpp @@ -1,5 +1,5 @@ /** - * Copyright 2011-2013 - Reliable Bits Software by Blommers IT. All Rights Reserved. + * Copyright 2011-2020 - Reliable Bits Software by Blommers IT. All Rights Reserved. * Author Rick Blommers */ @@ -8,6 +8,7 @@ #include #include "edbee/io/tmlanguageparser.h" +#include "edbee/io/tmlanguageparserjson.h" #include "edbee/util/regexp.h" #include "edbee/debug.h" @@ -294,12 +295,13 @@ TextGrammarManager::~TextGrammarManager() TextGrammar* TextGrammarManager::readGrammarFile(const QString& file) { lastErrorMessage_.clear(); + TextGrammar* grammar = nullptr; + QString lastErrorMessage; - // read the file TmLanguageParser parser; - TextGrammar* grammar = parser.parse( file ); - if( grammar ) { - giveGrammar( grammar ); + grammar = parser.parse(file); + if(grammar) { + giveGrammar(grammar); } else { QFileInfo fileInfo(file); lastErrorMessage_ = QObject::tr("Error reading file %1:%2").arg(fileInfo.absoluteFilePath()).arg(parser.lastErrorMessage()); @@ -315,7 +317,7 @@ void TextGrammarManager::readAllGrammarFilesInPath(const QString& path ) { // qlog_info() << "readAllGrammarFilesInPath(" << path << ")"; QDir dir(path); - QStringList filters("*.tmLanguage"); + QStringList filters = { "*.tmLanguage", "*.tmLanguage.json" }; foreach( QFileInfo fileInfo, dir.entryInfoList( filters, QDir::Files, QDir::Name ) ) { // qlog_info() << "- parse" << fileInfo.baseName() << "."; readGrammarFile( fileInfo.absoluteFilePath()); From 182d0f1cc69f08f485a7f0cbecc1bac47c7464ad Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Mon, 20 Jul 2020 08:35:45 +0200 Subject: [PATCH 05/15] removed incorrect include file --- edbee-lib/edbee/models/textgrammar.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/edbee-lib/edbee/models/textgrammar.cpp b/edbee-lib/edbee/models/textgrammar.cpp index 6d25d7c..844eacd 100644 --- a/edbee-lib/edbee/models/textgrammar.cpp +++ b/edbee-lib/edbee/models/textgrammar.cpp @@ -8,7 +8,6 @@ #include #include "edbee/io/tmlanguageparser.h" -#include "edbee/io/tmlanguageparserjson.h" #include "edbee/util/regexp.h" #include "edbee/debug.h" @@ -22,7 +21,7 @@ namespace edbee { TextGrammarRule::TextGrammarRule(TextGrammar* grammar, Instruction instruction) : grammarRef_(grammar) , instruction_(instruction) - , matchRegExp_(0) + , matchRegExp_(nullptr) , endRegExpString_() { } From bb579e6c73b1fdd7a048c283b25de2cdef3d3967 Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Mon, 20 Jul 2020 20:46:41 +0200 Subject: [PATCH 06/15] fixes #90, Several Qt deprecation warnings. Changed 0 to nullptr. Possible incompatibility with older releases! --- CHANGELOG.md | 1 + edbee-lib/edbee/commands/movelinecommand.cpp | 2 + edbee-lib/edbee/models/change.cpp | 25 +++++------ edbee-lib/edbee/models/dynamicvariables.cpp | 2 +- edbee-lib/edbee/models/textdocument.cpp | 1 + edbee-lib/edbee/models/texteditorkeymap.cpp | 6 +-- edbee-lib/edbee/models/texteditorkeymap.h | 3 +- edbee-lib/edbee/util/mem/debug_new.cpp | 16 ++++---- edbee-lib/edbee/util/mem/debug_new.h | 2 +- .../texteditorautocompletecomponent.cpp | 8 ++-- .../views/components/texteditorcomponent.cpp | 16 ++++---- .../views/components/textmargincomponent.cpp | 41 ++++++++++--------- edbee-lib/edbee/views/textrenderer.cpp | 41 ++++++++++--------- edbee-lib/edbee/views/texttheme.cpp | 6 +-- edbee-lib/edbee/views/texttheme.h | 4 +- .../models/changes/linedatalistchangetest.cpp | 6 +-- edbee-test/edbee/models/textrangetest.cpp | 2 +- vendor/qslog/QsLogDestFile.cpp | 2 +- 18 files changed, 97 insertions(+), 87 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe3fa85..4d7ba9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ edbee.lib: +- fix #90, Fixed several Qt deprecation warnings. Chagned 0 to nullptr. Possible incompatibility with older releases! - add #101, Support for JSON based grammar files. - fix #67, PlacholderText support via TextEditorWidget::setPlaceholderText. (uses 70% opacity of foreground color) - fix #98, Missing header include in Qt 5.15rc diff --git a/edbee-lib/edbee/commands/movelinecommand.cpp b/edbee-lib/edbee/commands/movelinecommand.cpp index e7dcb4b..bbfce73 100644 --- a/edbee-lib/edbee/commands/movelinecommand.cpp +++ b/edbee-lib/edbee/commands/movelinecommand.cpp @@ -23,6 +23,7 @@ MoveLineCommand::~MoveLineCommand() /// Calculates the new ranges after moving +/* static void calculateNewSelectionRanges( TextDocument* doc, TextRangeSet& newCaretSelection, int direction ) { for( int i=0,cnt=newCaretSelection.rangeCount(); iexecute(document); } @@ -187,7 +187,7 @@ void ChangeGroup::execute(TextDocument* document) /// Reverts the command gorup void ChangeGroup::revert(TextDocument* document) { - Q_UNUSED(document); + Q_UNUSED(document) for( int i=size()-1; i>=0; --i ) { at(i)->revert(document); } @@ -237,6 +237,7 @@ void ChangeGroup::flatten() void ChangeGroup::giveChange(TextDocument *doc, Change *change) { + Q_UNUSED(doc) changeList_.append(change); } @@ -269,7 +270,7 @@ void ChangeGroup::clear(bool performDelete) /// @return the last textchange Change* ChangeGroup::last() { - if( size() == 0 ) { return 0; } + if( size() == 0 ) { return nullptr; } return at(size()-1); } @@ -278,7 +279,7 @@ Change* ChangeGroup::last() /// @return the last textchange Change* ChangeGroup::takeLast() { - if( size() == 0 ) { return 0; } + if( size() == 0 ) { return nullptr; } return take(size()-1); } @@ -304,13 +305,13 @@ int ChangeGroup::recursiveSize() /// Then this context is returned else 0 is returned TextEditorController* ChangeGroup::controllerContext() { - TextEditorController* context = 0; + TextEditorController* context = nullptr; for( int i=size()-1; i>=0; --i ) { TextEditorController* commandContext = at(i)->controllerContext(); // multiple context in 1 group means it's a 'hard' undo - if( commandContext == 0 ) return 0; /// 0 is always 0! - if( commandContext && context && commandContext != context ) { return 0; } + if( commandContext == nullptr ) return nullptr; /// 0 is always 0! + if( commandContext && context && commandContext != context ) { return nullptr; } if( !context && commandContext ) { context = commandContext; } diff --git a/edbee-lib/edbee/models/dynamicvariables.cpp b/edbee-lib/edbee/models/dynamicvariables.cpp index dfa4453..6b9dd78 100644 --- a/edbee-lib/edbee/models/dynamicvariables.cpp +++ b/edbee-lib/edbee/models/dynamicvariables.cpp @@ -96,7 +96,7 @@ void DynamicVariables::setAndGiveScopedSelector(const QString& name, const QVari { /// Todo, perhaps we should detect identical scope selectors and replace the original variableNames_.insert(name); - scopedVariableMap_.insertMulti( name, new ScopedDynamicVariable(value, new TextScopeSelector(selector) ) ); + scopedVariableMap_.insert( name, new ScopedDynamicVariable(value, new TextScopeSelector(selector) ) ); } diff --git a/edbee-lib/edbee/models/textdocument.cpp b/edbee-lib/edbee/models/textdocument.cpp index eebe2ff..daf9716 100644 --- a/edbee-lib/edbee/models/textdocument.cpp +++ b/edbee-lib/edbee/models/textdocument.cpp @@ -299,6 +299,7 @@ Change *TextDocument::executeAndGiveChange(Change* change, int coalesceId ) beginUndoGroup(); // automaticly group changes together (when changes happend on emition) change->execute( this ); Change* result = giveChangeWithoutFilter( change, coalesceId ); + Q_UNUSED(result) endUndoGroup(coalesceId, true); return textUndoStack()->last(); // return result; diff --git a/edbee-lib/edbee/models/texteditorkeymap.cpp b/edbee-lib/edbee/models/texteditorkeymap.cpp index 8aa729a..17f3005 100644 --- a/edbee-lib/edbee/models/texteditorkeymap.cpp +++ b/edbee-lib/edbee/models/texteditorkeymap.cpp @@ -87,7 +87,7 @@ TextEditorKey* TextEditorKeyMap::get(const QString& name) const QHash::const_iterator itr = keyMap_.find(name); if( itr != keyMap_.end() ) { return itr.value(); } if( parentRef_ ) { return parentRef_->get(name); } - return 0; + return nullptr; } @@ -137,7 +137,7 @@ bool TextEditorKeyMap::has(const QString& name) const /// @param sequence the keysequence void TextEditorKeyMap::add(const QString& command, TextEditorKey* sequence) { - keyMap_.insertMulti(command,sequence); + keyMap_.insert(command,sequence); } @@ -146,7 +146,7 @@ void TextEditorKeyMap::add(const QString& command, TextEditorKey* sequence) /// @param sequence the keysequence void TextEditorKeyMap::add(const QString& command, const QKeySequence& seq) { - keyMap_.insertMulti(command, new TextEditorKey(seq) ); + keyMap_.insert(command, new TextEditorKey(seq) ); } diff --git a/edbee-lib/edbee/models/texteditorkeymap.h b/edbee-lib/edbee/models/texteditorkeymap.h index 147d5d3..951955e 100644 --- a/edbee-lib/edbee/models/texteditorkeymap.h +++ b/edbee-lib/edbee/models/texteditorkeymap.h @@ -9,6 +9,7 @@ #include #include +#include #include namespace edbee { @@ -68,7 +69,7 @@ class EDBEE_EXPORT TextEditorKeyMap { private: TextEditorKeyMap* parentRef_; ///< a reference to a parent keymap - QHash keyMap_; ///< a map to convert a name to a + QMultiHash keyMap_; ///< a map to convert a name to a }; diff --git a/edbee-lib/edbee/util/mem/debug_new.cpp b/edbee-lib/edbee/util/mem/debug_new.cpp index 9ef87f9..b92667e 100644 --- a/edbee-lib/edbee/util/mem/debug_new.cpp +++ b/edbee-lib/edbee/util/mem/debug_new.cpp @@ -30,17 +30,17 @@ void* debug_malloc(size_t size, const char* file, const int line) void* p = ::malloc(size); if( allocList->isRunning() ) { edbee::DebugAllocation* info = allocList->find(p); - if (info != 0) { + if (info != nullptr) { printf("already exist %p %s %d\n", p, file, line); - printf("existing info : %p(%u) %s:%d\n", info->pointer, (unsigned int)info->size, info->file, info->line); + printf("existing info : %p(%u) %s:%d\n", info->pointer, static_cast(info->size), info->file, info->line); ::free(p); - return 0; + return nullptr; } - info = allocList->add(p, size, (char*)file, (int)line); - if (info == 0) { - printf("can not add %p(%u) %s:%d\n", p,(unsigned int)size, file, line); + info = allocList->add(p, size, const_cast(file), static_cast(line)); + if (info == nullptr) { + printf("can not add %p(%u) %s:%d\n", p, static_cast(size), file, line); ::free(p); - return 0; + return nullptr; } } return p; @@ -122,6 +122,8 @@ void pause_memleak_detection(bool value) { #ifdef EDBEE_DEBUG_NEW_ACTIVE DebugAllocationList::instance()->pause(value); +#else + Q_UNUSED(value) #endif } diff --git a/edbee-lib/edbee/util/mem/debug_new.h b/edbee-lib/edbee/util/mem/debug_new.h index 8f4059e..4ebbc17 100644 --- a/edbee-lib/edbee/util/mem/debug_new.h +++ b/edbee-lib/edbee/util/mem/debug_new.h @@ -27,7 +27,7 @@ void operator delete[] (void* p) throw(); #define debug_new new(__FILE__, __LINE__) - #define new debug_new + #define new new(__FILE__, __LINE__) #define malloc(A) debug_malloc((A), __FILE__, __LINE__) #define free(A) debug_free((A), __FILE__, __LINE__) #endif diff --git a/edbee-lib/edbee/views/components/texteditorautocompletecomponent.cpp b/edbee-lib/edbee/views/components/texteditorautocompletecomponent.cpp index a92d0e9..892dd12 100644 --- a/edbee-lib/edbee/views/components/texteditorautocompletecomponent.cpp +++ b/edbee-lib/edbee/views/components/texteditorautocompletecomponent.cpp @@ -158,10 +158,10 @@ void TextEditorAutoCompleteComponent::showInfoTip() } if( sDetail.contains(" = ") ){ sType = QString("%1").arg(sDetail.split(" = ").value(0)); - int width = fm.width(QString("%1 %2").arg(sLabel).arg(sType)) + widthMod; + int width = fm.horizontalAdvance(QString("%1 %2").arg(sLabel).arg(sType)) + widthMod; maxWidth = qMax(width, maxWidth); } else { - int width = fm.width(QString("%1").arg(sLabel)) + widthMod; + int width = fm.horizontalAdvance(QString("%1").arg(sLabel)) + widthMod; maxWidth = qMax(width, maxWidth); } } @@ -474,8 +474,8 @@ void AutoCompleteDelegate::paint(QPainter *painter, const QStyleOptionViewItem & QPen typePen = QPen(themeRef_->findHighlightForegroundColor()); QPen namePen = QPen(themeRef_->foregroundColor()); - hyphenRect.setX(hyphenRect.x() + fm.width(sLabel)); - typeRect.setX(nameRect.x() + nameRect.width() - fm.width(sType) - 1); + hyphenRect.setX(hyphenRect.x() + fm.horizontalAdvance(sLabel)); + typeRect.setX(nameRect.x() + nameRect.width() - fm.horizontalAdvance(sType) - 1); painter->setFont(font); painter->drawText(nameRect, sLabel); diff --git a/edbee-lib/edbee/views/components/texteditorcomponent.cpp b/edbee-lib/edbee/views/components/texteditorcomponent.cpp index c407627..8986e25 100644 --- a/edbee-lib/edbee/views/components/texteditorcomponent.cpp +++ b/edbee-lib/edbee/views/components/texteditorcomponent.cpp @@ -36,9 +36,9 @@ namespace edbee { /// @param parent the parent QObject TextEditorComponent::TextEditorComponent(TextEditorController* controller, QWidget* parent) : QWidget(parent) - , caretTimer_(0) + , caretTimer_(nullptr) , controllerRef_(controller) - , textEditorRenderer_(0) + , textEditorRenderer_(nullptr) { textEditorRenderer_ = new TextEditorRenderer( controller->textRenderer()); @@ -213,12 +213,12 @@ void TextEditorComponent::paintEvent(QPaintEvent* paintEvent) void TextEditorComponent::moveEvent(QMoveEvent *moveEvent) { - + Q_UNUSED(moveEvent) } void TextEditorComponent::hideEvent(QHideEvent *hideEvent) { - + Q_UNUSED(hideEvent) } @@ -317,7 +317,7 @@ void TextEditorComponent::keyPressEvent(QKeyEvent* event) /// the key release event void TextEditorComponent::keyReleaseEvent(QKeyEvent *event) { - Q_UNUSED(event); + Q_UNUSED(event) } @@ -484,14 +484,14 @@ void TextEditorComponent::mouseMoveEvent(QMouseEvent* event ) /// A focus in event occured void TextEditorComponent::focusInEvent(QFocusEvent *event) { - Q_UNUSED(event); + Q_UNUSED(event) } /// The focus is lost, we must STOP coalescing of undo-events! void TextEditorComponent::focusOutEvent(QFocusEvent *event) { - Q_UNUSED(event); + Q_UNUSED(event) // no merging for new changes!! textDocument()->textUndoStack()->resetAllLastCoalesceIds(); } @@ -501,7 +501,7 @@ void TextEditorComponent::focusOutEvent(QFocusEvent *event) /// Add the default menu actions void TextEditorComponent::contextMenuEvent(QContextMenuEvent* event) { - Q_UNUSED(event); + Q_UNUSED(event) QMenu* menu = new QMenu(); menu->addAction( controller()->createAction("cut", tr("Cut") ) ); diff --git a/edbee-lib/edbee/views/components/textmargincomponent.cpp b/edbee-lib/edbee/views/components/textmargincomponent.cpp index 47b7cd7..6ecfa8a 100644 --- a/edbee-lib/edbee/views/components/textmargincomponent.cpp +++ b/edbee-lib/edbee/views/components/textmargincomponent.cpp @@ -31,7 +31,7 @@ static const int MarginPaddingRight = 5; /// The default constructor TextMarginComponentDelegate::TextMarginComponentDelegate() - : marginComponentRef_(0) + : marginComponentRef_(nullptr) , startLine_(0) { } @@ -52,19 +52,19 @@ int TextMarginComponentDelegate::widthBeforeLineNumber() /// Custom rendering before the line-numbers etc are drawn void TextMarginComponentDelegate::renderBefore(QPainter *painter, int startLine, int endLine, int width) { - Q_UNUSED(painter); - Q_UNUSED(startLine); - Q_UNUSED(endLine); - Q_UNUSED(width); + Q_UNUSED(painter) + Q_UNUSED(startLine) + Q_UNUSED(endLine) + Q_UNUSED(width) } /// The delegate can berform custom rendering on a given line void TextMarginComponentDelegate::renderAfter(QPainter* painter, int startLine, int endLine, int width) { - Q_UNUSED(painter); - Q_UNUSED(startLine); - Q_UNUSED(endLine); - Q_UNUSED(width); + Q_UNUSED(painter) + Q_UNUSED(startLine) + Q_UNUSED(endLine) + Q_UNUSED(width) } /// Make this method return true to enable mouse tracking @@ -77,8 +77,8 @@ bool TextMarginComponentDelegate::requiresMouseTracking() /// To use it you MUST manually call setMouseTracking() on the TextMarginComponent void TextMarginComponentDelegate::mouseMoveEvent(int line, QMouseEvent* event) { - Q_UNUSED(line); - Q_UNUSED(event); + Q_UNUSED(line) + Q_UNUSED(event) if( event->buttons() & Qt::LeftButton ) { if( line >= 0 ) { TextEditorController* controller = marginComponent()->editorWidget()->controller(); @@ -94,7 +94,7 @@ void TextMarginComponentDelegate::mouseMoveEvent(int line, QMouseEvent* event) void TextMarginComponentDelegate::mousePressEvent(int line, QMouseEvent* event) { - Q_UNUSED(event); + Q_UNUSED(event) if( line >= 0 ) { TextEditorController* controller = marginComponent()->editorWidget()->controller(); controller->moveCaretTo(line,0,false); @@ -105,7 +105,7 @@ void TextMarginComponentDelegate::mousePressEvent(int line, QMouseEvent* event) void TextMarginComponentDelegate::leaveEvent(QEvent* event) { - Q_UNUSED(event); + Q_UNUSED(event) } @@ -121,10 +121,10 @@ TextMarginComponent::TextMarginComponent(TextEditorWidget* editor, QWidget* pare , top_(0) , width_(-1) , lastLineCount_(-1) - , marginFont_(0) + , marginFont_(nullptr) , editorRef_( editor ) - , delegate_(0) - , delegateRef_(0) + , delegate_(nullptr) + , delegateRef_(nullptr) { this->setFocusPolicy( Qt::NoFocus ); this->setAutoFillBackground(false); @@ -228,8 +228,8 @@ TextRenderer* TextMarginComponent::renderer() const void TextMarginComponent::setDelegate(TextMarginComponentDelegate* delegate) { delete delegate_; - delegate_ = 0; - if( delegate == 0 ) { delegate = new TextMarginComponentDelegate(); } + delegate_ = nullptr; + if( delegate == nullptr ) { delegate = new TextMarginComponentDelegate(); } delegateRef_ = delegate; // perform some updates @@ -317,7 +317,7 @@ void TextMarginComponent::renderLineNumber(QPainter* painter, int startLine, int painter->setFont(*marginFont_); QColor selectedPenColor = renderer()->theme()->foregroundColor(); QColor penColor( selectedPenColor); - penColor.setAlphaF(0.5f); + penColor.setAlphaF(0.5); int lineHeight = renderer()->lineHeight(); int textWidth = width-LineNumberRightPadding-MarginPaddingRight - delegate()->widthBeforeLineNumber(); @@ -376,7 +376,8 @@ void TextMarginComponent::leaveEvent(QEvent* event) /// forward the mouse wheel event to the scrollbar so you can use the mouse wheel on this component void TextMarginComponent::wheelEvent(QWheelEvent* event) { - if( event->orientation() == Qt::Vertical) { +// if( event->orientation() == Qt::Vertical) { + if( event->angleDelta().y() != 0 ) { QApplication::sendEvent( editorRef_->textScrollArea()->verticalScrollBar(), event ); } } diff --git a/edbee-lib/edbee/views/textrenderer.cpp b/edbee-lib/edbee/views/textrenderer.cpp index 2e8b3ad..cd0307d 100644 --- a/edbee-lib/edbee/views/textrenderer.cpp +++ b/edbee-lib/edbee/views/textrenderer.cpp @@ -33,13 +33,13 @@ namespace edbee { /// The default textrenderer constructor TextRenderer::TextRenderer(TextEditorController* controller) - : QObject( 0 ) + : QObject(nullptr) , controllerRef_(controller) , caretTime_(0) , caretBlinkRate_(0) , totalWidthCache_(0) - , textThemeStyler_(0) - , clipRectRef_(0) + , textThemeStyler_(nullptr) + , clipRectRef_(nullptr) , startOffset_(0) , endOffset_(0) , startLine_(0) @@ -47,7 +47,7 @@ TextRenderer::TextRenderer(TextEditorController* controller) , placeHolderDocument_(0) { connect( controller, SIGNAL(textDocumentChanged(edbee::TextDocument*,edbee::TextDocument*)), this, SLOT(textDocumentChanged(edbee::TextDocument*,edbee::TextDocument*))); - textThemeStyler_ = new TextThemeStyler( controller ); + textThemeStyler_ = new TextThemeStyler(controller); placeHolderDocument_ = new CharTextDocument(); } @@ -148,7 +148,7 @@ int TextRenderer::totalHeight() /// This method returns width of the M cahracter int TextRenderer::emWidth() { - return textWidget()->fontMetrics().width("M"); + return textWidget()->fontMetrics().horizontalAdvance('M'); } @@ -156,7 +156,7 @@ int TextRenderer::emWidth() /// Often the M is to wide. That why we have a nr width which takes the 8 for the width int TextRenderer::nrWidth() { - return textWidget()->fontMetrics().width("8"); + return textWidget()->fontMetrics().horizontalAdvance('8'); } @@ -192,12 +192,12 @@ int TextRenderer::columnIndexForXpos(int line, int x ) int TextRenderer::xPosForColumn(int line, int column) { QTextLayout* layout = textLayoutForLine( line ); - int x = 0;// sideBarLeftWidth(); + qreal x = 0;// sideBarLeftWidth(); if(layout) { QTextLine tl = layout->lineAt(0); - x += tl.cursorToX( column ); + x += tl.cursorToX(column); } - return x; + return round(x); } @@ -248,16 +248,16 @@ QTextLayout *TextRenderer::textLayoutForLineForPlaceholder(int line) /// FIXME: Invalide TextLayout cache when required!!! TextDocument* doc = textDocument(); - if( line >= doc->lineCount() ) return 0; + if( line >= doc->lineCount() ) return nullptr; QTextLayout* textLayout = cachedTextLayoutList_.object(line); if( !textLayout ) { textLayout = new QTextLayout(); textLayout->setCacheEnabled(true); - int tabWidth = controllerRef_->widget()->fontMetrics().charWidth("M",0); + int tabWidth = controllerRef_->widget()->fontMetrics().horizontalAdvance('M'); QTextOption option; - option.setTabStop( config()->indentSize() * tabWidth ); + option.setTabStopDistance(config()->indentSize() * tabWidth); if( config()->showWhitespaceMode() == TextEditorConfig::ShowWhitespaces ) { option.setFlags( QTextOption::ShowTabsAndSpaces ); /// TODO: Make an option to show spaces and tabs } @@ -306,16 +306,16 @@ QTextLayout *TextRenderer::textLayoutForLineNormal(int line) /// FIXME: Invalide TextLayout cache when required!!! TextDocument* doc = textDocument(); - if( line >= doc->lineCount() ) return 0; + if( line >= doc->lineCount() ) return nullptr; QTextLayout* textLayout = cachedTextLayoutList_.object(line); if( !textLayout ) { textLayout = new QTextLayout(); textLayout->setCacheEnabled(true); - int tabWidth = controllerRef_->widget()->fontMetrics().charWidth("M",0); + int tabWidth = controllerRef_->widget()->fontMetrics().horizontalAdvance('M'); QTextOption option; - option.setTabStop( config()->indentSize() * tabWidth ); + option.setTabStopDistance(config()->indentSize() * tabWidth); if( config()->showWhitespaceMode() == TextEditorConfig::ShowWhitespaces ) { option.setFlags( QTextOption::ShowTabsAndSpaces ); /// TODO: Make an option to show spaces and tabs @@ -326,7 +326,8 @@ QTextLayout *TextRenderer::textLayoutForLineNormal(int line) textLayout->setTextOption( option ); // add extra format - textLayout->setAdditionalFormats( themeStyler()->getLineFormatRanges( line )); + + textLayout->setFormats(themeStyler()->getLineFormatRanges(line)); QString text = doc->lineWithoutNewline(line); #ifdef USE_CONTROL_PICTURES for( int i=0; isetText( text ); textLayout->beginLayout(); QTextLine textline = textLayout->createLine(); - Q_UNUSED(textline); + Q_UNUSED(textline) textLayout->endLayout(); // update the width cache @@ -413,7 +414,7 @@ void TextRenderer::renderBegin( const QRect& rect ) /// This method starts rendering void TextRenderer::renderEnd( const QRect& rect ) { - Q_UNUSED(rect); + Q_UNUSED(rect) } @@ -539,7 +540,7 @@ void TextRenderer::textDocumentChanged(edbee::TextDocument *oldDocument, edbee:: { // disconnect an old document (if required) if( oldDocument ) { - disconnect(oldDocument, 0, this, 0 ); + disconnect(oldDocument, nullptr, this, nullptr); } reset(); @@ -576,7 +577,7 @@ void TextRenderer::textChanged(edbee::TextBufferChange change) void TextRenderer::lastScopedOffsetChanged(int previousOffset, int newOffset) { //qlog_info() << "** lastScopedOffsetChanged("<lineFromOffset(previousOffset); invalidateTextLayoutCaches( lastValidLine ); // textWidget()->fullUpdate(); diff --git a/edbee-lib/edbee/views/texttheme.cpp b/edbee-lib/edbee/views/texttheme.cpp index 3caff1b..c1d19d2 100644 --- a/edbee-lib/edbee/views/texttheme.cpp +++ b/edbee-lib/edbee/views/texttheme.cpp @@ -147,12 +147,12 @@ TextThemeStyler::~TextThemeStyler() /// /// @param lineIdx the line index /// @return the array of ranges -QList TextThemeStyler::getLineFormatRanges( int lineIdx ) +QVector TextThemeStyler::getLineFormatRanges( int lineIdx ) { TextDocumentScopes* scopes = controller()->textDocument()->scopes(); // check if the range is in the case. When it is, use it - QList formatRangeList; + QVector formatRangeList; // get all textranges on the given line ScopedTextRangeList* scopedRanges = scopes->scopedRangesAtLine(lineIdx); @@ -278,7 +278,7 @@ QTextCharFormat TextThemeStyler::getTextScopeFormat( QVector& /// helper function to create a format range -void TextThemeStyler::appendFormatRange(QList &rangeList, int start, int end, QVector& activeRanges ) +void TextThemeStyler::appendFormatRange(QVector &rangeList, int start, int end, QVector& activeRanges ) { // only append a format if the lexer style is different then default if( activeRanges.size() > 1 ) { diff --git a/edbee-lib/edbee/views/texttheme.h b/edbee-lib/edbee/views/texttheme.h index 456a1ac..0bca000 100644 --- a/edbee-lib/edbee/views/texttheme.h +++ b/edbee-lib/edbee/views/texttheme.h @@ -163,7 +163,7 @@ Q_OBJECT TextThemeStyler( TextEditorController* controller ); virtual ~TextThemeStyler(); - QList getLineFormatRanges( int lineIdx ); + QVector getLineFormatRanges( int lineIdx ); TextEditorController* controller() { return controllerRef_; } @@ -176,7 +176,7 @@ Q_OBJECT private: QTextCharFormat getTextScopeFormat(QVector &activeRanges); - void appendFormatRange(QList& rangeList, int start, int end, QVector &activeRanges ); + void appendFormatRange(QVector& rangeList, int start, int end, QVector &activeRanges ); private slots: diff --git a/edbee-test/edbee/models/changes/linedatalistchangetest.cpp b/edbee-test/edbee/models/changes/linedatalistchangetest.cpp index 1327300..e64f6e8 100644 --- a/edbee-test/edbee/models/changes/linedatalistchangetest.cpp +++ b/edbee-test/edbee/models/changes/linedatalistchangetest.cpp @@ -18,7 +18,7 @@ static const int TEST_FIELD_INDEX = PredefinedFieldCount; typedef BasicTextLineData TestLineData; LineDataListChangeTest::LineDataListChangeTest() - : doc_(0) + : doc_(nullptr) { } @@ -41,7 +41,7 @@ void LineDataListChangeTest::clean() qDeleteAll(changeList_); changeList_.clear(); delete doc_; - doc_ = 0; + doc_ = nullptr; } @@ -208,7 +208,7 @@ QString LineDataListChangeTest::data2ptr( LineDataListChange* change ) if( list[i] ) { TextLineData* lineData = list[i]->at(manager(),TEST_FIELD_INDEX); if( lineData ) { - result.append( QStringLiteral("").sprintf("%8p", lineData) ); + result.append( QStringLiteral("").asprintf("%8p", static_cast(lineData)) ); } else { result.append("."); } diff --git a/edbee-test/edbee/models/textrangetest.cpp b/edbee-test/edbee/models/textrangetest.cpp index b5e5aab..acd3be3 100644 --- a/edbee-test/edbee/models/textrangetest.cpp +++ b/edbee-test/edbee/models/textrangetest.cpp @@ -32,7 +32,7 @@ do { \ /// @param definition the definition. In the format anchor>caret,anchor>caret static void addRanges( TextRangeSet* sel, const QString& definition ) { - QStringList ranges = definition.split(",", QString::SkipEmptyParts); + QStringList ranges = definition.split(",", Qt::SkipEmptyParts); foreach( QString range, ranges ) { QStringList values = range.split(">"); Q_ASSERT(values.length() == 2); diff --git a/vendor/qslog/QsLogDestFile.cpp b/vendor/qslog/QsLogDestFile.cpp index 3986cd4..ee15c4f 100644 --- a/vendor/qslog/QsLogDestFile.cpp +++ b/vendor/qslog/QsLogDestFile.cpp @@ -170,7 +170,7 @@ void QsLogging::FileDestination::write(const LogMessage& message) mOutputStream.setCodec(QTextCodec::codecForName("UTF-8")); } - mOutputStream << utf8Message << endl; + mOutputStream << utf8Message << Qt::endl; mOutputStream.flush(); } From 8fc006b8c06f0912d31ae600b7473f313b12e7e9 Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Fri, 24 Jul 2020 19:56:00 +0200 Subject: [PATCH 07/15] wip readonly --- edbee-lib/edbee-lib.pri | 2 + edbee-lib/edbee/commands/copycommand.cpp | 5 ++ edbee-lib/edbee/commands/copycommand.h | 5 +- edbee-lib/edbee/commands/debugcommand.cpp | 5 ++ edbee-lib/edbee/commands/debugcommand.h | 5 +- edbee-lib/edbee/commands/findcommand.cpp | 5 ++ edbee-lib/edbee/commands/findcommand.h | 3 +- edbee-lib/edbee/commands/redocommand.cpp | 5 ++ edbee-lib/edbee/commands/redocommand.h | 5 +- edbee-lib/edbee/commands/selectioncommand.cpp | 5 ++ edbee-lib/edbee/commands/selectioncommand.h | 5 +- .../edbee/commands/togglereadonlycommand.cpp | 34 +++++++++++ .../edbee/commands/togglereadonlycommand.h | 25 ++++++++ edbee-lib/edbee/commands/undocommand.cpp | 5 ++ edbee-lib/edbee/commands/undocommand.h | 5 +- edbee-lib/edbee/data/factorycommandmap.cpp | 5 +- edbee-lib/edbee/data/factorykeymap.cpp | 3 + edbee-lib/edbee/models/textdocument.cpp | 10 ++-- edbee-lib/edbee/texteditorcommand.cpp | 5 ++ edbee-lib/edbee/texteditorcommand.h | 3 + edbee-lib/edbee/texteditorcontroller.cpp | 60 +++++++++++++------ edbee-lib/edbee/texteditorcontroller.h | 4 ++ edbee-lib/edbee/texteditorwidget.cpp | 28 ++++++--- edbee-lib/edbee/texteditorwidget.h | 7 ++- 24 files changed, 200 insertions(+), 44 deletions(-) create mode 100644 edbee-lib/edbee/commands/togglereadonlycommand.cpp create mode 100644 edbee-lib/edbee/commands/togglereadonlycommand.h diff --git a/edbee-lib/edbee-lib.pri b/edbee-lib/edbee-lib.pri index a0af35c..42dba2b 100644 --- a/edbee-lib/edbee-lib.pri +++ b/edbee-lib/edbee-lib.pri @@ -17,6 +17,7 @@ SOURCES += \ $$PWD/edbee/commands/replaceselectioncommand.cpp \ $$PWD/edbee/commands/selectioncommand.cpp \ $$PWD/edbee/commands/tabcommand.cpp \ + $$PWD/edbee/commands/togglereadonlycommand.cpp \ $$PWD/edbee/commands/undocommand.cpp \ $$PWD/edbee/data/factorycommandmap.cpp \ $$PWD/edbee/data/factorykeymap.cpp \ @@ -95,6 +96,7 @@ HEADERS += \ $$PWD/edbee/commands/replaceselectioncommand.h \ $$PWD/edbee/commands/selectioncommand.h \ $$PWD/edbee/commands/tabcommand.h \ + $$PWD/edbee/commands/togglereadonlycommand.h \ $$PWD/edbee/commands/undocommand.h \ $$PWD/edbee/data/factorycommandmap.h \ $$PWD/edbee/data/factorykeymap.h \ diff --git a/edbee-lib/edbee/commands/copycommand.cpp b/edbee-lib/edbee/commands/copycommand.cpp index 1d7a098..ac8280f 100644 --- a/edbee-lib/edbee/commands/copycommand.cpp +++ b/edbee-lib/edbee/commands/copycommand.cpp @@ -55,4 +55,9 @@ QString CopyCommand::toString() return "CopyCommand"; } +bool CopyCommand::readonly() +{ + return true; +} + } // edbee diff --git a/edbee-lib/edbee/commands/copycommand.h b/edbee-lib/edbee/commands/copycommand.h index 3830ab1..47860f4 100644 --- a/edbee-lib/edbee/commands/copycommand.h +++ b/edbee-lib/edbee/commands/copycommand.h @@ -23,8 +23,9 @@ class EDBEE_EXPORT CopyCommand : public TextEditorCommand static const QString EDBEE_TEXT_TYPE; public: - virtual void execute( TextEditorController* controller ); - virtual QString toString(); + virtual void execute( TextEditorController* controller ) override; + virtual QString toString() override; + virtual bool readonly() override; }; diff --git a/edbee-lib/edbee/commands/debugcommand.cpp b/edbee-lib/edbee/commands/debugcommand.cpp index a2c60f4..b0162e3 100644 --- a/edbee-lib/edbee/commands/debugcommand.cpp +++ b/edbee-lib/edbee/commands/debugcommand.cpp @@ -39,6 +39,11 @@ QString DebugCommand::toString() return "DebugCommand"; } +bool DebugCommand::readonly() +{ + return true; +} + /// This method dumps the scopes void DebugCommand::dumpScopes( TextEditorController* controller ) { diff --git a/edbee-lib/edbee/commands/debugcommand.h b/edbee-lib/edbee/commands/debugcommand.h index 26d98e2..8fe3296 100644 --- a/edbee-lib/edbee/commands/debugcommand.h +++ b/edbee-lib/edbee/commands/debugcommand.h @@ -26,8 +26,9 @@ class EDBEE_EXPORT DebugCommand : public TextEditorCommand DebugCommand( DebugCommandType command ); - virtual void execute( TextEditorController* controller ); - virtual QString toString(); + virtual void execute(TextEditorController* controller) override; + virtual QString toString() override; + virtual bool readonly() override; protected: diff --git a/edbee-lib/edbee/commands/findcommand.cpp b/edbee-lib/edbee/commands/findcommand.cpp index fb63260..997aaff 100644 --- a/edbee-lib/edbee/commands/findcommand.cpp +++ b/edbee-lib/edbee/commands/findcommand.cpp @@ -114,5 +114,10 @@ QString FindCommand::toString() return QStringLiteral("FindCommand(%1)").arg(str); } +bool FindCommand::readonly() +{ + return true; +} + } // edbee diff --git a/edbee-lib/edbee/commands/findcommand.h b/edbee-lib/edbee/commands/findcommand.h index 3ebe16e..06179ee 100644 --- a/edbee-lib/edbee/commands/findcommand.h +++ b/edbee-lib/edbee/commands/findcommand.h @@ -32,7 +32,8 @@ class EDBEE_EXPORT FindCommand : public TextEditorCommand FindCommand( FindType findType ); virtual void execute( TextEditorController* controller ); - virtual QString toString(); + virtual QString toString() override; + virtual bool readonly() override; private: diff --git a/edbee-lib/edbee/commands/redocommand.cpp b/edbee-lib/edbee/commands/redocommand.cpp index 32ae36b..adfc39f 100644 --- a/edbee-lib/edbee/commands/redocommand.cpp +++ b/edbee-lib/edbee/commands/redocommand.cpp @@ -26,5 +26,10 @@ QString RedoCommand::toString() return QStringLiteral("RedoCommand(%1)").arg( soft_ ? "soft" : "hard" ); } +bool RedoCommand::readonly() +{ + return soft_; +} + } // edbee diff --git a/edbee-lib/edbee/commands/redocommand.h b/edbee-lib/edbee/commands/redocommand.h index 1bf533b..1a5e531 100644 --- a/edbee-lib/edbee/commands/redocommand.h +++ b/edbee-lib/edbee/commands/redocommand.h @@ -20,8 +20,9 @@ class EDBEE_EXPORT RedoCommand : public TextEditorCommand /// This method should return the command identifier virtual int commandId() { return CoalesceId_None; } - virtual void execute( TextEditorController* controller ); - virtual QString toString(); + virtual void execute(TextEditorController* controller) override; + virtual QString toString() override; + virtual bool readonly() override; private: bool soft_; diff --git a/edbee-lib/edbee/commands/selectioncommand.cpp b/edbee-lib/edbee/commands/selectioncommand.cpp index 7c2fd63..f7d5b22 100644 --- a/edbee-lib/edbee/commands/selectioncommand.cpp +++ b/edbee-lib/edbee/commands/selectioncommand.cpp @@ -219,4 +219,9 @@ QString SelectionCommand::toString() return QStringLiteral("SelectionCommand(%1)").arg( unitToString(unit_) ); } +bool SelectionCommand::readonly() +{ + return true; +} + } // edbee diff --git a/edbee-lib/edbee/commands/selectioncommand.h b/edbee-lib/edbee/commands/selectioncommand.h index 098da65..8dda1be 100644 --- a/edbee-lib/edbee/commands/selectioncommand.h +++ b/edbee-lib/edbee/commands/selectioncommand.h @@ -50,8 +50,9 @@ class EDBEE_EXPORT SelectionCommand : public TextEditorCommand virtual int commandId(); - virtual void execute( TextEditorController* controller ); - virtual QString toString(); + virtual void execute( TextEditorController* controller ) override; + virtual QString toString() override; + virtual bool readonly() override; SelectionType unit() { return unit_; } int amount() { return amount_; } diff --git a/edbee-lib/edbee/commands/togglereadonlycommand.cpp b/edbee-lib/edbee/commands/togglereadonlycommand.cpp new file mode 100644 index 0000000..7121fc8 --- /dev/null +++ b/edbee-lib/edbee/commands/togglereadonlycommand.cpp @@ -0,0 +1,34 @@ +#include "togglereadonlycommand.h" + +#include "edbee/texteditorcontroller.h" +#include "edbee/models/changes/mergablechangegroup.h" +#include "edbee/models/texteditorconfig.h" +#include "edbee/models/textdocument.h" +#include "edbee/views/textselection.h" + +#include "edbee/debug.h" + +namespace edbee { + +/// Constructs the toggle readonly command +ToggleReadonlyCommand::ToggleReadonlyCommand() +{ + +} + +void ToggleReadonlyCommand::execute(TextEditorController *controller) +{ + controller->setReadonly(controller->readonly() ? false : true); +} + +QString ToggleReadonlyCommand::toString() +{ + return "ToggleReadOnlyCommand()"; +} + +bool ToggleReadonlyCommand::readonly() +{ + return true; +} + +} // edbee diff --git a/edbee-lib/edbee/commands/togglereadonlycommand.h b/edbee-lib/edbee/commands/togglereadonlycommand.h new file mode 100644 index 0000000..7497a31 --- /dev/null +++ b/edbee-lib/edbee/commands/togglereadonlycommand.h @@ -0,0 +1,25 @@ +/** + * Copyright 2011-2020 - Reliable Bits Software by Blommers IT. All Rights Reserved. + * Author Rick Blommers + */ + +#pragma once +#include "edbee/exports.h" +#include "edbee/texteditorcommand.h" + + +namespace edbee { + +class ToggleReadonlyCommand : public TextEditorCommand +{ +public: + ToggleReadonlyCommand(); + + virtual void execute(TextEditorController* controller) override; + virtual QString toString() override; + virtual bool readonly() override; + +}; + +} // edbee + diff --git a/edbee-lib/edbee/commands/undocommand.cpp b/edbee-lib/edbee/commands/undocommand.cpp index 4533ac5..81fc2c3 100644 --- a/edbee-lib/edbee/commands/undocommand.cpp +++ b/edbee-lib/edbee/commands/undocommand.cpp @@ -26,5 +26,10 @@ QString UndoCommand::toString() return QStringLiteral("UndoCommand(%1)").arg( soft_ ? "soft" : "hard" ); } +bool UndoCommand::readonly() +{ + return soft_; +} + } // edbee diff --git a/edbee-lib/edbee/commands/undocommand.h b/edbee-lib/edbee/commands/undocommand.h index d3726d3..3682a67 100644 --- a/edbee-lib/edbee/commands/undocommand.h +++ b/edbee-lib/edbee/commands/undocommand.h @@ -19,8 +19,9 @@ class EDBEE_EXPORT UndoCommand : public TextEditorCommand virtual int commandId() { return CoalesceId_None; } - virtual void execute( TextEditorController* controller ); - virtual QString toString(); + virtual void execute( TextEditorController* controller ) override; + virtual QString toString() override; + virtual bool readonly() override; private: bool soft_; ///< should this command perform a soft undo? diff --git a/edbee-lib/edbee/data/factorycommandmap.cpp b/edbee-lib/edbee/data/factorycommandmap.cpp index 5e1180e..c2d9024 100644 --- a/edbee-lib/edbee/data/factorycommandmap.cpp +++ b/edbee-lib/edbee/data/factorycommandmap.cpp @@ -1,5 +1,5 @@ /** - * Copyright 2011-2014 - Reliable Bits Software by Blommers IT. All Rights Reserved. + * Copyright 2011-2020 - Reliable Bits Software by Blommers IT. All Rights Reserved. * Author Rick Blommers */ @@ -19,6 +19,7 @@ #include "edbee/commands/replaceselectioncommand.h" #include "edbee/commands/selectioncommand.h" #include "edbee/commands/tabcommand.h" +#include "edbee/commands/togglereadonlycommand.h" #include "edbee/commands/undocommand.h" #include "edbee/models/texteditorcommandmap.h" @@ -130,6 +131,8 @@ void FactoryCommandMap::fill(TextEditorCommandMap* cm) give( "move_lines_up", new MoveLineCommand(-1)); give( "move_lines_down", new MoveLineCommand(1)); + + give( "toggle_readonly", new ToggleReadonlyCommand()); } diff --git a/edbee-lib/edbee/data/factorykeymap.cpp b/edbee-lib/edbee/data/factorykeymap.cpp index e67209f..439ef0c 100644 --- a/edbee-lib/edbee/data/factorykeymap.cpp +++ b/edbee-lib/edbee/data/factorykeymap.cpp @@ -128,6 +128,9 @@ void FactoryKeyMap::fill( TextEditorKeyMap* km ) add( "move_lines_up", "Ctrl+Meta+Up"); add( "move_lines_down", "Ctrl+Meta+Down"); + // toggle readonly + add( "toggle_readonly", "Ctrl+R"); + } diff --git a/edbee-lib/edbee/models/textdocument.cpp b/edbee-lib/edbee/models/textdocument.cpp index daf9716..5dd1749 100644 --- a/edbee-lib/edbee/models/textdocument.cpp +++ b/edbee-lib/edbee/models/textdocument.cpp @@ -26,9 +26,9 @@ namespace edbee { /// Constructs the textdocument TextDocument::TextDocument( QObject* obj ) : QObject(obj) - , documentFilter_(0) - , documentFilterRef_(0) - , textLineDataManager_(0) + , documentFilter_(nullptr) + , documentFilterRef_(nullptr) + , textLineDataManager_(nullptr) { textLineDataManager_ = new TextLineDataManager(); } @@ -44,7 +44,7 @@ TextDocument::~TextDocument() /// This method can be used to change the number of reserved fields by the document /// Increasing the amount will result in a realoc -/// Decreasting the fieldcount reults in the lost of the 'old' fields +/// Decreasting the fieldcount reults in the lost of the 'old' fields /// At least the 'PredefinedFieldCount' amont of fields are required /// This method EMPTIES the undo-stack. So after this call all undo history is gone! void TextDocument::setLineDataFieldsPerLine( int count ) @@ -89,7 +89,7 @@ TextLineData* TextDocument::getLineData(int line, int field) void TextDocument::beginUndoGroup(ChangeGroup* group) { if( !group ) { - group = new ChangeGroup(0); + group = new ChangeGroup(nullptr); } // if( documentFilter() ) { // documentFilter()->filterBeginGroup( this, group ); diff --git a/edbee-lib/edbee/texteditorcommand.cpp b/edbee-lib/edbee/texteditorcommand.cpp index 02fdca4..b7ee1d7 100644 --- a/edbee-lib/edbee/texteditorcommand.cpp +++ b/edbee-lib/edbee/texteditorcommand.cpp @@ -22,5 +22,10 @@ TextEditorCommand::~TextEditorCommand() } +bool TextEditorCommand::readonly() +{ + return false; +} + } // edbee diff --git a/edbee-lib/edbee/texteditorcommand.h b/edbee-lib/edbee/texteditorcommand.h index 4ce8ddf..5f07152 100644 --- a/edbee-lib/edbee/texteditorcommand.h +++ b/edbee-lib/edbee/texteditorcommand.h @@ -59,6 +59,9 @@ class EDBEE_EXPORT TextEditorCommand { /// should return the description of the command virtual QString toString() = 0; + + /// Tis method should return true if it's executable in readonly mode + virtual bool readonly(); }; } // edbee diff --git a/edbee-lib/edbee/texteditorcontroller.cpp b/edbee-lib/edbee/texteditorcontroller.cpp index f80e963..6dcec2f 100644 --- a/edbee-lib/edbee/texteditorcontroller.cpp +++ b/edbee-lib/edbee/texteditorcontroller.cpp @@ -46,18 +46,18 @@ namespace edbee { TextEditorController::TextEditorController( TextEditorWidget* widget, QObject *parent) : QObject(parent) , widgetRef_(widget) - , textDocument_(0) - , textDocumentRef_(0) - , textSelection_(0) - , keyMap_(0) - , keyMapRef_(0) - , commandMap_(0) - , commandMapRef_(0) - , textRenderer_(0) - , textCaretCache_(0) - , textSearcher_(0) + , textDocument_(nullptr) + , textDocumentRef_(nullptr) + , textSelection_(nullptr) + , keyMap_(nullptr) + , keyMapRef_(nullptr) + , commandMap_(nullptr) + , commandMapRef_(nullptr) + , textRenderer_(nullptr) + , textCaretCache_(nullptr) + , textSearcher_(nullptr) , autoScrollToCaret_(AutoScrollAlways) - , borderedTextRanges_(0) + , borderedTextRanges_(nullptr) { // create the keymap @@ -162,7 +162,7 @@ void TextEditorController::setTextDocument(TextDocument* doc) // delete the old stuff delete textDocument_; - textDocument_ = 0; + textDocument_ = nullptr; } } @@ -266,7 +266,7 @@ TextRangeSet *TextEditorController::borderedTextRanges() const void TextEditorController::setKeyMap(TextEditorKeyMap* keyMap) { delete keyMap_; - keyMap_ = 0; + keyMap_ = nullptr; keyMapRef_= keyMap; } @@ -294,7 +294,7 @@ TextEditorKeyMap*TextEditorController::keyMap() const void TextEditorController::setCommandMap(TextEditorCommandMap* commandMap) { delete commandMap_; - commandMap_ = 0; + commandMap_ = nullptr; commandMapRef_ = commandMap; } @@ -365,7 +365,7 @@ DynamicVariables* TextEditorController::dynamicVariables() const /// This slot is placed if a piece of text is replaced void TextEditorController::onTextChanged( edbee::TextBufferChange change ) { - Q_UNUSED(change); + Q_UNUSED(change) /// update the selection // textSelection()->changeSpatial( change.offset(), change.length(), change.newTextLength() ); @@ -382,7 +382,7 @@ void TextEditorController::onTextChanged( edbee::TextBufferChange change ) /// @param oldRangeSet the old range set of the change void TextEditorController::onSelectionChanged(TextRangeSet* oldRangeSet) { - Q_UNUSED(oldRangeSet); + Q_UNUSED(oldRangeSet) /// TODO: improve this: if( widgetRef_) { @@ -518,6 +518,12 @@ void TextEditorController::storeSelection(int coalesceId) /// This method executes the command void TextEditorController::executeCommand( TextEditorCommand* textCommand ) { + // Only readonly commands can be executed in readonly mode + if( readonly() && !textCommand->readonly() ) { + updateStatusText( "Cannot edit a readonly document!" ); + return; + } + emit commandToBeExecuted( textCommand ); textCommand->execute( this ); emit commandExecuted( textCommand ); @@ -552,7 +558,19 @@ bool TextEditorController::executeCommand(const QString& name) // try to retrieve the command TextEditorCommand* command = commandMap()->get(commandName); if( command ) { executeCommand( command ); } - return command != 0; + return command != nullptr; +} + +/// Return the readonly state. +bool TextEditorController::readonly() const +{ + return widget()->readonly(); +} + +/// Sets the readonly state +void TextEditorController::setReadonly(bool value) +{ + widget()->setReadonly(value); } @@ -594,6 +612,8 @@ void TextEditorController::replaceSelection(const QStringList& texts, int coales /// @param coalesceId the identifier for grouping undo operations void TextEditorController::replaceRangeSet(TextRangeSet& rangeSet, const QString& text, int coalesceId) { + if(readonly()) return; + textDocument()->beginChanges( this ); textDocument()->replaceRangeSet(rangeSet, text); textDocument()->endChanges( coalesceId ); @@ -607,6 +627,8 @@ void TextEditorController::replaceRangeSet(TextRangeSet& rangeSet, const QString /// @param coalesceId the identifier for grouping undo operations void TextEditorController::replaceRangeSet(TextRangeSet& rangeSet, const QStringList& texts, int coalesceId) { + if(readonly()) return; + textDocument()->beginChanges( this ); textDocument()->replaceRangeSet( rangeSet, texts ); textDocument()->endChanges( coalesceId ); @@ -687,7 +709,7 @@ void TextEditorController::changeAndGiveTextSelection(TextRangeSet* rangeSet, in /// controller based operations are undone. When suppplying false a Document operation is being undone void TextEditorController::undo(bool soft) { - textDocument()->textUndoStack()->undo( soft ? this : 0, soft ); + textDocument()->textUndoStack()->undo( soft ? this : nullptr, soft ); } @@ -696,7 +718,7 @@ void TextEditorController::undo(bool soft) /// @param soft perform a soft undo? void TextEditorController::redo(bool soft) { - textDocument()->textUndoStack()->redo( soft ? this : 0, soft ); + textDocument()->textUndoStack()->redo( soft ? this : nullptr, soft ); } diff --git a/edbee-lib/edbee/texteditorcontroller.h b/edbee-lib/edbee/texteditorcontroller.h index dd1d8ae..a7194cb 100644 --- a/edbee-lib/edbee/texteditorcontroller.h +++ b/edbee-lib/edbee/texteditorcontroller.h @@ -146,6 +146,10 @@ public slots: virtual void executeCommand( TextEditorCommand* textCommand ); virtual bool executeCommand( const QString& name=QString() ); + // returns the readonly state + virtual bool readonly() const; + virtual void setReadonly(bool value); + private: TextEditorWidget* widgetRef_; ///< A reference to the text editor widget diff --git a/edbee-lib/edbee/texteditorwidget.cpp b/edbee-lib/edbee/texteditorwidget.cpp index 0c492f3..e6dea21 100644 --- a/edbee-lib/edbee/texteditorwidget.cpp +++ b/edbee-lib/edbee/texteditorwidget.cpp @@ -47,19 +47,20 @@ namespace edbee { /// The default TextEditor widget constructor -TextEditorWidget::TextEditorWidget( QWidget* parent) - : QWidget( parent ) - , controller_(0) - , scrollAreaRef_(0) - , editCompRef_(0) - , autoCompleteCompRef_(0) +TextEditorWidget::TextEditorWidget(QWidget* parent) + : QWidget(parent) + , controller_(nullptr) + , scrollAreaRef_(nullptr) + , editCompRef_(nullptr) + , autoCompleteCompRef_(nullptr) , autoScrollMargin_(50) + , readonly_(false) { // auto initialize edbee if this hasn't been done alread Edbee::instance()->autoInit(); // create the controller - controller_ = new TextEditorController(this ); + controller_ = new TextEditorController(this); // setup the ui scrollAreaRef_ = new class TextEditorScrollArea(this); @@ -271,6 +272,19 @@ void TextEditorWidget::setPlaceholderText(const QString &text) } +/// Return the readonly status +bool TextEditorWidget::readonly() const +{ + return readonly_; +} + +/// Set the readonly status +void TextEditorWidget::setReadonly(bool value) +{ + readonly_ = value; +} + + /// This mehtod is called when a resize happens /// @param event the event of the editor widget void TextEditorWidget::resizeEvent(QResizeEvent* event) diff --git a/edbee-lib/edbee/texteditorwidget.h b/edbee-lib/edbee/texteditorwidget.h index 0ae7f2d..0e0ee40 100644 --- a/edbee-lib/edbee/texteditorwidget.h +++ b/edbee-lib/edbee/texteditorwidget.h @@ -65,6 +65,10 @@ class EDBEE_EXPORT TextEditorWidget : public QWidget void setAutoScrollMargin(int amount=50); void setPlaceholderText(const QString& text); + virtual bool readonly() const; + void setReadonly(bool readonly); + + protected: virtual void resizeEvent(QResizeEvent* event); @@ -103,7 +107,8 @@ public slots: TextMarginComponent* marginCompRef_; ///< The margin components TextEditorAutoCompleteComponent* autoCompleteCompRef_; ///< The autocomplete list widget - int autoScrollMargin_; //< Customize the autoscroll margin + int autoScrollMargin_; ///< Customize the autoscroll margin + bool readonly_; ///< Readonly mode }; } // edbee From 7dc2228ae67d5e752f9545ddcbf6f603e7c85eee Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Sat, 25 Jul 2020 06:08:58 +0200 Subject: [PATCH 08/15] ref #96, Added support for readonly mode, via widget->setReadonly() or controller->setReadonly() Update CMakeList.txt --- CHANGELOG.md | 1 + edbee-lib/CMakeLists.txt | 248 ++++++++++++++++++++------------------- 2 files changed, 126 insertions(+), 123 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d7ba9c..1d7b616 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ edbee.lib: +- fix #96, Added support for readonly mode, via widget->setReadonly() or controller->setReadonly - fix #90, Fixed several Qt deprecation warnings. Chagned 0 to nullptr. Possible incompatibility with older releases! - add #101, Support for JSON based grammar files. - fix #67, PlacholderText support via TextEditorWidget::setPlaceholderText. (uses 70% opacity of foreground color) diff --git a/edbee-lib/CMakeLists.txt b/edbee-lib/CMakeLists.txt index 05ca437..26e4031 100644 --- a/edbee-lib/CMakeLists.txt +++ b/edbee-lib/CMakeLists.txt @@ -10,162 +10,164 @@ PROJECT(edbee-lib) add_subdirectory(../vendor/qslog/ qslog) SET(SOURCES - edbee/util/mem/debug_new.cpp - edbee/util/mem/debug_allocs.cpp - edbee/util/simpleprofiler.cpp - edbee/util/textcodecdetector.cpp - edbee/util/lineending.cpp - edbee/texteditorwidget.cpp - edbee/views/textrenderer.cpp - edbee/models/textdocument.cpp - edbee/models/chardocument/chartextdocument.cpp - edbee/models/texteditorconfig.cpp - edbee/models/texteditorkeymap.cpp - edbee/models/textundostack.cpp - edbee/views/textcaretcache.cpp - edbee/models/textlexer.cpp - edbee/models/textrange.cpp - edbee/views/textselection.cpp - edbee/models/textdocumentscopes.cpp - edbee/lexers/grammartextlexer.cpp - edbee/util/gapvector.h - edbee/util/lineoffsetvector.cpp - edbee/models/textlinedata.cpp - edbee/models/textbuffer.cpp - edbee/models/chardocument/chartextbuffer.cpp - edbee/texteditorcontroller.cpp - edbee/texteditorcommand.cpp - edbee/commands/selectioncommand.cpp - edbee/commands/undocommand.cpp - edbee/commands/redocommand.cpp - edbee/commands/replaceselectioncommand.cpp + edbee/commands/commentcommand.cpp edbee/commands/copycommand.cpp edbee/commands/cutcommand.cpp - edbee/commands/pastecommand.cpp - edbee/io/textdocumentserializer.cpp - edbee/util/test.cpp - edbee/util/textcodec.cpp - edbee/io/tmlanguageparser.cpp edbee/commands/debugcommand.cpp - edbee/util/regexp.cpp - edbee/io/tmthemeparser.cpp - edbee/io/baseplistparser.cpp - edbee/io/jsonparser.cpp - edbee/models/textgrammar.cpp - edbee/models/texteditorcommandmap.cpp - edbee/views/components/texteditorautocompletecomponent.cpp - edbee/views/components/texteditorcomponent.cpp - edbee/views/components/texteditorrenderer.cpp - edbee/views/components/textmargincomponent.cpp - edbee/views/texttheme.cpp - edbee/views/texteditorscrollarea.cpp - edbee/models/textsearcher.cpp - edbee/commands/findcommand.cpp - edbee/io/keymapparser.cpp - edbee/commands/tabcommand.cpp - edbee/edbee.cpp - edbee/models/textdocumentfilter.cpp - edbee/util/cascadingqvariantmap.cpp edbee/commands/duplicatecommand.cpp + edbee/commands/findcommand.cpp edbee/commands/movelinecommand.cpp edbee/commands/newlinecommand.cpp - edbee/util/util.cpp + edbee/commands/pastecommand.cpp + edbee/commands/redocommand.cpp edbee/commands/removecommand.cpp + edbee/commands/replaceselectioncommand.cpp + edbee/commands/selectioncommand.cpp + edbee/commands/tabcommand.cpp + edbee/commands/togglereadonlycommand.cpp + edbee/commands/undocommand.cpp + edbee/data/factorycommandmap.cpp + edbee/data/factorykeymap.cpp + edbee/edbee.cpp + edbee/io/baseplistparser.cpp + edbee/io/jsonparser.cpp + edbee/io/keymapparser.cpp + edbee/io/textdocumentserializer.cpp + edbee/io/tmlanguageparser.cpp + edbee/io/tmthemeparser.cpp + edbee/lexers/grammartextlexer.cpp edbee/models/change.cpp edbee/models/changes/abstractrangedchange.cpp - edbee/models/changes/linedatalistchange.cpp edbee/models/changes/linedatachange.cpp + edbee/models/changes/linedatalistchange.cpp + edbee/models/changes/mergablechangegroup.cpp edbee/models/changes/selectionchange.cpp edbee/models/changes/textchange.cpp edbee/models/changes/textchangewithcaret.cpp - edbee/models/changes/mergablechangegroup.cpp - edbee/commands/commentcommand.cpp - edbee/util/rangesetlineiterator.cpp + edbee/models/chardocument/chartextbuffer.cpp + edbee/models/chardocument/chartextdocument.cpp edbee/models/dynamicvariables.cpp - edbee/util/rangelineiterator.cpp - edbee/data/factorykeymap.cpp - edbee/data/factorycommandmap.cpp edbee/models/textautocompleteprovider.cpp + edbee/models/textbuffer.cpp + edbee/models/textdocument.cpp + edbee/models/textdocumentfilter.cpp + edbee/models/textdocumentscopes.cpp + edbee/models/texteditorcommandmap.cpp + edbee/models/texteditorconfig.cpp + edbee/models/texteditorkeymap.cpp + edbee/models/textgrammar.cpp + edbee/models/textlexer.cpp + edbee/models/textlinedata.cpp + edbee/models/textrange.cpp + edbee/models/textsearcher.cpp + edbee/models/textundostack.cpp + edbee/texteditorcommand.cpp + edbee/texteditorcontroller.cpp + edbee/texteditorwidget.cpp + edbee/util/cascadingqvariantmap.cpp + edbee/util/gapvector.h + edbee/util/lineending.cpp + edbee/util/lineoffsetvector.cpp + edbee/util/mem/debug_allocs.cpp + edbee/util/mem/debug_new.cpp + edbee/util/rangelineiterator.cpp + edbee/util/rangesetlineiterator.cpp + edbee/util/regexp.cpp + edbee/util/simpleprofiler.cpp + edbee/util/test.cpp + edbee/util/textcodec.cpp + edbee/util/textcodecdetector.cpp + edbee/util/util.cpp + edbee/views/components/texteditorautocompletecomponent.cpp + edbee/views/components/texteditorcomponent.cpp + edbee/views/components/texteditorrenderer.cpp + edbee/views/components/textmargincomponent.cpp + edbee/views/textcaretcache.cpp + edbee/views/texteditorscrollarea.cpp + edbee/views/textrenderer.cpp + edbee/views/textselection.cpp + edbee/views/texttheme.cpp ) SET(HEADERS - edbee/util/logging.h - edbee/util/mem/debug_new.h - edbee/util/mem/debug_allocs.h - edbee/util/simpleprofiler.h - edbee/util/textcodecdetector.h - edbee/util/lineending.h - edbee/texteditorwidget.h - edbee/views/textrenderer.h - edbee/models/textdocument.h - edbee/models/chardocument/chartextdocument.h - edbee/models/texteditorconfig.h - edbee/models/texteditorkeymap.h - edbee/models/textundostack.h - edbee/texteditorcontroller.h - edbee/views/textcaretcache.h - edbee/models/textlexer.h - edbee/models/textrange.h - edbee/views/textselection.h - edbee/models/textdocumentscopes.h - edbee/lexers/grammartextlexer.h - edbee/util/lineoffsetvector.h - edbee/models/textlinedata.h - edbee/models/textbuffer.h - edbee/models/chardocument/chartextbuffer.h - edbee/texteditorcommand.h - edbee/commands/selectioncommand.h - edbee/commands/undocommand.h - edbee/commands/redocommand.h - edbee/commands/replaceselectioncommand.h + edbee/commands/commentcommand.h edbee/commands/copycommand.h edbee/commands/cutcommand.h - edbee/commands/pastecommand.h - edbee/models/textdocumentfilter.h - edbee/debug.h - edbee/io/textdocumentserializer.h - edbee/util/test.h - edbee/util/textcodec.h - edbee/io/tmlanguageparser.h edbee/commands/debugcommand.h - edbee/util/regexp.h - edbee/io/tmthemeparser.h - edbee/io/baseplistparser.h - edbee/io/jsonparser.h - edbee/models/textgrammar.h - edbee/models/texteditorcommandmap.h - edbee/views/components/texteditorautocompletecomponent.h - edbee/views/components/texteditorcomponent.h - edbee/views/components/texteditorrenderer.h - edbee/views/components/textmargincomponent.h - edbee/views/texttheme.h - edbee/views/texteditorscrollarea.h - edbee/models/textsearcher.h - edbee/commands/findcommand.h - edbee/io/keymapparser.h - edbee/commands/tabcommand.h - edbee/edbee.h - edbee/util/cascadingqvariantmap.h edbee/commands/duplicatecommand.h + edbee/commands/findcommand.h edbee/commands/movelinecommand.h edbee/commands/newlinecommand.h - edbee/util/util.h + edbee/commands/pastecommand.h + edbee/commands/redocommand.h edbee/commands/removecommand.h + edbee/commands/replaceselectioncommand.h + edbee/commands/selectioncommand.h + edbee/commands/tabcommand.h + edbee/commands/togglereadonlycommand.h + edbee/commands/undocommand.h + edbee/data/factorycommandmap.h + edbee/data/factorykeymap.h + edbee/debug.h + edbee/edbee.h + edbee/io/baseplistparser.h + edbee/io/jsonparser.h + edbee/io/keymapparser.h + edbee/io/textdocumentserializer.h + edbee/io/tmlanguageparser.h + edbee/io/tmthemeparser.h + edbee/lexers/grammartextlexer.h edbee/models/change.h edbee/models/changes/abstractrangedchange.h - edbee/models/changes/linedatalistchange.h edbee/models/changes/linedatachange.h + edbee/models/changes/linedatalistchange.h + edbee/models/changes/mergablechangegroup.h edbee/models/changes/selectionchange.h edbee/models/changes/textchange.h edbee/models/changes/textchangewithcaret.h - edbee/models/changes/mergablechangegroup.h - edbee/commands/commentcommand.h - edbee/util/rangesetlineiterator.h + edbee/models/chardocument/chartextbuffer.h + edbee/models/chardocument/chartextdocument.h edbee/models/dynamicvariables.h - edbee/util/rangelineiterator.h - edbee/data/factorykeymap.h - edbee/data/factorycommandmap.h edbee/models/textautocompleteprovider.h + edbee/models/textbuffer.h + edbee/models/textdocument.h + edbee/models/textdocumentfilter.h + edbee/models/textdocumentscopes.h + edbee/models/texteditorcommandmap.h + edbee/models/texteditorconfig.h + edbee/models/texteditorkeymap.h + edbee/models/textgrammar.h + edbee/models/textlexer.h + edbee/models/textlinedata.h + edbee/models/textrange.h + edbee/models/textsearcher.h + edbee/models/textundostack.h + edbee/texteditorcommand.h + edbee/texteditorcontroller.h + edbee/texteditorwidget.h + edbee/util/cascadingqvariantmap.h + edbee/util/lineending.h + edbee/util/lineoffsetvector.h + edbee/util/logging.h + edbee/util/mem/debug_allocs.h + edbee/util/mem/debug_new.h + edbee/util/rangelineiterator.h + edbee/util/rangesetlineiterator.h + edbee/util/regexp.h + edbee/util/simpleprofiler.h + edbee/util/test.h + edbee/util/textcodec.h + edbee/util/textcodecdetector.h + edbee/util/util.h + edbee/views/components/texteditorautocompletecomponent.h + edbee/views/components/texteditorcomponent.h + edbee/views/components/texteditorrenderer.h + edbee/views/components/textmargincomponent.h + edbee/views/textcaretcache.h + edbee/views/texteditorscrollarea.h + edbee/views/textrenderer.h + edbee/views/textselection.h + edbee/views/texttheme.h ) FIND_PACKAGE(Qt5Core REQUIRED) From d946f680e887406e69b95f43adb4b404859424c4 Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Mon, 27 Jul 2020 21:44:34 +0200 Subject: [PATCH 09/15] ref #99, Speed improvements for markAll. (Added beginChanges and endChanges, to prevent updating per item) --- CHANGELOG.md | 1 + edbee-lib/edbee/models/textsearcher.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d7b616..254910b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ edbee.lib: +- ref #99, Speed improvements for markAll. (Added beginChanges and endChanges, to prevent updating) - fix #96, Added support for readonly mode, via widget->setReadonly() or controller->setReadonly - fix #90, Fixed several Qt deprecation warnings. Chagned 0 to nullptr. Possible incompatibility with older releases! - add #101, Support for JSON based grammar files. diff --git a/edbee-lib/edbee/models/textsearcher.cpp b/edbee-lib/edbee/models/textsearcher.cpp index 6792ab6..0300445 100644 --- a/edbee-lib/edbee/models/textsearcher.cpp +++ b/edbee-lib/edbee/models/textsearcher.cpp @@ -25,7 +25,7 @@ TextSearcher::TextSearcher( QObject* parent ) , caseSensitive_(false) , wrapAround_(true) , reverse_(false) - , regExp_(0) + , regExp_(nullptr) { } @@ -239,12 +239,14 @@ void TextSearcher::markAll(TextRangeSet *rangeset) reverse_ = false; wrapAround_ = false; rangeset->clear(); + rangeset->beginChanges(); TextRange range = findNextRange(rangeset); while( !range.isEmpty() ) { rangeset->addRange(range.anchor(), range.caret()); range = findNextRange( rangeset ); } + rangeset->endChanges(); wrapAround_ = oldWrapAround; reverse_ = oldReverse; } @@ -359,7 +361,7 @@ void TextSearcher::selectUnderExpand( TextEditorWidget* widget, bool selectAllTe void TextSearcher::setDirty() { delete regExp_; - regExp_ = 0; + regExp_ = nullptr; } From 55e675a9698d7c0478296150d948c892da724e6e Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Sun, 16 Aug 2020 12:34:47 +0200 Subject: [PATCH 10/15] ref #106, Missing round function on SuSE. (Changed to qRound) --- CHANGELOG.md | 1 + edbee-lib/edbee/views/textrenderer.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 254910b..bb2e6f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ edbee.lib: +- ref #106, Missing round function on SuSE. (Changed to qRound) - ref #99, Speed improvements for markAll. (Added beginChanges and endChanges, to prevent updating) - fix #96, Added support for readonly mode, via widget->setReadonly() or controller->setReadonly - fix #90, Fixed several Qt deprecation warnings. Chagned 0 to nullptr. Possible incompatibility with older releases! diff --git a/edbee-lib/edbee/views/textrenderer.cpp b/edbee-lib/edbee/views/textrenderer.cpp index cd0307d..e2d9f56 100644 --- a/edbee-lib/edbee/views/textrenderer.cpp +++ b/edbee-lib/edbee/views/textrenderer.cpp @@ -197,7 +197,7 @@ int TextRenderer::xPosForColumn(int line, int column) QTextLine tl = layout->lineAt(0); x += tl.cursorToX(column); } - return round(x); + return qRound(x); } From 0c622658ad78dd6bfe4054dc553a1929be198599 Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Wed, 19 Aug 2020 15:35:34 +0200 Subject: [PATCH 11/15] =?UTF-8?q?ref=20#107,=20Several=20improvements=20?= =?UTF-8?q?=20(Thanks=20@sebcaux)=20Support=20for=20sticky-selection=20in?= =?UTF-8?q?=20replaceSelection=20methods.=20(Required=20for=20InpuMethod?= =?UTF-8?q?=20entry)=20Improved=20TextEditorComponent::InputMethodEvent...?= =?UTF-8?q?=20It=20now=20support=20special=20chars=20entry=20like=20expect?= =?UTF-8?q?ed.=20(Option+e,=20=20e=20=3D>=20=C2=B4=20=3D>=20=C3=A9)=20-=20?= =?UTF-8?q?Fixed=20gapvector=20destructor:=20it=20did=20not=20use=20an=20a?= =?UTF-8?q?rray=20delete.=20-=20TextEditorWidget::setHorizontalScrollBar?= =?UTF-8?q?=20not=20emits=20the=20correct=20horizontalScrollBarChanged=20e?= =?UTF-8?q?vent.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 +++++ edbee-lib/edbee/models/textdocument.cpp | 23 ++++++++++++------- edbee-lib/edbee/models/textdocument.h | 4 ++-- edbee-lib/edbee/texteditorcontroller.cpp | 22 +++++++++--------- edbee-lib/edbee/texteditorcontroller.h | 10 ++++---- edbee-lib/edbee/texteditorwidget.cpp | 4 ++-- edbee-lib/edbee/util/gapvector.h | 2 +- .../views/components/texteditorcomponent.cpp | 4 +++- .../views/components/texteditorrenderer.cpp | 8 ++++--- 9 files changed, 50 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb2e6f1..9971743 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ edbee.lib: +- Support for sticky-selection in replaceSelection methods. (Required for InpuMethod entry) +- Improved TextEditorComponent::InputMethodEvent... It now support special chars entry like expected. (Option+e, e => ´ => é) +- ref #107, Several improvements (Thanks @sebcaux) + - Fixed gapvector destructor: it did not use an array delete. + - TextEditorWidget::setHorizontalScrollBar not emits the correct horizontalScrollBarChanged event. + - (Did not include the condition defines, for older Qt versions) - ref #106, Missing round function on SuSE. (Changed to qRound) - ref #99, Speed improvements for markAll. (Added beginChanges and endChanges, to prevent updating) - fix #96, Added support for readonly mode, via widget->setReadonly() or controller->setReadonly diff --git a/edbee-lib/edbee/models/textdocument.cpp b/edbee-lib/edbee/models/textdocument.cpp index 5dd1749..cb81e60 100644 --- a/edbee-lib/edbee/models/textdocument.cpp +++ b/edbee-lib/edbee/models/textdocument.cpp @@ -202,14 +202,14 @@ void TextDocument::beginChanges(TextEditorController* controller) /// Replaces the given rangeset -void TextDocument::replaceRangeSet(TextRangeSet& rangeSet, const QString& textIn ) +void TextDocument::replaceRangeSet(TextRangeSet& rangeSet, const QString& textIn, bool stickySelection) { - return replaceRangeSet( rangeSet, QStringList(textIn) ); + return replaceRangeSet(rangeSet, QStringList(textIn), stickySelection); } /// replaces the given rangeset -void TextDocument::replaceRangeSet(TextRangeSet& rangeSet, const QStringList& textsIn ) +void TextDocument::replaceRangeSet(TextRangeSet& rangeSet, const QStringList& textsIn, bool stickySelection) { QStringList texts = textsIn; @@ -237,14 +237,21 @@ void TextDocument::replaceRangeSet(TextRangeSet& rangeSet, const QStringList& te // when a new caret position is supplied (can only happen via a TextDocumentFilter) // access it and change the caret to the given position + int caret = 0; if( effectiveChangeWithCaret && effectiveChangeWithCaret->caret() >= 0 ) { - range.setCaret( effectiveChangeWithCaret->caret() ); - + caret = effectiveChangeWithCaret->caret(); // Default caret location is change-independent: old location + length new text } else { - range.setCaret(range.min() + text.length() ); + caret = range.min() + text.length(); + } + + // sticky selection, keeps the selection around the text + if(stickySelection) { + range.set(range.min(), caret); + } else { + range.setCaret(caret); + range.reset(); } - range.reset(); // next range if( rangeSet.rangeCount() < oldRangeCount ) { @@ -321,7 +328,7 @@ void TextDocument::append(const QString& text, int coalesceId ) /// @param coalesceId (default 0) the coalesceId to use. Whe using the same number changes could be merged to one change. CoalesceId of 0 means no merging void TextDocument::replace( int offset, int length, const QString& text, int coalesceId ) { - executeAndGiveChange( new TextChange( offset, length, text ), coalesceId ); + executeAndGiveChange( new TextChange( offset, length, text ), coalesceId); } diff --git a/edbee-lib/edbee/models/textdocument.h b/edbee-lib/edbee/models/textdocument.h index 98b759d..a18fb36 100644 --- a/edbee-lib/edbee/models/textdocument.h +++ b/edbee-lib/edbee/models/textdocument.h @@ -113,8 +113,8 @@ Q_OBJECT virtual TextDocumentFilter* documentFilter(); void beginChanges( TextEditorController* controller ); - void replaceRangeSet( TextRangeSet& rangeSet, const QString& text ); - void replaceRangeSet( TextRangeSet& rangeSet, const QStringList& texts ); + void replaceRangeSet(TextRangeSet& rangeSet, const QString& text, bool stickySelection = false); + void replaceRangeSet(TextRangeSet& rangeSet, const QStringList& texts, bool stickySelection = false); void giveSelection( TextEditorController* controller, TextRangeSet* rangeSet); void endChanges( int coalesceId ); diff --git a/edbee-lib/edbee/texteditorcontroller.cpp b/edbee-lib/edbee/texteditorcontroller.cpp index 6dcec2f..999852c 100644 --- a/edbee-lib/edbee/texteditorcontroller.cpp +++ b/edbee-lib/edbee/texteditorcontroller.cpp @@ -579,30 +579,30 @@ void TextEditorController::setReadonly(bool value) /// @param length the number of characters to replace /// @param text the text to replace /// @param coalesceId the identifier for grouping undo operations -void TextEditorController::replace(int offset, int length, const QString& text, int coalesceId) +void TextEditorController::replace(int offset, int length, const QString& text, int coalesceId, bool stickySelection) { // SelectionTextChange* change = new SelectionTextChange(this); TextRangeSet ranges(textDocument()); ranges.addRange(offset, offset+length); - replaceRangeSet(ranges,text,coalesceId); + replaceRangeSet(ranges,text,coalesceId, stickySelection); } /// This method replaces the selection with the given text /// @param text the text to replace the selection with /// @param coalesceId the identifier for grouping undo operations -void TextEditorController::replaceSelection(const QString& text, int coalesceId ) +void TextEditorController::replaceSelection(const QString& text, int coalesceId, bool stickySelection) { - replaceRangeSet( *dynamic_cast( textSelection() ), text, coalesceId ); + replaceRangeSet( *dynamic_cast( textSelection() ), text, coalesceId, stickySelection); } /// This method replaces the given selection with the given texts /// @param texts the list of texts that need to be replaced /// @param coalesceID the identifier for grouping undo operation -void TextEditorController::replaceSelection(const QStringList& texts, int coalesceId) +void TextEditorController::replaceSelection(const QStringList& texts, int coalesceId, bool stickySelection) { - replaceRangeSet( *dynamic_cast( textSelection() ), texts, coalesceId ); + replaceRangeSet(*dynamic_cast( textSelection() ), texts, coalesceId, stickySelection); } @@ -610,13 +610,13 @@ void TextEditorController::replaceSelection(const QStringList& texts, int coales /// @param reangeSet hte ranges to replace /// @param text the text to replace the selection with /// @param coalesceId the identifier for grouping undo operations -void TextEditorController::replaceRangeSet(TextRangeSet& rangeSet, const QString& text, int coalesceId) +void TextEditorController::replaceRangeSet(TextRangeSet& rangeSet, const QString& text, int coalesceId, bool stickySelection) { if(readonly()) return; textDocument()->beginChanges( this ); - textDocument()->replaceRangeSet(rangeSet, text); - textDocument()->endChanges( coalesceId ); + textDocument()->replaceRangeSet(rangeSet, text, stickySelection); + textDocument()->endChanges(coalesceId); notifyStateChange(); } @@ -625,12 +625,12 @@ void TextEditorController::replaceRangeSet(TextRangeSet& rangeSet, const QString /// @param rangeSet the rangeset to fille /// @param text the texts to fill the given ranges with. /// @param coalesceId the identifier for grouping undo operations -void TextEditorController::replaceRangeSet(TextRangeSet& rangeSet, const QStringList& texts, int coalesceId) +void TextEditorController::replaceRangeSet(TextRangeSet& rangeSet, const QStringList& texts, int coalesceId, bool stickySelection) { if(readonly()) return; textDocument()->beginChanges( this ); - textDocument()->replaceRangeSet( rangeSet, texts ); + textDocument()->replaceRangeSet( rangeSet, texts, stickySelection); textDocument()->endChanges( coalesceId ); notifyStateChange(); } diff --git a/edbee-lib/edbee/texteditorcontroller.h b/edbee-lib/edbee/texteditorcontroller.h index a7194cb..d760159 100644 --- a/edbee-lib/edbee/texteditorcontroller.h +++ b/edbee-lib/edbee/texteditorcontroller.h @@ -121,11 +121,11 @@ public slots: virtual void storeSelection( int coalesceId=0 ); // replace the given selection - virtual void replace( int offset, int length, const QString& text, int coalesceId ); - virtual void replaceSelection( const QString& text, int coalesceId=0 ); - virtual void replaceSelection( const QStringList& texts, int coalesceId=0 ); - virtual void replaceRangeSet(TextRangeSet& rangeSet, const QString& text, int coalesceId=0 ); - virtual void replaceRangeSet(TextRangeSet& rangeSet, const QStringList& texts, int coalesceId=0 ); + virtual void replace( int offset, int length, const QString& text, int coalesceId, bool stickySelection=false); + virtual void replaceSelection(const QString& text, int coalesceId=0, bool stickySelection=false); + virtual void replaceSelection(const QStringList& texts, int coalesceId=0, bool stickySelection=false); + virtual void replaceRangeSet(TextRangeSet& rangeSet, const QString& text, int coalesceId=0, bool stickySelection=false); + virtual void replaceRangeSet(TextRangeSet& rangeSet, const QStringList& texts, int coalesceId=0, bool stickySelection=false); // caret movements virtual void moveCaretTo( int line, int col, bool keepAnchors, int rangeIndex=-1 ); diff --git a/edbee-lib/edbee/texteditorwidget.cpp b/edbee-lib/edbee/texteditorwidget.cpp index e6dea21..101e012 100644 --- a/edbee-lib/edbee/texteditorwidget.cpp +++ b/edbee-lib/edbee/texteditorwidget.cpp @@ -241,7 +241,7 @@ QScrollBar* TextEditorWidget::verticalScrollBar() const void TextEditorWidget::setVerticalScrollBar(QScrollBar* scrollBar) { scrollAreaRef_->setVerticalScrollBar(scrollBar); - emit verticalScrollBarChanged( scrollBar ); + emit verticalScrollBarChanged(scrollBar); } @@ -251,7 +251,7 @@ void TextEditorWidget::setVerticalScrollBar(QScrollBar* scrollBar) void TextEditorWidget::setHorizontalScrollBar(QScrollBar* scrollBar) { scrollAreaRef_->setHorizontalScrollBar(scrollBar); - emit verticalScrollBarChanged( scrollBar ); + emit horizontalScrollBarChanged(scrollBar); } /// Returns the auto scroll margin diff --git a/edbee-lib/edbee/util/gapvector.h b/edbee-lib/edbee/util/gapvector.h index 8b8d8c5..e59e8e7 100644 --- a/edbee-lib/edbee/util/gapvector.h +++ b/edbee-lib/edbee/util/gapvector.h @@ -29,7 +29,7 @@ class EDBEE_EXPORT GapVector { } ~GapVector() { - delete items_; + delete[] items_; } /// returns the used length of the data diff --git a/edbee-lib/edbee/views/components/texteditorcomponent.cpp b/edbee-lib/edbee/views/components/texteditorcomponent.cpp index 8986e25..0d8501d 100644 --- a/edbee-lib/edbee/views/components/texteditorcomponent.cpp +++ b/edbee-lib/edbee/views/components/texteditorcomponent.cpp @@ -339,7 +339,8 @@ void TextEditorComponent::keyReleaseEvent(QKeyEvent *event) void TextEditorComponent::inputMethodEvent( QInputMethodEvent* m ) { - // replace the selection with an empty text + + // replace the selection with an empty text if( textSelection()->hasSelection() ) { controller()->replaceSelection("",false); } @@ -355,6 +356,7 @@ void TextEditorComponent::inputMethodEvent( QInputMethodEvent* m ) if( !m->preeditString().isEmpty() ) { // replaceSelection(m->preeditString()); + controller()->replaceSelection(m->preeditString(),false, true); } else { controller()->replaceSelection(m->commitString(),false); } diff --git a/edbee-lib/edbee/views/components/texteditorrenderer.cpp b/edbee-lib/edbee/views/components/texteditorrenderer.cpp index 3877b95..3ec1ebf 100644 --- a/edbee-lib/edbee/views/components/texteditorrenderer.cpp +++ b/edbee-lib/edbee/views/components/texteditorrenderer.cpp @@ -124,6 +124,8 @@ void TextEditorRenderer::renderLineBorderedRanges(QPainter *painter,int line) int lineHeight = renderer()->lineHeight(); QPen pen(themeRef_->foregroundColor(), 0.5); +// QPen pen(themeRef_->findHighlightForegroundColor(), 0.5); +// QBrush brush(themeRef_->findHighlightBackgroundColor()); painter->setRenderHint(QPainter::Antialiasing); int firstRangeIdx=0; @@ -143,15 +145,15 @@ void TextEditorRenderer::renderLineBorderedRanges(QPainter *painter,int line) int startColumn = doc->columnFromOffsetAndLine( range.min(), line ); int endColumn = doc->columnFromOffsetAndLine( range.max(), line ); - int startX = textLine.cursorToX( startColumn ); - int endX = textLine.cursorToX( endColumn ); + qreal startX = textLine.cursorToX( startColumn ); + qreal endX = textLine.cursorToX( endColumn ); if( range.length() > 0 && endColumn+1 >= lastLineColumn) endX += 3; QPainterPath path; path.addRoundedRect(startX, line*lineHeight + rect.top(), endX - startX, rect.height(),5,5); +// painter->fillPath(path, brush); painter->strokePath(path, pen); -// painter->strok(startX, line*lineHeight + rect.top(), endX - startX, rect.height(), themeRef_->selectionColor() ); //QColor::fromRgb(0xDD, 0x88, 0xEE) ); } } //PROF_END From a95706d621e4610c5fe66a339bf9f9cea4c0a32d Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Fri, 4 Sep 2020 10:34:09 +0200 Subject: [PATCH 12/15] Disabled TextEditorComponent::inputMethodEvent for Linux --- .../edbee/views/components/texteditorcomponent.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/edbee-lib/edbee/views/components/texteditorcomponent.cpp b/edbee-lib/edbee/views/components/texteditorcomponent.cpp index 0d8501d..dd68fef 100644 --- a/edbee-lib/edbee/views/components/texteditorcomponent.cpp +++ b/edbee-lib/edbee/views/components/texteditorcomponent.cpp @@ -339,9 +339,13 @@ void TextEditorComponent::keyReleaseEvent(QKeyEvent *event) void TextEditorComponent::inputMethodEvent( QInputMethodEvent* m ) { + #ifndef Q_OS_LINUX - // replace the selection with an empty text - if( textSelection()->hasSelection() ) { +/// TODO: https://doc.qt.io/qt-5/qinputmethodevent.html +/// Analyize how to implement this. The preeditString should NOT alter the undo-buffer + + // replace the selection with an empty text (only if there's content to replace) + if( textSelection()->hasSelection() && (!m->preeditString().isEmpty() || !m->commitString().isEmpty())) { controller()->replaceSelection("",false); } @@ -361,6 +365,9 @@ void TextEditorComponent::inputMethodEvent( QInputMethodEvent* m ) controller()->replaceSelection(m->commitString(),false); } + m->accept(); + + #endif } From fce89540c784eceb58d9c4845dfe361b4ee8c15d Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Sat, 5 Sep 2020 19:05:37 +0200 Subject: [PATCH 13/15] Fixed cmake on mac os x --- .gitignore | 6 ++++-- edbee-lib/CMakeLists.txt | 3 +++ edbee-test/main.cpp | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 0aa00b5..e1e8ecc 100644 --- a/.gitignore +++ b/.gitignore @@ -40,5 +40,7 @@ edbee-test/edbee-test .vscode .vs/ -edbee-lib/debug/ -edbee-lib/release/ +edbee-lib/edbee-lib_autogen/ +edbee-lib/qslog/ +edbee-test/edbee-test_autogen/ +edbee-test/edbee-lib/qslog/ diff --git a/edbee-lib/CMakeLists.txt b/edbee-lib/CMakeLists.txt index 26e4031..ebc7103 100644 --- a/edbee-lib/CMakeLists.txt +++ b/edbee-lib/CMakeLists.txt @@ -5,6 +5,9 @@ IF(POLICY CMP0020) CMAKE_POLICY(SET CMP0020 NEW) ENDIF() +# hack?? https://stackoverflow.com/questions/31561309/cmake-warnings-under-os-x-macosx-rpath-is-not-specified-for-the-following-targe +set(CMAKE_MACOSX_RPATH 1) + PROJECT(edbee-lib) add_subdirectory(../vendor/qslog/ qslog) diff --git a/edbee-test/main.cpp b/edbee-test/main.cpp index 4bce738..1eb5e3d 100644 --- a/edbee-test/main.cpp +++ b/edbee-test/main.cpp @@ -8,8 +8,8 @@ #include #include -#include -#include +#include "../vendor/qslog/QsLog.h" +#include "../vendor/qslog/QsLogDest.h" #include "edbee/util/test.h" #include "edbee/edbee.h" From d01c05fce58cad4f6b093f2f32b605d79c33ffe9 Mon Sep 17 00:00:00 2001 From: Rick Blommers Date: Sun, 25 Oct 2020 19:36:02 +0100 Subject: [PATCH 14/15] ref #112, Workaround for missing Qt::endl in Qt 5.12 --- CHANGELOG.md | 1 + vendor/qslog/QsLogDestFile.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9971743..6a86b95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ edbee.lib: +- #112, Workaround for missing Qt::endl in Qt 5.12 - Support for sticky-selection in replaceSelection methods. (Required for InpuMethod entry) - Improved TextEditorComponent::InputMethodEvent... It now support special chars entry like expected. (Option+e, e => ´ => é) - ref #107, Several improvements (Thanks @sebcaux) diff --git a/vendor/qslog/QsLogDestFile.cpp b/vendor/qslog/QsLogDestFile.cpp index ee15c4f..00ae8c9 100644 --- a/vendor/qslog/QsLogDestFile.cpp +++ b/vendor/qslog/QsLogDestFile.cpp @@ -170,7 +170,7 @@ void QsLogging::FileDestination::write(const LogMessage& message) mOutputStream.setCodec(QTextCodec::codecForName("UTF-8")); } - mOutputStream << utf8Message << Qt::endl; + mOutputStream << utf8Message << '\n'; mOutputStream.flush(); } From 56343e578f3d16400637e6d45347770c6e5911a8 Mon Sep 17 00:00:00 2001 From: Stephen Lyons Date: Tue, 27 Oct 2020 01:13:13 +0000 Subject: [PATCH 15/15] Revise: fix QString::split(...) for older Qt Versions A use of the above in the test code fails to build on anything older than Qt 5.14 as the `enum` used is only present in that and newer versions. Previously the `enum` was a member of the `QString` class rather than the `Qt` namespace... Signed-off-by: Stephen Lyons --- edbee-test/edbee/models/textrangetest.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/edbee-test/edbee/models/textrangetest.cpp b/edbee-test/edbee/models/textrangetest.cpp index acd3be3..6d4b648 100644 --- a/edbee-test/edbee/models/textrangetest.cpp +++ b/edbee-test/edbee/models/textrangetest.cpp @@ -32,7 +32,11 @@ do { \ /// @param definition the definition. In the format anchor>caret,anchor>caret static void addRanges( TextRangeSet* sel, const QString& definition ) { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) QStringList ranges = definition.split(",", Qt::SkipEmptyParts); +#else + QStringList ranges = definition.split(",", QString::SkipEmptyParts); +#endif foreach( QString range, ranges ) { QStringList values = range.split(">"); Q_ASSERT(values.length() == 2);