Commit 87ed8746 authored by Kai Koehne's avatar Kai Koehne
Browse files

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
parent d1175f3e
......@@ -28,9 +28,6 @@ namespace Internal {
QmlOutlineItem::QmlOutlineItem(QmlOutlineModel *model) :
m_outlineModel(model)
{
Qt::ItemFlags defaultFlags = flags();
setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags);
setEditable(false);
}
QVariant QmlOutlineItem::data(int role) const
......@@ -242,8 +239,9 @@ private:
int indent;
};
QmlOutlineModel::QmlOutlineModel(QObject *parent) :
QStandardItemModel(parent)
QmlOutlineModel::QmlOutlineModel(QmlJSTextEditor *editor) :
QStandardItemModel(editor),
m_textEditor(editor)
{
m_icons = Icons::instance();
const QString resourcePath = Core::ICore::instance()->resourcePath();
......@@ -335,6 +333,25 @@ bool QmlOutlineModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
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
{
return m_semanticInfo.document;
......
......@@ -55,12 +55,13 @@ public:
NonElementBindingType // can be filtered out
};
QmlOutlineModel(QObject *parent = 0);
QmlOutlineModel(QmlJSTextEditor *editor);
// QStandardItemModel
QStringList mimeTypes() const;
QMimeData *mimeData(const QModelIndexList &indexes) const;
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;
void update(const SemanticInfo &semanticInfo);
......@@ -124,6 +125,7 @@ private:
QHash<QmlOutlineItem*,QIcon> m_itemToIcon;
QHash<QmlOutlineItem*,QmlJS::AST::Node*> m_itemToNode;
QHash<QmlOutlineItem*,QmlJS::AST::UiQualifiedId*> m_itemToIdNode;
QmlJSTextEditor *m_textEditor;
friend class QmlOutlineModelSync;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment