forked from qt-creator/qt-creator
QmlOutline: Don't allow drag&drop when outline is out of sync
The Outline is only updated (with a delay) if the current text is syntactically valid. Prevent the outline from changing the text underneath via drag&drop if the outline model is 'behind'. Reviewed-by: Christian Kamm
This commit is contained in:
@@ -28,9 +28,6 @@ namespace Internal {
|
|||||||
QmlOutlineItem::QmlOutlineItem(QmlOutlineModel *model) :
|
QmlOutlineItem::QmlOutlineItem(QmlOutlineModel *model) :
|
||||||
m_outlineModel(model)
|
m_outlineModel(model)
|
||||||
{
|
{
|
||||||
Qt::ItemFlags defaultFlags = flags();
|
|
||||||
setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags);
|
|
||||||
setEditable(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant QmlOutlineItem::data(int role) const
|
QVariant QmlOutlineItem::data(int role) const
|
||||||
@@ -242,8 +239,9 @@ private:
|
|||||||
int indent;
|
int indent;
|
||||||
};
|
};
|
||||||
|
|
||||||
QmlOutlineModel::QmlOutlineModel(QObject *parent) :
|
QmlOutlineModel::QmlOutlineModel(QmlJSTextEditor *editor) :
|
||||||
QStandardItemModel(parent)
|
QStandardItemModel(editor),
|
||||||
|
m_textEditor(editor)
|
||||||
{
|
{
|
||||||
m_icons = Icons::instance();
|
m_icons = Icons::instance();
|
||||||
const QString resourcePath = Core::ICore::instance()->resourcePath();
|
const QString resourcePath = Core::ICore::instance()->resourcePath();
|
||||||
@@ -335,6 +333,25 @@ bool QmlOutlineModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags QmlOutlineModel::flags(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return QStandardItemModel::flags(index);
|
||||||
|
|
||||||
|
Qt::ItemFlags flags = Qt::ItemIsSelectable|Qt::ItemIsEnabled;
|
||||||
|
|
||||||
|
// only allow drag&drop if we're in sync
|
||||||
|
if (m_semanticInfo.isValid()
|
||||||
|
&& m_semanticInfo.revision() == m_textEditor->editorRevision()) {
|
||||||
|
if (index.parent().isValid())
|
||||||
|
flags |= Qt::ItemIsDragEnabled;
|
||||||
|
if (index.data(ItemTypeRole) != NonElementBindingType)
|
||||||
|
flags |= Qt::ItemIsDropEnabled;
|
||||||
|
}
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Document::Ptr QmlOutlineModel::document() const
|
Document::Ptr QmlOutlineModel::document() const
|
||||||
{
|
{
|
||||||
return m_semanticInfo.document;
|
return m_semanticInfo.document;
|
||||||
|
|||||||
@@ -55,12 +55,13 @@ public:
|
|||||||
NonElementBindingType // can be filtered out
|
NonElementBindingType // can be filtered out
|
||||||
};
|
};
|
||||||
|
|
||||||
QmlOutlineModel(QObject *parent = 0);
|
QmlOutlineModel(QmlJSTextEditor *editor);
|
||||||
|
|
||||||
// QStandardItemModel
|
// QStandardItemModel
|
||||||
QStringList mimeTypes() const;
|
QStringList mimeTypes() const;
|
||||||
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||||
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
|
||||||
QmlJS::Document::Ptr document() const;
|
QmlJS::Document::Ptr document() const;
|
||||||
void update(const SemanticInfo &semanticInfo);
|
void update(const SemanticInfo &semanticInfo);
|
||||||
@@ -124,6 +125,7 @@ private:
|
|||||||
QHash<QmlOutlineItem*,QIcon> m_itemToIcon;
|
QHash<QmlOutlineItem*,QIcon> m_itemToIcon;
|
||||||
QHash<QmlOutlineItem*,QmlJS::AST::Node*> m_itemToNode;
|
QHash<QmlOutlineItem*,QmlJS::AST::Node*> m_itemToNode;
|
||||||
QHash<QmlOutlineItem*,QmlJS::AST::UiQualifiedId*> m_itemToIdNode;
|
QHash<QmlOutlineItem*,QmlJS::AST::UiQualifiedId*> m_itemToIdNode;
|
||||||
|
QmlJSTextEditor *m_textEditor;
|
||||||
|
|
||||||
|
|
||||||
friend class QmlOutlineModelSync;
|
friend class QmlOutlineModelSync;
|
||||||
|
|||||||
Reference in New Issue
Block a user