diff options
Diffstat (limited to '')
| -rw-r--r-- | lsscenemodel.cpp | 81 | ||||
| -rw-r--r-- | lsscenemodel.h | 7 | 
2 files changed, 87 insertions, 1 deletions
| diff --git a/lsscenemodel.cpp b/lsscenemodel.cpp index e2e411c..48b32bd 100644 --- a/lsscenemodel.cpp +++ b/lsscenemodel.cpp @@ -11,6 +11,13 @@ LSSceneModel::LSSceneModel(LYTLayout *layout, QObject *parent) :  	m_paneIcons[LYTPane::TextBoxType] = LSGlobals::getIcon("textbox");  	m_paneIcons[LYTPane::WindowType] = LSGlobals::getIcon("window");  	m_paneIcons[LYTPane::BoundingType] = LSGlobals::getIcon("bounding"); + +	m_movingPaneParent = 0; +} + +LSSceneModel::~LSSceneModel() { +	if (m_movingPaneParent) +		delete m_movingPaneParent;  } @@ -83,5 +90,77 @@ Qt::ItemFlags LSSceneModel::flags(const QModelIndex &index) const {  Qt::DropActions LSSceneModel::supportedDropActions() const { -	return Qt::CopyAction | Qt::MoveAction; +	return Qt::MoveAction; +} + + +// I am doing a terrible, terrible, terrible thing here. +// I hate drag-and-drop. + +// As far as I can see, insertRows and removeRows are ONLY called by Qt when +// dragging something. So instead of doing a real insertion/removal... I'll +// store the intended destination, and once I'm told what pane needs to be +// removed (moved) I do the whole thing at once. + +bool LSSceneModel::insertRows(int row, int count, const QModelIndex &parent) { +	qDebug("LSSceneModel::insertRows(%d, %d, something)", row, count); + +	if (count != 1) { +		qWarning("huh, what? count != 1"); +		return false; +	} + +	if (m_movingPaneParent) { +		qWarning("huh, already moving something? dunno"); +		return false; +	} + +	m_movingPaneParent = new QPersistentModelIndex(parent); +	m_movingPaneRow = row; + +	return true; +} + +bool LSSceneModel::removeRows(int row, int count, const QModelIndex &parent) { +	qDebug("LSSceneModel::removeRows(%d, %d, something)", row, count); + +	if (count != 1) { +		qWarning("huh, what? count != 1"); +		return false; +	} + +	if (!m_movingPaneParent) { +		qWarning("huh, not moving anything? dunno"); +		return false; +	} + +	LYTPane *parentPane = (LYTPane*)parent.internalPointer(); +	LYTPane *pane = parentPane->children.at(row); + +	beginRemoveRows(parent, row, row); +	parentPane->children.removeAt(row); +	endRemoveRows(); + +	// now add it! +	LYTPane *newParentPane = (LYTPane*)m_movingPaneParent->internalPointer(); + +	// note: compensate for the offset: if we're moving the thing within the +	// same parent and the destination row is higher than the source row, then +	// removing the source row will have changed the index of the row the user +	// actually wanted to move the moved row to... what a terrible sentence :| +	if (*m_movingPaneParent == parent && m_movingPaneRow > row) +		m_movingPaneRow--; + +	beginInsertRows(*m_movingPaneParent, m_movingPaneRow, m_movingPaneRow); + +	pane->parent = newParentPane; +	newParentPane->children.insert(m_movingPaneRow, pane); + +	endInsertRows(); + +	delete m_movingPaneParent; +	m_movingPaneParent = 0; + +	return true;  } + diff --git a/lsscenemodel.h b/lsscenemodel.h index c769857..4dd1019 100644 --- a/lsscenemodel.h +++ b/lsscenemodel.h @@ -9,6 +9,7 @@ class LSSceneModel : public QAbstractItemModel {  	Q_OBJECT  public:  	explicit LSSceneModel(LYTLayout *layout, QObject *parent = 0); +	~LSSceneModel();  	LYTLayout *layout() const { return m_layout; } @@ -21,10 +22,16 @@ public:  	Qt::ItemFlags flags(const QModelIndex &index) const;  	Qt::DropActions supportedDropActions() const; +	bool insertRows(int row, int count, const QModelIndex &parent); +	bool removeRows(int row, int count, const QModelIndex &parent); +  private:  	LYTLayout *m_layout;  	QIcon m_paneIcons[LYTPane::PaneTypeCount]; + +	QPersistentModelIndex *m_movingPaneParent; +	int m_movingPaneRow;  signals: | 
