[kdevplatform/frameworks] language: make compile with new ktexteditor: remove start/endEditing

Dominik Haumann dhaumann at kde.org
Mon Mar 31 20:13:40 UTC 2014


On Saturday 29 March 2014 22:56:37 Sven Brauch wrote:
> Git commit 4d474f43b36914490e8b9aacac6b988970f28d26 by Sven Brauch.
> Committed on 29/03/2014 at 22:54.
> Pushed by brauch into branch 'frameworks'.
> 
> make compile with new ktexteditor: remove start/endEditing
> 
> M  +4    -3    language/backgroundparser/tests/test_backgroundparser.cpp
> M  +16   -51   language/codegen/coderepresentation.cpp
> M  +49   -7    language/codegen/coderepresentation.h
> M  +1    -4    language/codegen/documentchangeset.cpp
> 
> http://commits.kde.org/kdevplatform/4d474f43b36914490e8b9aacac6b988970f28d26
> 
> diff --git a/language/backgroundparser/tests/test_backgroundparser.cpp
> b/language/backgroundparser/tests/test_backgroundparser.cpp index
> aee0bec..caf4720 100644
> --- a/language/backgroundparser/tests/test_backgroundparser.cpp
> +++ b/language/backgroundparser/tests/test_backgroundparser.cpp
> @@ -281,9 +281,10 @@ void TestBackgroundparser::benchmarkDocumentChanges()
>      doc->createView(0);
>      QBENCHMARK {
>          for ( int i = 0; i < 5000; i++ ) {
> -            doc->startEditing();
> -            doc->insertText(KTextEditor::Cursor(0, 0), "This is a test line.\n");
> -            doc->finishEditing();
> +            {
> +                KTextEditor::Document::EditingTransaction t(doc);
> +                doc->insertText(KTextEditor::Cursor(0, 0), "This is a test line.\n");
> +            }
>              QApplication::processEvents();
>          }
>      }

In the above case, an EditingTransaction is not required, since it's only about a single insertText anyways.


> @@ -409,3 +373,4 @@ QString InsertArtificialCodeRepresentation::text() {
> 
>  }
> 
> +// kate: indent-width 4;
> diff --git a/language/codegen/coderepresentation.h
> b/language/codegen/coderepresentation.h index 17f1859..a866ee3 100644
> --- a/language/codegen/coderepresentation.h
> +++ b/language/codegen/coderepresentation.h
> @@ -22,7 +22,11 @@
>  #include "../languageexport.h"
>  #include <language/duchain/indexedstring.h>
> 
> +#include <ktexteditor/configinterface.h>
> +#include <ktexteditor/document.h>
> +
>  #include <ksharedptr.h>
> +#include <memory>
> 
>  class QString;
> 
> @@ -32,9 +36,49 @@ namespace KTextEditor {
> 
>  namespace KDevelop {
> 
> -    class SimpleRange;
> -    class IndexedString;
> -
> +struct KDevEditingTransaction;
> +
> +class SimpleRange;
> +class IndexedString;
> +
> +//NOTE: this is ugly, but otherwise kate might remove tabs again :-/
> +// see also: https://bugs.kde.org/show_bug.cgi?id=291074
> +struct EditorDisableReplaceTabs {
> +    EditorDisableReplaceTabs(KTextEditor::Document* document) : m_iface(qobject_cast<KTextEditor::ConfigInterface*>(document)), m_count(0) {
> +        ++m_count;
> +        if( m_count > 1 )
> +            return;
> +        if ( m_iface ) {
> +            m_oldReplaceTabs = m_iface->configValue( "replace-tabs" );
> +            m_iface->setConfigValue( "replace-tabs", false );
> +        }
> +    }
> +
> +    ~EditorDisableReplaceTabs() {
> +        --m_count;
> +        if( m_count > 0 )
> +            return;
> +
> +        Q_ASSERT( m_count == 0 );
> +
> +        if (m_iface)
> +            m_iface->setConfigValue("replace-tabs", m_oldReplaceTabs);
> +    }
> +
> +    KTextEditor::ConfigInterface* m_iface;
> +    int m_count;
> +    QVariant m_oldReplaceTabs;
> +};
> +
> +struct KDevEditingTransaction {
> +    KDevEditingTransaction(KTextEditor::Document* document)
> +    : disableReplaceTabs(document)
> +    , edit(document) { }
> +    EditorDisableReplaceTabs disableReplaceTabs;
> +    KTextEditor::Document::EditingTransaction edit;
> +    typedef std::unique_ptr<KDevEditingTransaction> Ptr;
> +};
> +

KDevelop should seriously try to fix such things through proper interfaces in KTextEditor.
The not above says "this is ugly" and this is so true...

Greetings,
Dominik


More information about the KDevelop-devel mailing list