Exemplo n.º 1
0
void ItemPinnedSaver::onRowsRemoved(const QModelIndex &, int start, int end)
{
    if (!m_model || m_lastPinned < start)
        return;

    disconnect( m_model.data(), &QAbstractItemModel::rowsMoved,
                this, &ItemPinnedSaver::onRowsMoved );

    // Shift rows below removed down.
    const int rowCount = end - start + 1;
    for (int row = m_lastPinned - rowCount; row >= start; --row) {
        const auto index = m_model->index(row, 0);
        if ( isPinned(index) )
            moveRow(row, row + rowCount + 1);
    }

    connect( m_model.data(), &QAbstractItemModel::rowsMoved,
             this, &ItemPinnedSaver::onRowsMoved );
}
Exemplo n.º 2
0
void TableWidget::moveRowTo(){

    bool ok;
    int n = rowCount();
    int row = QInputDialog::getInt(this, "",
                                   tr("Move to row:"), 1, 1, n, 1, &ok)-1; // -1,let rows start at 1 instead of 0 for user
    if(!ok){
        return;
    }
    int current = currentRow();
    if( row<0 || row>=n ){
        QMessageBox::critical(this, "Move row "+QString::number(current)+" to:",
                              "Row nr out of bounds",QMessageBox::Ok,QMessageBox::Ok);
        return;
    }
    QAction *action = qobject_cast<QAction *>(sender());
    ColumnType t = (ColumnType)action->data().toInt();
    moveRow( current, row, t );
}
Exemplo n.º 3
0
void PlaylistModel::moveUp(Channel *channel)
{
    if (_channelNumbers.contains(channel->number()-1) && channel->number()-1 > 0) {
        if (moveRow(indexFromItem(channel).row(), indexFromItem(channel).row()-1)) {
            _numbers.remove(channel->number());
            _numbers[channel->number()-1]->setNumber(channel->number());
            _numbers.insert(channel->number(), _numbers[channel->number()-1]);
            _numbers.remove(channel->number()-1);
            channel->setNumber(channel->number()-1);
            _numbers.insert(channel->number(), channel);
        }
    } else if (channel->number()-1 > 0) {
        _channelNumbers.removeAll(channel->number());
        _numbers.remove(channel->number());
        channel->setNumber(channel->number()-1);
        _numbers.insert(channel->number(), channel);
        _channelNumbers << channel->number();
    }
}
Exemplo n.º 4
0
void ItemPinnedSaver::onRowsInserted(const QModelIndex &, int start, int end)
{
    if (!m_model || m_lastPinned < start) {
        updateLastPinned(start, end);
        return;
    }

    disconnect( m_model.data(), &QAbstractItemModel::rowsMoved,
                this, &ItemPinnedSaver::onRowsMoved );

    // Shift rows below inserted up.
    const int rowCount = end - start + 1;
    for (int row = end + 1; row <= m_lastPinned + rowCount; ++row) {
        const auto index = m_model->index(row, 0);
        if ( isPinned(index) )
            moveRow(row, row - rowCount);
    }

    connect( m_model.data(), &QAbstractItemModel::rowsMoved,
             this, &ItemPinnedSaver::onRowsMoved );
}
Exemplo n.º 5
0
void ItemPinnedSaver::onRowsMoved(const QModelIndex &, int start, int end, const QModelIndex &, int destinationRow)
{
    if (!m_model)
        return;

    if ( (m_lastPinned >= start || m_lastPinned >= destinationRow)
         && (end >= m_lastPinned || destinationRow >= m_lastPinned) )
    {
        if (start < destinationRow)
            updateLastPinned(start, destinationRow + end - start + 1);
        else
            updateLastPinned(destinationRow, end);
    }

    if (destinationRow != 0 || start < destinationRow)
        return;

    const int rowCount = end - start + 1;

    for (int row = destinationRow; row < destinationRow + rowCount; ++row) {
        if ( isPinned(m_model->index(row, 0)) )
            return;
    }

    disconnect( m_model.data(), &QAbstractItemModel::rowsMoved,
                this, &ItemPinnedSaver::onRowsMoved );

    // Shift rows below inserted up.
    for (int row = destinationRow + rowCount; row <= std::min(m_lastPinned, end); ++row) {
        const auto index = m_model->index(row, 0);
        if ( isPinned(index) )
            moveRow(row, row - rowCount);
    }

    connect( m_model.data(), &QAbstractItemModel::rowsMoved,
             this, &ItemPinnedSaver::onRowsMoved );
}
Exemplo n.º 6
0
void ItemViewWidget::moveUpRow()
{
	moveRow(true);
}
Exemplo n.º 7
0
void QgsGlobePluginDialog::on_elevationDown_clicked()
{
  moveRow( elevationDatasourcesWidget, false );
}
Exemplo n.º 8
0
void QgsGlobePluginDialog::on_elevationUp_clicked()
{
  moveRow( elevationDatasourcesWidget, true );
}
Exemplo n.º 9
0
bool KNMusicPlaylistModel::dropMimeData(const QMimeData *data,
                                        Qt::DropAction action,
                                        int row,
                                        int column,
                                        const QModelIndex &parent)
{
    //Check move or copy action enabled.
    if(action==Qt::MoveAction || action==Qt::CopyAction)
    {
        //Check if the drop operation is from a music model.
        if(data->hasFormat(ModelMimeType))
        {
            //Check whether the data is from it self.
            if(data->data(ModelMimeType).toLongLong()==(qint64)this)
            {
                //Generate the remove index list.
                QList<QPersistentModelIndex> sourceRowIndexes;
                //Translate the row list to source row indexes list.
                //We have to move the source indexes to the target positions.
                QJsonArray rawRowData=
                        QJsonDocument::fromBinaryData(
                            data->data(ModelRowList)).array();
                //Translate all the row into persistant list.
                for(auto i=rawRowData.begin(); i!=rawRowData.end(); ++i)
                {
                    //Add the target index to source row indexes.
                    sourceRowIndexes.append(index((*i).toInt(), Name));
                }
                //Sort the indexes as the row.
                //We want to sort the list from a greater row to lesser row.
                std::sort(sourceRowIndexes.begin(), sourceRowIndexes.end(),
                          [](const QModelIndex &left, const QModelIndex &right)
                          {return left.row()>right.row();});
                //Translate the target position to persistant index.
                int targetRow=(row==-1)?parent.row():row;
                QPersistentModelIndex targetIndex=
                        index((targetRow==-1)?rowCount()-1:targetRow, Name);
                //Move all the rows to target position.
                while(!sourceRowIndexes.isEmpty())
                {
                    //Get the source row.
                    int sourceRow=sourceRowIndexes.takeLast().row();
                    //Move the source row to target row.
                    moveRow(QModelIndex(), sourceRow,
                            QModelIndex(), targetIndex.row());
                }
                return true;
            }
            //We can simply parse the row information.
            QJsonArray rawRowData=
                    QJsonDocument::fromBinaryData(
                        data->data(ModelRowData)).array();
            //Generate a detail info list.
            QList<KNMusicDetailInfo> detailInfoList;
            //Parse all the data inside the array list.
            for(auto i=rawRowData.begin(); i!=rawRowData.end(); ++i)
            {
                //Add the detail info to the detail info list.
                detailInfoList.append(
                            KNMusicUtil::objectToDetailInfo((*i).toObject()));
            }
            //Check the row.
            if(row==-1)
            {
                //We have to move all of these data to the end of the model.
                appendRows(detailInfoList);
            }
            else
            {
                //We have to insert those rows to a specific positions.
                insertMusicRows(row, detailInfoList);
            }
            //Accept.
            return true;
        }
    }
    //Or others, throw it to KNMusicModel.
    return KNMusicModel::dropMimeData(data, action, row, column, parent);
}
Exemplo n.º 10
0
// Computer AI
// 1. Search for possible wins for me
// 2. Search for possible wins for opponent
// 3. Perform most strategic move
static void autoMove()
{
    // Can I win
    if (moveRow(PLAYER2)) 
	return;
    if (moveColumn(PLAYER2)) 
	return;
    if (moveDiagonal(PLAYER2)) 
	return;

    // Can he/she win
    if (moveRow(PLAYER1)) 
	return;
    if (moveColumn(PLAYER1)) 
	return;
    if (moveDiagonal(PLAYER1)) 
	return;

    // Most strategic move
    if (board[5] == NO_ONE)
    {
	board[5] = PLAYER2;
	return;
    }

    // Very Special cases
    if ((board[5] == PLAYER2) && (board[9] == NO_ONE) &&
	(board[8] == PLAYER1) && (board[3] == PLAYER1)) 
    {
	board[9] = PLAYER2;
	return;
    }

    if ((board[5] == PLAYER2) && (board[9] == NO_ONE) &&
	(board[7] == PLAYER1) && (board[6] == PLAYER1)) 
    {
	board[9] = PLAYER2;
	return;
    }

    if ((board[5] == PLAYER2) && (board[7] == NO_ONE) &&
	(board[8] == PLAYER1) && (board[1] == PLAYER1))
    {
	board[7] = PLAYER2;
	return;     
    }

    // Special cases
    int *r = 0;
    if ((board[5] == PLAYER2) && 
	(((board[1] == PLAYER1) && (board[9] == PLAYER1)) ||
	 ((board[3] == PLAYER1) && (board[7] == PLAYER1))))
    {
	static int rtmp[9] = {5, 2, 4, 6, 8, 1, 3, 7, 9};
	r = rtmp;
    }
    else if ((board[5] == PLAYER2) &&
	     (board[2] == PLAYER1) && (board[4] == PLAYER1))
    {
	static int rtmp[9] = {5, 1, 4, 6, 8, 2, 3, 7, 9};
	r = rtmp;
    }
    else if ((board[5] == PLAYER2) &&
	     (board[2] == PLAYER1) && (board[6] == PLAYER1))
    {
	static int rtmp[9] = {5, 3, 4, 6, 8, 1, 2, 7, 9};
	r = rtmp;
    } 
    else if ((board[5] == PLAYER2) &&
	     (board[8] == PLAYER1) && (board[4] == PLAYER1))
    {
	static int rtmp[9] = {5, 7, 4, 6, 8, 1, 3, 2, 9};
	r = rtmp;
    }
    else if ((board[5] == PLAYER2) &&
	     (board[8] == PLAYER1) && (board[6] == PLAYER1))
    {
	static int rtmp[9] = {5, 9, 4, 6, 8, 1, 3, 7, 2};
	r = rtmp;
    }
    else 
    {
	static int tics = 0;
	if (++tics % 10 == 0)
	{
	    // In one out of 10 cases, give the user a chance.
	    static int rtmp[9] = {5, 2, 4, 6, 8, 1, 3, 7, 9};
	    r = rtmp;
	}
	else
	{
	    static int rtmp[9] = {5, 1, 3, 7, 9, 2, 4, 6, 8};
	    r = rtmp;
	}
    }

    for (int i = 0; i < 9; i++)
	if (board[r[i]] == NO_ONE) {
	    board[r[i]] = PLAYER2;
	    return;
	}
}
Exemplo n.º 11
0
void TableWidget::moveRowDown(){
    QAction *action = qobject_cast<QAction *>(sender());
    ColumnType t = (ColumnType)action->data().toInt();
    int current = currentRow();
    moveRow( current, current+1, t );
}
Exemplo n.º 12
0
void ItemViewWidget::moveDownRow()
{
	moveRow(false);
}
Exemplo n.º 13
0
xpr_bool_t Splitter::moveTracking(const CPoint &aPoint)
{
    if (XPR_IS_NOT_NULL(mTrack) && XPR_IS_TRUE(mTrack->mSetCapture))
    {
        SetCursor(::LoadCursor(0, XPR_IS_FALSE(mTrack->mHorzSplitter) ? IDC_SIZEWE : IDC_SIZENS));

        xpr_sint_t sCapturedCoord = XPR_IS_FALSE(mTrack->mHorzSplitter) ? aPoint.x : aPoint.y;
        xpr_sint_t sCurPos = mTrack->mCurPos + (sCapturedCoord - mTrack->mCapturedCoord);

        //XPR_TRACE(XPR_STRING_LITERAL("OnMouseMove - %d\n", sCurPos));

        if (mMinPaneSize > 0 && sCurPos < mMinPaneSize) sCurPos = mMinPaneSize;
        if (mMaxPaneSize > 0 && sCurPos > mMaxPaneSize) sCurPos = mMaxPaneSize;

        xpr_sint_t sOffset = sCurPos - mTrack->mCurPos;

        if (XPR_IS_FALSE(mTrack->mHorzSplitter))
        {
            CSize sRightPaneSize(0, 0);
            getPaneSize(mTrack->mRow, mTrack->mColumn + 1, sRightPaneSize);

            if (mMinPaneSize > 0 && (sRightPaneSize.cx - sOffset) < mMinPaneSize)
                sCurPos -= mMinPaneSize - (sRightPaneSize.cx - sOffset);
        }
        else
        {
            CSize sRightPaneSize(0, 0);
            getPaneSize(mTrack->mRow + 1, mTrack->mColumn, sRightPaneSize);

            if (mMinPaneSize > 0 && (sRightPaneSize.cy - sOffset) < mMinPaneSize)
                sCurPos -= mMinPaneSize - (sRightPaneSize.cy - sOffset);
        }

        if (sCurPos != mTrack->mCurPos)
        {
            sOffset = sCurPos - mTrack->mCurPos; // recalculate offset

            mTrack->mCurPos = sCurPos;
            mTrack->mCapturedCoord += sOffset;

            XPR_TRACE(XPR_STRING_LITERAL("OnMouseMove - %d\n"), mTrack->mCurPos);

            if (XPR_IS_FALSE(mTrack->mHorzSplitter))
            {
                CSize sRightPaneSize(0, 0);
                getPaneSize(mTrack->mRow, mTrack->mColumn + 1, sRightPaneSize);

                moveColumn(mTrack->mColumn, mTrack->mCurPos);
                moveColumn(mTrack->mColumn + 1, sRightPaneSize.cx - sOffset);
            }
            else
            {
                moveRow(mTrack->mRow, mTrack->mCurPos);
            }

            //resize();
            //::UpdateWindow(mTrack->mHwnd);
        }

        return XPR_TRUE;
    }

    xpr_sint_t i;
    xpr_sint_t sSplitterCount = getSplitterCount();
    xpr_bool_t sSplitterHover = XPR_FALSE;
    xpr_bool_t sHorzSplitter = XPR_FALSE;
    CRect sSplitterRect;

    for (i = 0; i < sSplitterCount; ++i)
    {
        if (getSplitterRect(i, sSplitterRect, &sHorzSplitter) == XPR_FALSE)
            continue;

        if (sSplitterRect.PtInRect(aPoint) == XPR_TRUE)
        {
            sSplitterHover = XPR_TRUE;
            break;
        }
    }

    if (XPR_IS_TRUE(sSplitterHover))
    {
        SetCursor(::LoadCursor(0, XPR_IS_FALSE(sHorzSplitter) ? IDC_SIZEWE : IDC_SIZENS));
    }

    return XPR_FALSE;
}
Exemplo n.º 14
0
void TableViewWidget::moveDownRow()
{
	moveRow(false);
}
Exemplo n.º 15
0
void TableViewWidget::moveUpRow()
{
	moveRow(true);
}
Exemplo n.º 16
0
void movepiece(struct movement move) {
    
    moveRow(row_square - move.fromRow);
    moveCol(col_square - move.fromCol);
    
    row_square = move.toRow;
    col_square = move.toCol;
    
    CyDelay(5000);

    Em_Write(1);
    
    int rowdis = move.fromRow - move.toRow;
    int coldis = move.fromCol - move.toCol;
    
    //diagnal movement if clear path
    if (abs(rowdis) == abs(coldis)) {
        int temp = 0;
        for(int i = 1; i <= abs(coldis); i++) {
            if (board[move.fromRow + i * rowdis / abs(coldis)][move.fromCol + i * coldis / abs(coldis)] != 0) temp++;
        }
        if (temp == 0) {
            for(int i = 0; i < abs(coldis) * 51; i++) {
                move_x(coldis / abs(coldis));
                move_y(rowdis / abs(rowdis) * -1);
            }
        }
        return;
    }

    //col movement if clear path
    if (rowdis == 0) {
        int temp = 0;
        for(int i = 1; i <= abs(coldis); i++) {
            if (board[move.fromRow][move.fromCol + i * coldis / abs(coldis)] != 0) temp++;
        }
        moveCol(coldis);
        return;
    }

    //row movement if clear path
    if (coldis == 0) {
        int temp = 0;
        for(int i = 1; i <= abs(rowdis); i++) {
            if (board[move.fromRow + i * rowdis / abs(rowdis)][move.fromCol] != 0) temp++;
        }
        moveRow(rowdis);
        return;
    }

    //up or down indicator for end adjustment, where down is 1 and up -1
    //left or right indicator for end adjustment, where left is -1 and right is 1       
    int uod = 0, lor = 0;

    //determines the best path between spaces for cols

    if (move.fromCol < move.toCol) {
        lor = 1;
    } else if (move.fromCol > move.toCol) {
        lor = -1;
    } else if (move.fromCol < 6) {
        lor = 1;
    } else {
        lor = -1;
    }
    moveColHalf(lor * -1);

    //determines the best path between spaces for rows
    if (move.fromRow > move.toRow) {
        uod = -1;
    } else if (move.fromRow < move.toRow) {
        uod = 1;
    } else if (move.toRow < 4) {
        uod = -1;
    } else {
        uod = 1;
    }

    //moves across the rows with the adjustment
    if (rowdis == 0) {
        moveRowHalf(uod);
    } else if (rowdis > 0) {
        moveRowHalf(rowdis / abs(rowdis) * (rowdis * 2 - uod * -1));
    } else {
        moveRowHalf(rowdis / abs(rowdis) * (abs(rowdis) * 2 - uod));
    }
    //moves across the rows
    if (coldis == 0) {
        moveColHalf(lor);
    } else if (coldis > 0) {
        moveColHalf(coldis / abs(coldis) * (coldis * 2 - lor * -1));
    } else {
        moveColHalf(coldis / abs(coldis) * (abs(coldis) * 2 - lor));
    }

    //moves row adjustment
    moveRowHalf(-1 * uod);
    
    Em_Write(0);
    
}
Exemplo n.º 17
0
void Splitter::endTracking(const CPoint &aPoint)
{
    if (XPR_IS_NOT_NULL(mTrack) && XPR_IS_TRUE(mTrack->mSetCapture))
    {
        xpr_sint_t sCapturedCoord = XPR_IS_FALSE(mTrack->mHorzSplitter) ? aPoint.x : aPoint.y;
        xpr_sint_t sCurPos = mTrack->mCurPos + (sCapturedCoord - mTrack->mCapturedCoord);

        if (mMinPaneSize > 0 && sCurPos < mMinPaneSize) sCurPos = mMinPaneSize;
        if (mMaxPaneSize > 0 && sCurPos > mMaxPaneSize) sCurPos = mMaxPaneSize;

        xpr_sint_t sOffset = sCurPos - mTrack->mCurPos;

        if (XPR_IS_FALSE(mTrack->mHorzSplitter))
        {
            CSize sRightPaneSize(0, 0);
            getPaneSize(mTrack->mRow, mTrack->mColumn + 1, sRightPaneSize);

            if (mMinPaneSize > 0 && (sRightPaneSize.cx - sOffset) < mMinPaneSize)
                sCurPos -= mMinPaneSize - (sRightPaneSize.cx - sOffset);
        }
        else
        {
            CSize sRightPaneSize(0, 0);
            getPaneSize(mTrack->mRow + 1, mTrack->mColumn, sRightPaneSize);

            if (mMinPaneSize > 0 && (sRightPaneSize.cy - sOffset) < mMinPaneSize)
                sCurPos -= mMinPaneSize - (sRightPaneSize.cy - sOffset);
        }

        if (sCurPos != mTrack->mCurPos)
        {
            sOffset = sCurPos - mTrack->mCurPos;

            mTrack->mCurPos = sCurPos;
            mTrack->mCapturedCoord += sOffset;

            if (XPR_IS_FALSE(mTrack->mHorzSplitter))
            {
                CSize sRightPaneSize(0, 0);
                getPaneSize(mTrack->mRow, mTrack->mColumn + 1, sRightPaneSize);

                moveColumn(mTrack->mColumn, mTrack->mCurPos);
                moveColumn(mTrack->mColumn + 1, sRightPaneSize.cx - sOffset);
            }
            else
            {
                moveRow(mTrack->mRow, mTrack->mCurPos);
            }

            //resize();
            //::UpdateWindow(mTrack->mHwnd);
        }

        mTrack->mHover = XPR_FALSE;
        mTrack->mPressed = XPR_FALSE;
        mTrack->mPressedLeave = XPR_FALSE;

        mTrack->mSetCapture = XPR_FALSE;
        ::ReleaseCapture();

        ::InvalidateRect(mTrack->mHwnd, XPR_NULL, XPR_TRUE);
        //::UpdateWindow(mTrack->mHwnd);

        XPR_SAFE_DELETE(mTrack);
    }
}