forked from qt-creator/qt-creator
use QSharedPointer instead of QRefCountPointer
Change-Id: Ie670448bf924e02720eae6db33f2a346e8ac0001 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
committed by
David Schulz
parent
4435d55dee
commit
4a32f1d821
@@ -46,6 +46,7 @@
|
|||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
using namespace CMakeProjectManager;
|
using namespace CMakeProjectManager;
|
||||||
using namespace CMakeProjectManager::Internal;
|
using namespace CMakeProjectManager::Internal;
|
||||||
@@ -112,7 +113,7 @@ void CMakeEditor::build()
|
|||||||
CMakeEditorWidget::CMakeEditorWidget(QWidget *parent, CMakeEditorFactory *factory, TextEditor::TextEditorActionHandler *ah)
|
CMakeEditorWidget::CMakeEditorWidget(QWidget *parent, CMakeEditorFactory *factory, TextEditor::TextEditorActionHandler *ah)
|
||||||
: BaseTextEditorWidget(parent), m_factory(factory), m_ah(ah)
|
: BaseTextEditorWidget(parent), m_factory(factory), m_ah(ah)
|
||||||
{
|
{
|
||||||
CMakeDocument *doc = new CMakeDocument();
|
QSharedPointer<CMakeDocument> doc(new CMakeDocument);
|
||||||
doc->setMimeType(QLatin1String(CMakeProjectManager::Constants::CMAKEMIMETYPE));
|
doc->setMimeType(QLatin1String(CMakeProjectManager::Constants::CMAKEMIMETYPE));
|
||||||
setBaseTextDocument(doc);
|
setBaseTextDocument(doc);
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
@@ -124,7 +125,7 @@ ProjectFilesEditorWidget::ProjectFilesEditorWidget(QWidget *parent, ProjectFiles
|
|||||||
m_factory(factory),
|
m_factory(factory),
|
||||||
m_actionHandler(handler)
|
m_actionHandler(handler)
|
||||||
{
|
{
|
||||||
BaseTextDocument *doc = new BaseTextDocument();
|
QSharedPointer<BaseTextDocument> doc(new BaseTextDocument());
|
||||||
setBaseTextDocument(doc);
|
setBaseTextDocument(doc);
|
||||||
|
|
||||||
handler->setupActions(this);
|
handler->setupActions(this);
|
||||||
|
|||||||
@@ -73,6 +73,7 @@
|
|||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
using namespace GLSL;
|
using namespace GLSL;
|
||||||
using namespace GLSLEditor;
|
using namespace GLSLEditor;
|
||||||
@@ -159,7 +160,7 @@ GLSLTextEditorWidget::GLSLTextEditorWidget(QWidget *parent) :
|
|||||||
|
|
||||||
connect(this, SIGNAL(textChanged()), this, SLOT(updateDocument()));
|
connect(this, SIGNAL(textChanged()), this, SLOT(updateDocument()));
|
||||||
|
|
||||||
new Highlighter(baseTextDocument());
|
new Highlighter(baseTextDocument().data());
|
||||||
|
|
||||||
// if (m_modelManager) {
|
// if (m_modelManager) {
|
||||||
// m_semanticHighlighter->setModelManager(m_modelManager);
|
// m_semanticHighlighter->setModelManager(m_modelManager);
|
||||||
|
|||||||
@@ -436,7 +436,7 @@ void SemanticHighlighter::applyResults(int from, int to)
|
|||||||
if (m_startRevision != m_editor->editorRevision())
|
if (m_startRevision != m_editor->editorRevision())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TextEditor::BaseTextDocument *baseTextDocument = m_editor->baseTextDocument();
|
TextEditor::BaseTextDocument *baseTextDocument = m_editor->baseTextDocument().data();
|
||||||
QTC_ASSERT(baseTextDocument, return);
|
QTC_ASSERT(baseTextDocument, return);
|
||||||
TextEditor::SyntaxHighlighter *highlighter = qobject_cast<TextEditor::SyntaxHighlighter *>(baseTextDocument->syntaxHighlighter());
|
TextEditor::SyntaxHighlighter *highlighter = qobject_cast<TextEditor::SyntaxHighlighter *>(baseTextDocument->syntaxHighlighter());
|
||||||
QTC_ASSERT(highlighter, return);
|
QTC_ASSERT(highlighter, return);
|
||||||
@@ -452,7 +452,7 @@ void SemanticHighlighter::finished()
|
|||||||
if (m_startRevision != m_editor->editorRevision())
|
if (m_startRevision != m_editor->editorRevision())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TextEditor::BaseTextDocument *baseTextDocument = m_editor->baseTextDocument();
|
TextEditor::BaseTextDocument *baseTextDocument = m_editor->baseTextDocument().data();
|
||||||
QTC_ASSERT(baseTextDocument, return);
|
QTC_ASSERT(baseTextDocument, return);
|
||||||
TextEditor::SyntaxHighlighter *highlighter = qobject_cast<TextEditor::SyntaxHighlighter *>(baseTextDocument->syntaxHighlighter());
|
TextEditor::SyntaxHighlighter *highlighter = qobject_cast<TextEditor::SyntaxHighlighter *>(baseTextDocument->syntaxHighlighter());
|
||||||
QTC_ASSERT(highlighter, return);
|
QTC_ASSERT(highlighter, return);
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
namespace Qt4ProjectManager {
|
namespace Qt4ProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -81,7 +82,7 @@ Core::Id ProFileEditor::id() const
|
|||||||
ProFileEditorWidget::ProFileEditorWidget(QWidget *parent, ProFileEditorFactory *factory, TextEditor::TextEditorActionHandler *ah)
|
ProFileEditorWidget::ProFileEditorWidget(QWidget *parent, ProFileEditorFactory *factory, TextEditor::TextEditorActionHandler *ah)
|
||||||
: BaseTextEditorWidget(parent), m_factory(factory), m_ah(ah)
|
: BaseTextEditorWidget(parent), m_factory(factory), m_ah(ah)
|
||||||
{
|
{
|
||||||
ProFileDocument *doc = new ProFileDocument();
|
QSharedPointer<ProFileDocument> doc(new ProFileDocument());
|
||||||
doc->setMimeType(QLatin1String(Constants::PROFILE_MIMETYPE));
|
doc->setMimeType(QLatin1String(Constants::PROFILE_MIMETYPE));
|
||||||
setBaseTextDocument(doc);
|
setBaseTextDocument(doc);
|
||||||
|
|
||||||
|
|||||||
@@ -525,7 +525,7 @@ BaseTextEditor *BaseTextEditorWidget::editor() const
|
|||||||
|
|
||||||
void BaseTextEditorWidget::selectEncoding()
|
void BaseTextEditorWidget::selectEncoding()
|
||||||
{
|
{
|
||||||
BaseTextDocument *doc = d->m_document;
|
BaseTextDocument *doc = d->m_document.data();
|
||||||
CodecSelector codecSelector(this, doc);
|
CodecSelector codecSelector(this, doc);
|
||||||
|
|
||||||
switch (codecSelector.exec()) {
|
switch (codecSelector.exec()) {
|
||||||
@@ -655,7 +655,7 @@ void BaseTextEditorWidget::setChangeSet(const Utils::ChangeSet &changeSet)
|
|||||||
|
|
||||||
Core::IDocument *BaseTextEditorWidget::editorDocument() const
|
Core::IDocument *BaseTextEditorWidget::editorDocument() const
|
||||||
{
|
{
|
||||||
return d->m_document;
|
return d->m_document.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextEditorWidget::editorContentsChange(int position, int charsRemoved, int charsAdded)
|
void BaseTextEditorWidget::editorContentsChange(int position, int charsRemoved, int charsAdded)
|
||||||
@@ -2136,15 +2136,15 @@ void BaseTextEditorWidget::setDisplayName(const QString &title)
|
|||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseTextDocument *BaseTextEditorWidget::baseTextDocument() const
|
QSharedPointer<BaseTextDocument> BaseTextEditorWidget::baseTextDocument() const
|
||||||
{
|
{
|
||||||
return d->m_document;
|
return d->m_document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BaseTextEditorWidget::setBaseTextDocument(BaseTextDocument *doc)
|
void BaseTextEditorWidget::setBaseTextDocument(const QSharedPointer<BaseTextDocument> &doc)
|
||||||
{
|
{
|
||||||
if (doc) {
|
if (!doc.isNull()) {
|
||||||
d->setupDocumentSignals(doc);
|
d->setupDocumentSignals(doc);
|
||||||
d->m_document = doc;
|
d->m_document = doc;
|
||||||
}
|
}
|
||||||
@@ -2504,12 +2504,12 @@ BaseTextEditorWidgetPrivate::~BaseTextEditorWidgetPrivate()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextEditorWidgetPrivate::setupDocumentSignals(BaseTextDocument *document)
|
void BaseTextEditorWidgetPrivate::setupDocumentSignals(const QSharedPointer<BaseTextDocument> &document)
|
||||||
{
|
{
|
||||||
BaseTextDocument *oldDocument = q->baseTextDocument();
|
QSharedPointer<BaseTextDocument> oldDocument = q->baseTextDocument();
|
||||||
if (oldDocument) {
|
if (!oldDocument.isNull()) {
|
||||||
q->disconnect(oldDocument->document(), 0, q, 0);
|
q->disconnect(oldDocument->document(), 0, q, 0);
|
||||||
q->disconnect(oldDocument, 0, q, 0);
|
q->disconnect(oldDocument.data(), 0, q, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextDocument *doc = document->document();
|
QTextDocument *doc = document->document();
|
||||||
@@ -2534,10 +2534,10 @@ void BaseTextEditorWidgetPrivate::setupDocumentSignals(BaseTextDocument *documen
|
|||||||
QObject::connect(doc, SIGNAL(modificationChanged(bool)), q, SIGNAL(changed()));
|
QObject::connect(doc, SIGNAL(modificationChanged(bool)), q, SIGNAL(changed()));
|
||||||
QObject::connect(doc, SIGNAL(contentsChange(int,int,int)), q,
|
QObject::connect(doc, SIGNAL(contentsChange(int,int,int)), q,
|
||||||
SLOT(editorContentsChange(int,int,int)), Qt::DirectConnection);
|
SLOT(editorContentsChange(int,int,int)), Qt::DirectConnection);
|
||||||
QObject::connect(document, SIGNAL(changed()), q, SIGNAL(changed()));
|
QObject::connect(document.data(), SIGNAL(changed()), q, SIGNAL(changed()));
|
||||||
QObject::connect(document, SIGNAL(titleChanged(QString)), q, SLOT(setDisplayName(QString)));
|
QObject::connect(document.data(), SIGNAL(titleChanged(QString)), q, SLOT(setDisplayName(QString)));
|
||||||
QObject::connect(document, SIGNAL(aboutToReload()), q, SLOT(documentAboutToBeReloaded()));
|
QObject::connect(document.data(), SIGNAL(aboutToReload()), q, SLOT(documentAboutToBeReloaded()));
|
||||||
QObject::connect(document, SIGNAL(reloaded()), q, SLOT(documentReloaded()));
|
QObject::connect(document.data(), SIGNAL(reloaded()), q, SLOT(documentReloaded()));
|
||||||
q->slotUpdateExtraAreaWidth();
|
q->slotUpdateExtraAreaWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6137,7 +6137,7 @@ void BaseTextEditorWidget::appendStandardContextMenuActions(QMenu *menu)
|
|||||||
if (a && a->isEnabled())
|
if (a && a->isEnabled())
|
||||||
menu->addAction(a);
|
menu->addAction(a);
|
||||||
|
|
||||||
BaseTextDocument *doc = baseTextDocument();
|
QSharedPointer<BaseTextDocument> doc = baseTextDocument();
|
||||||
if (doc->codec()->name() == QByteArray("UTF-8")) {
|
if (doc->codec()->name() == QByteArray("UTF-8")) {
|
||||||
a = Core::ActionManager::command(Constants::SWITCH_UTF8BOM)->action();
|
a = Core::ActionManager::command(Constants::SWITCH_UTF8BOM)->action();
|
||||||
if (a && a->isEnabled()) {
|
if (a && a->isEnabled()) {
|
||||||
@@ -6599,7 +6599,7 @@ IAssistInterface *BaseTextEditorWidget::createAssistInterface(AssistKind kind,
|
|||||||
AssistReason reason) const
|
AssistReason reason) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(kind);
|
Q_UNUSED(kind);
|
||||||
return new DefaultAssistInterface(document(), position(), d->m_document, reason);
|
return new DefaultAssistInterface(document(), position(), d->m_document.data(), reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TextEditor::BaseTextEditorWidget::foldReplacementText(const QTextBlock &) const
|
QString TextEditor::BaseTextEditorWidget::foldReplacementText(const QTextBlock &) const
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#include <find/ifindsupport.h>
|
#include <find/ifindsupport.h>
|
||||||
|
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
@@ -357,8 +358,8 @@ public:
|
|||||||
void duplicateFrom(BaseTextEditorWidget *editor);
|
void duplicateFrom(BaseTextEditorWidget *editor);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BaseTextDocument *baseTextDocument() const;
|
QSharedPointer<BaseTextDocument> baseTextDocument() const;
|
||||||
void setBaseTextDocument(BaseTextDocument *doc);
|
void setBaseTextDocument(const QSharedPointer<BaseTextDocument> &doc);
|
||||||
|
|
||||||
void setDefaultPath(const QString &defaultPath);
|
void setDefaultPath(const QString &defaultPath);
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
#include <utils/changeset.h>
|
#include <utils/changeset.h>
|
||||||
|
|
||||||
#include <QBasicTimer>
|
#include <QBasicTimer>
|
||||||
#include <QSharedData>
|
#include <QSharedPointer>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
|
||||||
@@ -75,73 +75,6 @@ public:
|
|||||||
void fromSelection(const TabSettings &ts, const QTextCursor &selection);
|
void fromSelection(const TabSettings &ts, const QTextCursor &selection);
|
||||||
};
|
};
|
||||||
|
|
||||||
//========== Pointers with reference count ==========
|
|
||||||
|
|
||||||
template <class T> class QRefCountData : public QSharedData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QRefCountData(T *data) { m_data = data; }
|
|
||||||
|
|
||||||
~QRefCountData() { delete m_data; }
|
|
||||||
|
|
||||||
T *m_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* MOSTLY COPIED FROM QSHAREDDATA(-POINTER) */
|
|
||||||
template <class T> class QRefCountPointer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
inline T &operator*() { return d ? *(d->m_data) : 0; }
|
|
||||||
inline const T &operator*() const { return d ? *(d->m_data) : 0; }
|
|
||||||
inline T *operator->() { return d ? d->m_data : 0; }
|
|
||||||
inline const T *operator->() const { return d ? d->m_data : 0; }
|
|
||||||
inline operator T *() { return d ? d->m_data : 0; }
|
|
||||||
inline operator const T *() const { return d ? d->m_data : 0; }
|
|
||||||
|
|
||||||
inline bool operator==(const QRefCountPointer<T> &other) const { return d == other.d; }
|
|
||||||
inline bool operator!=(const QRefCountPointer<T> &other) const { return d != other.d; }
|
|
||||||
|
|
||||||
inline QRefCountPointer() { d = 0; }
|
|
||||||
inline ~QRefCountPointer() { if (d && !d->ref.deref()) delete d; }
|
|
||||||
|
|
||||||
explicit QRefCountPointer(T *data) {
|
|
||||||
if (data) {
|
|
||||||
d = new QRefCountData<T>(data);
|
|
||||||
d->ref.ref();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
d = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inline QRefCountPointer(const QRefCountPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
|
|
||||||
inline QRefCountPointer<T> & operator=(const QRefCountPointer<T> &o) {
|
|
||||||
if (o.d != d) {
|
|
||||||
if (d && !d->ref.deref())
|
|
||||||
delete d;
|
|
||||||
//todo: atomic assign of pointers
|
|
||||||
d = o.d;
|
|
||||||
if (d)
|
|
||||||
d->ref.ref();
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
inline QRefCountPointer &operator=(T *o) {
|
|
||||||
if (d == 0 || d->m_data != o) {
|
|
||||||
if (d && !d->ref.deref())
|
|
||||||
delete d;
|
|
||||||
d = new QRefCountData<T>(o);
|
|
||||||
if (d)
|
|
||||||
d->ref.ref();
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator!() const { return !d; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
QRefCountData<T> *d;
|
|
||||||
};
|
|
||||||
|
|
||||||
//================BaseTextEditorPrivate==============
|
//================BaseTextEditorPrivate==============
|
||||||
|
|
||||||
struct BaseTextEditorPrivateHighlightBlocks
|
struct BaseTextEditorPrivateHighlightBlocks
|
||||||
@@ -168,7 +101,7 @@ public:
|
|||||||
~BaseTextEditorWidgetPrivate();
|
~BaseTextEditorWidgetPrivate();
|
||||||
|
|
||||||
void setupBasicEditActions(TextEditorActionHandler *actionHandler);
|
void setupBasicEditActions(TextEditorActionHandler *actionHandler);
|
||||||
void setupDocumentSignals(BaseTextDocument *document);
|
void setupDocumentSignals(const QSharedPointer<BaseTextDocument> &document);
|
||||||
void updateLineSelectionColor();
|
void updateLineSelectionColor();
|
||||||
|
|
||||||
void print(QPrinter *printer);
|
void print(QPrinter *printer);
|
||||||
@@ -184,7 +117,7 @@ public:
|
|||||||
QList<QTextEdit::ExtraSelection> m_syntaxHighlighterSelections;
|
QList<QTextEdit::ExtraSelection> m_syntaxHighlighterSelections;
|
||||||
QTextEdit::ExtraSelection m_lineSelection;
|
QTextEdit::ExtraSelection m_lineSelection;
|
||||||
|
|
||||||
QRefCountPointer<BaseTextDocument> m_document;
|
QSharedPointer<BaseTextDocument> m_document;
|
||||||
QByteArray m_tempState;
|
QByteArray m_tempState;
|
||||||
QByteArray m_tempNavigationState;
|
QByteArray m_tempNavigationState;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user