1 #include "mainwindow.h"
2 #include "standarditemmodel.h"
4 StandardItemModel::StandardItemModel( MainWindow
* aparent
) : p( aparent
) {
7 QStringList
StandardItemModel::mimeTypes() const {
9 types
<< "qsnip/itempointer";
10 types
<< "text/plain";
14 QMimeData
* StandardItemModel::mimeData( const QModelIndexList
&indexes
) const {
15 QMimeData
*mimeData
= new QMimeData();
16 QByteArray encodedData
;
18 QDataStream
stream( &encodedData
, QIODevice::WriteOnly
);
20 foreach( QModelIndex index
, indexes
) {
21 Snippet
* snippet
= p
->snippetForItem
.value( itemFromIndex( index
) );
22 stream
<< QString::number( (long)itemFromIndex( index
) );
23 if( !snippet
->isCategory() )
24 mimeData
->setText( snippet
->code() );
27 mimeData
->setData( "qsnip/itempointer", encodedData
);
31 bool StandardItemModel::dropMimeData( const QMimeData
*data
, Qt::DropAction action
,
32 int, int, const QModelIndex
&parent
) {
33 if( action
== Qt::IgnoreAction
)
36 QByteArray encodedData
= data
->data( "qsnip/itempointer" );
37 QDataStream
stream( &encodedData
, QIODevice::ReadOnly
);
40 while( !stream
.atEnd() ) {
46 QStandardItem
* itemToMove
= ( QStandardItem
* )newItems
.at( 0 ).toLong();
47 Snippet
* newParentSnippet
= p
->snippetForItem
.value( itemFromIndex( parent
) );
48 if( !newParentSnippet
)
49 newParentSnippet
= p
->snippetForItem
.value( invisibleRootItem() );
50 Snippet
* snippet
= p
->snippetForItem
.value( itemToMove
);
52 if( !snippet
|| !itemToMove
)
54 if( itemToMove
->parent() == itemFromIndex( parent
) )
56 if( !newParentSnippet
->isCategory() )
59 if( !itemToMove
->parent() )
60 itemToMove
= takeRow( itemToMove
->index().row() ).at( 0 );
62 itemToMove
= itemToMove
->parent()->takeRow( itemToMove
->index().row() ).at( 0 );
64 p
->insertItem( itemToMove
, p
->snippetForItem
.key( newParentSnippet
) );
69 Qt::DropActions
StandardItemModel::supportedDropActions() const {
70 return Qt::CopyAction
;