(#372) First step in Reimplemented drag and drop support

This commit is contained in:
Jacob Støren
2015-08-18 11:23:53 +02:00
parent eadf1ca300
commit 302f46b61b
15 changed files with 516 additions and 100 deletions

View File

@@ -62,6 +62,7 @@ set( PROJECT_FILES
cafPdmUiComboBoxEditor.h
cafPdmUiDoubleSliderEditor.cpp
cafPdmUiDoubleSliderEditor.h
cafPdmUiDragDropHandle.h
cafPdmUiFilePathEditor.cpp
cafPdmUiFilePathEditor.h
cafPdmUiLineEditor.cpp

View File

@@ -0,0 +1,64 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2015- Ceetron Solutions AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include <QModelIndexList>
class QMimeData;
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class PdmUiDragDropHandle
{
public:
virtual ~PdmUiDragDropHandle() = 0;
virtual Qt::DropActions supportedDropActions() const = 0;
virtual Qt::ItemFlags flags(const QModelIndex &index) const = 0;
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) = 0;
virtual QMimeData* mimeData(const QModelIndexList &indexes) const = 0;
virtual QStringList mimeTypes() const = 0;
};
inline PdmUiDragDropHandle::~PdmUiDragDropHandle() { }
} // end namespace caf

View File

@@ -171,5 +171,13 @@ QModelIndex PdmUiTreeView::findModelIndex(const PdmUiItem* object) const
return m_treeViewEditor->findModelIndex(object);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiTreeView::setDragDropHandle(PdmUiDragDropHandle* dragDropHandle)
{
m_treeViewEditor->setDragDropHandle(dragDropHandle);
}
} //End of namespace caf

View File

@@ -50,6 +50,7 @@ namespace caf
class PdmUiItem;
class PdmUiTreeViewEditor;
class PdmUiDragDropHandle;
//==================================================================================================
///
@@ -77,6 +78,8 @@ public:
PdmUiItem* uiItemFromModelIndex(const QModelIndex& index) const;
QModelIndex findModelIndex(const PdmUiItem* object) const;
void setDragDropHandle(PdmUiDragDropHandle* dragDropHandle);
signals:
void selectionChanged();

View File

@@ -290,5 +290,13 @@ QModelIndex PdmUiTreeViewEditor::findModelIndex(const PdmUiItem* object) const
return m_treeViewModel->findModelIndex(object);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiTreeViewEditor::setDragDropHandle(PdmUiDragDropHandle* dragDropHandle)
{
m_treeViewModel->setDragDropHandle(dragDropHandle);
}
} // end namespace caf

View File

@@ -59,6 +59,7 @@ namespace caf
class PdmUiItem;
class PdmUiTreeViewModel;
class PdmChildArrayFieldHandle;
class PdmUiDragDropHandle;
//--------------------------------------------------------------------------------------------------
///
@@ -96,6 +97,8 @@ public:
QWidget* createWidget(QWidget* parent);
void setDragDropHandle(PdmUiDragDropHandle* dragDropHandle);
signals:
void selectionChanged();

View File

@@ -39,6 +39,7 @@
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmUiDragDropHandle.h"
#include "cafPdmUiTreeItemEditor.h"
#include "cafPdmUiTreeOrdering.h"
#include "cafPdmUiTreeViewEditor.h"
@@ -54,6 +55,8 @@ namespace caf
PdmUiTreeViewModel::PdmUiTreeViewModel(PdmUiTreeViewEditor* treeViewEditor)
{
m_treeOrderingRoot = NULL;
m_dragDropHandle = NULL;
m_treeViewEditor = treeViewEditor;
}
@@ -658,6 +661,12 @@ Qt::ItemFlags PdmUiTreeViewModel::flags(const QModelIndex &index) const
}
}
if (m_dragDropHandle)
{
Qt::ItemFlags dragDropFlags = m_dragDropHandle->flags(index);
flagMask |= dragDropFlags;
}
return flagMask;
}
@@ -692,5 +701,73 @@ PdmUiItem* PdmUiTreeViewModel::uiItemFromModelIndex(const QModelIndex& index) co
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiTreeViewModel::setDragDropHandle(PdmUiDragDropHandle* dragDropHandle)
{
m_dragDropHandle = dragDropHandle;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList PdmUiTreeViewModel::mimeTypes() const
{
if (m_dragDropHandle)
{
return m_dragDropHandle->mimeTypes();
}
else
{
return QAbstractItemModel::mimeTypes();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QMimeData * PdmUiTreeViewModel::mimeData(const QModelIndexList &indexes) const
{
if (m_dragDropHandle)
{
return m_dragDropHandle->mimeData(indexes);
}
else
{
return QAbstractItemModel::mimeData(indexes);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmUiTreeViewModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
if (m_dragDropHandle)
{
return m_dragDropHandle->dropMimeData(data, action, row, column, parent);
}
else
{
return QAbstractItemModel::dropMimeData(data, action, row, column, parent);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Qt::DropActions PdmUiTreeViewModel::supportedDropActions() const
{
if (m_dragDropHandle)
{
return m_dragDropHandle->supportedDropActions();
}
else
{
return QAbstractItemModel::supportedDropActions();
}
}
} // end namespace caf

View File

@@ -49,6 +49,7 @@ class PdmObjectHandle;
class PdmUiItem;
class PdmUiTreeViewEditor;
class PdmUiTreeOrdering;
class PdmUiDragDropHandle;
//==================================================================================================
//
@@ -73,6 +74,8 @@ public:
PdmUiItem* uiItemFromModelIndex(const QModelIndex& index) const;
QModelIndex findModelIndex(const PdmUiItem* object) const;
void setDragDropHandle(PdmUiDragDropHandle* dragDropHandle);
private:
void updateSubTreeRecursive(const QModelIndex& uiSubTreeRootModelIdx, PdmUiTreeOrdering* uiModelSubTreeRoot, PdmUiTreeOrdering* updatedPdmSubTreeRoot);
@@ -90,6 +93,8 @@ private:
PdmUiTreeViewEditor* m_treeViewEditor;
PdmUiDragDropHandle* m_dragDropHandle;
private:
// Overrides from QAbstractItemModel
@@ -105,6 +110,11 @@ private:
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
virtual QStringList mimeTypes() const;
virtual QMimeData* mimeData(const QModelIndexList &indexes) const;
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
virtual Qt::DropActions supportedDropActions() const;
};