forked from qt-creator/qt-creator
VcsBase: Re-organize BaseVcsEditorFactory interface
Less code now. Change-Id: I5abdd0bb56ecb940bb606111461b521a54ecaf21 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -51,21 +51,20 @@ namespace Internal {
|
||||
class BaseVcsEditorFactoryPrivate
|
||||
{
|
||||
public:
|
||||
BaseVcsEditorFactoryPrivate(const VcsBaseEditorParameters *t);
|
||||
|
||||
const VcsBaseEditorParameters *m_type;
|
||||
QObject *m_describeReceiver;
|
||||
const char *m_describeSlot;
|
||||
};
|
||||
|
||||
BaseVcsEditorFactoryPrivate::BaseVcsEditorFactoryPrivate(const VcsBaseEditorParameters *t) :
|
||||
m_type(t)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
BaseVcsEditorFactory::BaseVcsEditorFactory(const VcsBaseEditorParameters *t)
|
||||
: d(new Internal::BaseVcsEditorFactoryPrivate(t))
|
||||
BaseVcsEditorFactory::BaseVcsEditorFactory(const VcsBaseEditorParameters *t,
|
||||
QObject *describeReceiver, const char *describeSlot)
|
||||
: d(new Internal::BaseVcsEditorFactoryPrivate)
|
||||
{
|
||||
d->m_type = t;
|
||||
d->m_describeReceiver = describeReceiver;
|
||||
d->m_describeSlot = describeSlot;
|
||||
setId(t->id);
|
||||
setDisplayName(QCoreApplication::translate("VCS", t->displayName));
|
||||
addMimeType(t->mimeType);
|
||||
@@ -81,6 +80,10 @@ Core::IEditor *BaseVcsEditorFactory::createEditor()
|
||||
{
|
||||
VcsBaseEditorWidget *vcsEditor = createVcsBaseEditor(d->m_type);
|
||||
|
||||
vcsEditor->init();
|
||||
if (d->m_describeReceiver)
|
||||
connect(vcsEditor, SIGNAL(describeRequested(QString,QString)), d->m_describeReceiver, d->m_describeSlot);
|
||||
|
||||
vcsEditor->baseTextDocument()->setMimeType(mimeTypes().front());
|
||||
|
||||
TextEditor::TextEditorSettings::initializeEditor(vcsEditor);
|
||||
|
||||
@@ -43,16 +43,16 @@ class VCSBASE_EXPORT BaseVcsEditorFactory : public Core::IEditorFactory
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BaseVcsEditorFactory(const VcsBaseEditorParameters *type);
|
||||
explicit BaseVcsEditorFactory(const VcsBaseEditorParameters *type,
|
||||
QObject *describeReceiver,
|
||||
const char *describeSlot);
|
||||
~BaseVcsEditorFactory();
|
||||
|
||||
Core::IEditor *createEditor();
|
||||
|
||||
private:
|
||||
// Implement to create and initialize (call init()) a
|
||||
// VcsBaseEditor subclass
|
||||
virtual VcsBaseEditorWidget *createVcsBaseEditor(const VcsBaseEditorParameters *type,
|
||||
QWidget *parent = 0) = 0;
|
||||
// Implement to create and initialize (call init()) a VcsBaseEditor subclass.
|
||||
virtual VcsBaseEditorWidget *createVcsBaseEditor(const VcsBaseEditorParameters *type) = 0;
|
||||
|
||||
Internal::BaseVcsEditorFactoryPrivate *const d;
|
||||
};
|
||||
@@ -64,37 +64,18 @@ class VcsEditorFactory : public BaseVcsEditorFactory
|
||||
public:
|
||||
explicit VcsEditorFactory(const VcsBaseEditorParameters *type,
|
||||
QObject *describeReceiver = 0,
|
||||
const char *describeSlot = 0);
|
||||
const char *describeSlot = 0)
|
||||
: BaseVcsEditorFactory(type, describeReceiver, describeSlot)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
VcsBaseEditorWidget *createVcsBaseEditor(const VcsBaseEditorParameters *type,
|
||||
QWidget *parent = 0);
|
||||
QObject *m_describeReceiver;
|
||||
const char *m_describeSlot;
|
||||
VcsBaseEditorWidget *createVcsBaseEditor(const VcsBaseEditorParameters *type)
|
||||
{
|
||||
return new Editor(type, 0);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Editor>
|
||||
VcsEditorFactory<Editor>::VcsEditorFactory(const VcsBaseEditorParameters *type,
|
||||
QObject *describeReceiver,
|
||||
const char *describeSlot) :
|
||||
BaseVcsEditorFactory(type),
|
||||
m_describeReceiver(describeReceiver),
|
||||
m_describeSlot(describeSlot)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Editor>
|
||||
VcsBaseEditorWidget *VcsEditorFactory<Editor>::createVcsBaseEditor(const VcsBaseEditorParameters *type,
|
||||
QWidget *parent)
|
||||
{
|
||||
VcsBaseEditorWidget *rc = new Editor(type, parent);
|
||||
rc->init();
|
||||
if (m_describeReceiver)
|
||||
connect(rc, SIGNAL(describeRequested(QString,QString)), m_describeReceiver, m_describeSlot);
|
||||
return rc;
|
||||
|
||||
}
|
||||
|
||||
} // namespace VcsBase
|
||||
|
||||
#endif // BASEVCSEDITORFACTORY_H
|
||||
|
||||
Reference in New Issue
Block a user