Example #1
0
void GraphicalModelAssistApi::removeElement(const Id &graphicalId)
{
	const QPersistentModelIndex index = indexById(graphicalId);
	if (graphicalRepoApi().exist(graphicalId) && index.isValid()) {
		mGraphicalModel.removeRow(index.row(), index.parent());
	}
}
Example #2
0
void ModelTest::layoutChanged()
{
    for ( int i = 0; i < changing.count(); ++i ) {
        QPersistentModelIndex p = changing[i];
        Q_ASSERT ( p == model->index ( p.row(), p.column(), p.parent() ) );
    }
    changing.clear();
}
Example #3
0
void Helper::layoutChanged()
{
    for ( int i = 0; i < changing.count(); ++i ) {
        QPersistentModelIndex p = changing[i];
        QVERIFY( p == model->index ( p.row(), p.column(), p.parent() ) );
    }
    changing.clear();
}
Example #4
0
//-----------------------------------------------------------------------------
void ctkModelTester::testPersistentModelIndex(const QPersistentModelIndex& index)const
{
  CTK_D(const ctkModelTester);
  //qDebug() << "Test persistent Index: " << index ;
  this->test(index.isValid(), "Persistent model index can't be invalid");
  // did you forget to call QAbstractItemModel::changePersistentIndex() between 
  // beginLayoutChanged() and changePersistentIndex() ?
  QModelIndex modelIndex = d->Model->index(index.row(), index.column(), index.parent());
  this->test(modelIndex == index, 
             QString("Persistent index (%1, %2) can't be invalid").arg(index.row()).arg(index.column()));
}
Example #5
0
void VisualMusicModel::itemRowSequenceChanged(VisualItem *visualItem)
{
    if (!(visualItem->graphicalType() == VisualItem::GraphicalRowType))
        return;

    if (!m_visualItemIndexes.values().contains(visualItem))
        return;

    int scoreRow = 0;
    QPersistentModelIndex index = m_visualItemIndexes.key(visualItem);
    switch (visualItem->itemType()) {
    case VisualItem::NoVisualItem:
        break;
    case VisualItem::VisualScoreItem: {
        scoreRow = index.row();
        break;
    }
    case VisualItem::VisualTuneItem: {
        scoreRow = index.parent().row();
        break;
    }
    case VisualItem::VisualPartItem: {
        scoreRow = index.parent().parent().row();
        break;
    }
    case VisualItem::VisualMeasureItem: {
        scoreRow = index.parent().parent().parent().row();
        break;
    }
    case VisualItem::VisualSymbolItem: {
        scoreRow = index.parent().parent().parent().parent().row();
        break;
    }
    }

    emit scoreRowSequenceChanged(scoreRow);
}
Example #6
0
void MOTableView::startDrag(Qt::DropActions supportedActions)
{
    qDebug() << "MOTableView::startDrag; begin";
    QModelIndexList indexes = selectedIndexes();
    QList<QPersistentModelIndex> persistentIndexes;

    if (indexes.count() > 0) {
        QMimeData *data = model()->mimeData(indexes);
        if (!data)
            return;
        for (int i = 0; i<indexes.count(); i++){
            QModelIndex idx = indexes.at(i);
            persistentIndexes.append(QPersistentModelIndex(idx));
        }

        QPixmap pixmap = indexes.first().data(Qt::DecorationRole).value<QPixmap>();
        QDrag *drag = new QDrag(this);
        drag->setPixmap(pixmap);
        drag->setMimeData(data);
        drag->setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2));

        Qt::DropAction defaultDropAction = Qt::IgnoreAction;
        if (supportedActions & Qt::MoveAction && dragDropMode() != QAbstractItemView::InternalMove)
            defaultDropAction = Qt::MoveAction; //was Qt::CopyAction THIS WAS THE CULPRIT!

        if ( drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction ){
            //when we get here any copying done in dropMimeData has messed up our selected indexes
            //that's why we use persistent indexes
            for (int i = 0; i<indexes.count(); i++){
                QPersistentModelIndex idx = persistentIndexes.at(i);
                if (idx.isValid()){ //the item is not top level
                    model()->removeRow(idx.row(), idx.parent());
                }
                else{
                    model()->removeRow(idx.row(), QModelIndex());
                }
            }
        }
    }
    qDebug() << "MOTableView::startDrag; end";
}