Exemplo n.º 1
0
void Dropper::handleInternalDrag( QDropEvent* dropEvent, AbstractByteArrayView* sourceByteArrayView )
{
    // get drag origin
    AddressRange selection = sourceByteArrayView->tableRanges()->removeSelection();

    ByteArrayTableCursor* tableCursor = mByteArrayView->tableCursor();
    AbstractByteArrayModel* byteArrayModel = mByteArrayView->byteArrayModel();

    Address insertIndex = tableCursor->realIndex();

    // is this a move?
    if( dropEvent->proposedAction() == Qt::MoveAction )
    {
        // ignore the copy hold in the event but only move
        Address newCursorIndex;
        // need to swap?
        if( selection.end() < insertIndex )
        {
            newCursorIndex = insertIndex;
            const Address firstIndex = selection.start();
            selection.set( selection.nextBehindEnd(), insertIndex-1 );
            insertIndex = firstIndex;
        }
        else
            newCursorIndex = insertIndex + selection.width();

        const bool success = byteArrayModel->swap( insertIndex, selection );
        if( success )
        {
            tableCursor->gotoCIndex( newCursorIndex );
            emit mByteArrayView->cursorPositionChanged( tableCursor->realIndex() );
        }
    }
    // is a copy
    else
    {
        // TODO: should this be a method of AbstractByteArrayModel, to reuse piece data?

        // get data
        const QByteArray data =
            dropEvent->mimeData()->data( QLatin1String(DropperOctetStreamFormatName) );

        if( !data.isEmpty() )
        {
            if( mByteArrayView->isOverwriteMode() )
            {
                const Size length = mByteArrayView->layout()->length();
                if( !tableCursor->isBehind() && length > 0 )
                {
                    AddressRange overwriteRange = AddressRange::fromWidth( insertIndex, data.size() );
                    overwriteRange.restrictEndTo( length-1 );
                    if( overwriteRange.isValid() )
                        byteArrayModel->replace( overwriteRange, reinterpret_cast<const Byte*>(data.constData()), overwriteRange.width() );
                }
            }
            else
                byteArrayModel->insert( insertIndex, reinterpret_cast<const Byte*>(data.constData()), data.size() );
        }
    }
}
Exemplo n.º 2
0
void AddressRangeTest::testSplitAtLocal()
{
    AddressRange addressRange( Start, End );

    // split at start
    AddressRange splitAddressRange = addressRange.splitAtLocal( 0 );
    QVERIFY( !addressRange.isValid() );
    QCOMPARE( splitAddressRange.start(), Start );
    QCOMPARE( splitAddressRange.end(),   End );

    // split at one after start
    addressRange.set( Start, End );
    splitAddressRange = addressRange.splitAtLocal( 1 );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(), Start );
    QCOMPARE( splitAddressRange.start(), Start+1 );
    QCOMPARE( splitAddressRange.end(),   End );

    // split at mid
    const Address Mid = Width/2;
    addressRange.set( Start, End );
    splitAddressRange = addressRange.splitAtLocal( Mid );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(), Start+Mid-1 );
    QCOMPARE( splitAddressRange.start(), Start+Mid );
    QCOMPARE( splitAddressRange.end(),   End );

    // split at one before end
    addressRange.set( Start, End );
    splitAddressRange = addressRange.splitAtLocal( Width-1 );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(), End-1 );
    QCOMPARE( splitAddressRange.start(), End );
    QCOMPARE( splitAddressRange.end(),   End );

    // split at start so the split is the full
    addressRange.set( Start, End );
    splitAddressRange = addressRange.splitAtLocal( Width );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(), End );
    QVERIFY( !splitAddressRange.isValid() );
}
Exemplo n.º 3
0
void AddressRangeTest::testRemoveLocal()
{
    const Address Mid = Width/2;
    AddressRange addressRange( Start, End );

    // remove none at start
    AddressRange removeAddressRange( 0, 0-1  );
    AddressRange splitAddressRange = addressRange.removeLocal( removeAddressRange );
    QVERIFY( !addressRange.isValid() );
    QCOMPARE( splitAddressRange.start(), Start );
    QCOMPARE( splitAddressRange.end(),   End );

    // remove one at start
    addressRange.set( Start, End );
    removeAddressRange.set( 0, 0 );
    splitAddressRange = addressRange.removeLocal( removeAddressRange );
    QVERIFY( !addressRange.isValid() );
    QCOMPARE( splitAddressRange.start(), Start+1 );
    QCOMPARE( splitAddressRange.end(),   End );

    // remove many at start
    addressRange.set( Start, End );
    removeAddressRange.set( 0, Mid );
    splitAddressRange = addressRange.removeLocal( removeAddressRange );
    QVERIFY( !addressRange.isValid() );
    QCOMPARE( splitAddressRange.start(), Start+Mid+1 );
    QCOMPARE( splitAddressRange.end(),   End );

    // remove all except last
    addressRange.set( Start, End );
    removeAddressRange.set( 0, Width-2 );
    splitAddressRange = addressRange.removeLocal( removeAddressRange );
    QVERIFY( !addressRange.isValid() );
    QCOMPARE( splitAddressRange.start(), End );
    QCOMPARE( splitAddressRange.end(),   End );

    // remove at mid
    addressRange.set( Start, End );
    removeAddressRange.set( Mid-1, Mid+1 );
    splitAddressRange = addressRange.removeLocal( removeAddressRange );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(), Start+Mid-2 );
    QCOMPARE( splitAddressRange.start(), Start+Mid+2 );
    QCOMPARE( splitAddressRange.end(),   End );

    // remove none at end
    addressRange.set( Start, End );
    removeAddressRange.set( Width, Width-1 );
    splitAddressRange = addressRange.removeLocal( removeAddressRange );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(),   End );
    QVERIFY( !splitAddressRange.isValid() );

    // remove one at end
    addressRange.set( Start, End );
    removeAddressRange.set( Width-1, Width-1 );
    splitAddressRange = addressRange.removeLocal( removeAddressRange );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(),   End-1 );
    QVERIFY( !splitAddressRange.isValid() );

    // remove many at end
    addressRange.set( Start, End );
    removeAddressRange.set( Mid, Width-1 );
    splitAddressRange = addressRange.removeLocal( removeAddressRange );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(),   Start+Mid-1 );
    QVERIFY( !splitAddressRange.isValid() );

    // remove all except first
    addressRange.set( Start, End );
    removeAddressRange.set( 1, Width-1 );
    splitAddressRange = addressRange.removeLocal( removeAddressRange );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(),   Start );
    QVERIFY( !splitAddressRange.isValid() );

    // remove all
    addressRange.set( Start, End );
    removeAddressRange.set( 0, Width-1 );
    splitAddressRange = addressRange.removeLocal( removeAddressRange );
    QVERIFY( !addressRange.isValid() );
    QVERIFY( !splitAddressRange.isValid() );
}
Exemplo n.º 4
0
void AddressRangeTest::testRemove()
{
    const Address Mid = (Start+End)/2;
    AddressRange addressRange( Start, End );

    // remove none at start
    AddressRange removeAddressRange( Start, Start-1  );
    AddressRange splitAddressRange = addressRange.remove( removeAddressRange );
    QVERIFY( !addressRange.isValid() );
    QCOMPARE( splitAddressRange.start(), Start );
    QCOMPARE( splitAddressRange.end(),   End );

    // remove one at start
    addressRange.set( Start, End );
    removeAddressRange.set( Start, Start );
    splitAddressRange = addressRange.remove( removeAddressRange );
    QVERIFY( !addressRange.isValid() );
    QCOMPARE( splitAddressRange.start(), Start+1 );
    QCOMPARE( splitAddressRange.end(),   End );

    // remove many at start
    addressRange.set( Start, End );
    removeAddressRange.set( Start, Mid );
    splitAddressRange = addressRange.remove( removeAddressRange );
    QVERIFY( !addressRange.isValid() );
    QCOMPARE( splitAddressRange.start(), Mid+1 );
    QCOMPARE( splitAddressRange.end(),   End );

    // remove all except last
    addressRange.set( Start, End );
    removeAddressRange.set( Start, End-1 );
    splitAddressRange = addressRange.remove( removeAddressRange );
    QVERIFY( !addressRange.isValid() );
    QCOMPARE( splitAddressRange.start(), End );
    QCOMPARE( splitAddressRange.end(),   End );

    // remove at mid
    addressRange.set( Start, End );
    removeAddressRange.set( Mid-1, Mid+1 );
    splitAddressRange = addressRange.remove( removeAddressRange );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(), Mid-2 );
    QCOMPARE( splitAddressRange.start(), Mid+2 );
    QCOMPARE( splitAddressRange.end(),   End );

    // remove none at end
    addressRange.set( Start, End );
    removeAddressRange.set( End+1, End );
    splitAddressRange = addressRange.remove( removeAddressRange );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(),   End );
    QVERIFY( !splitAddressRange.isValid() );

    // remove one at end
    addressRange.set( Start, End );
    removeAddressRange.set( End, End );
    splitAddressRange = addressRange.remove( removeAddressRange );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(),   End-1 );
    QVERIFY( !splitAddressRange.isValid() );

    // remove many at end
    addressRange.set( Start, End );
    removeAddressRange.set( Mid, End );
    splitAddressRange = addressRange.remove( removeAddressRange );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(),   Mid-1 );
    QVERIFY( !splitAddressRange.isValid() );

    // remove all except first
    addressRange.set( Start, End );
    removeAddressRange.set( Start+1, End );
    splitAddressRange = addressRange.remove( removeAddressRange );
    QCOMPARE( addressRange.start(), Start );
    QCOMPARE( addressRange.end(),   Start );
    QVERIFY( !splitAddressRange.isValid() );

    // remove all
    addressRange.set( Start, End );
    removeAddressRange.set( Start, End );
    splitAddressRange = addressRange.remove( removeAddressRange );
    QVERIFY( !addressRange.isValid() );
    QVERIFY( !splitAddressRange.isValid() );
}