コード例 #1
0
ファイル: launchermodel.cpp プロジェクト: papyros/protoshell
bool LauncherModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
                             const QModelIndex &destinationParent, int destinationChild)
{
    QList<Application *> tmp;

    Q_UNUSED(sourceParent);
    Q_UNUSED(destinationParent);

    if (sourceRow + count - 1 < destinationChild) {
        beginMoveRows(QModelIndex(), sourceRow, sourceRow + count - 1, QModelIndex(),
                      destinationChild + 1);
        for (int i = sourceRow; i < sourceRow + count; i++) {
            Q_ASSERT(m_list[i]);
            tmp << m_list.takeAt(i);
        }
        for (int i = 0; i < count; i++) {
            Q_ASSERT(tmp[i]);
            m_list.insert(destinationChild - count + 2 + i, tmp[i]);
        }
        endMoveRows();
    } else if (sourceRow > destinationChild) {
        beginMoveRows(QModelIndex(), sourceRow, sourceRow + count - 1, QModelIndex(),
                      destinationChild);
        for (int i = sourceRow; i < sourceRow + count; i++) {
            Q_ASSERT(m_list[i]);
            tmp << m_list.takeAt(i);
        }
        for (int i = 0; i < count; i++) {
            Q_ASSERT(tmp[i]);
            m_list.insert(destinationChild + i, tmp[i]);
        }
        endMoveRows();
    }
    return true;
}
コード例 #2
0
ファイル: listmodel.cpp プロジェクト: Pandahisham/outliner
QModelIndex ListModel::moveItemHorizontal(const QModelIndex& index, int direction)
{
    ListItem* item = itemFromIndex(index);
    if (!item)
        return index;

    ListItem* parent = item->parent();
    int row = item->row();

    if (direction == App::Left) { // reparent as child of parent's parent
        if (!parent || parent->isRoot()) // already top level item
            return index;

        ListItem* newParent = parent->parent();
        int newRow = parent->row() + 1;

        QSqlDatabase db = QSqlDatabase::database();
        db.transaction();
        if (parent->takeChildDb(row) &&
            item->setParentDb(newParent, newRow)) {
            db.commit();
            if (beginMoveRows(indexFromItem(parent), row, row, indexFromItem(newParent), newRow)) {
                newParent->insertChild(newRow, parent->takeChild(row));
                endMoveRows();
            }
            return indexFromItem(item);
        } else {
            db.rollback();
            return index;
        }
    } else { // move as child of previous sibling
        ListItem* newParent = parent->child(row - 1);
        if (!newParent)
            return index;

        QSqlDatabase db = QSqlDatabase::database();
        db.transaction();
        if (parent->takeChildDb(row) &&
            item->setParentDb(newParent, newParent->childCount())) {
            db.commit();
            if (beginMoveRows(indexFromItem(parent), row, row, indexFromItem(newParent), newParent->childCount())) {
                newParent->appendChild(parent->takeChild(row));
                endMoveRows();
            }
            newParent->setExpanded(true);
            return indexFromItem(item);
        } else {
            db.rollback();
            return index;
        }
    }
}
コード例 #3
0
ファイル: rssmodel.cpp プロジェクト: glassez/qBittorrent
void RSSModel::itemPathChanged(RSS::Item *rssItem)
{
    const auto itemIndex = index(rssItem);
    const auto parentIndex = itemIndex.parent();
    beginMoveRows(itemIndex.parent(), itemIndex.row(), itemIndex.row(), parentIndex, 0);
    endMoveRows();
}
コード例 #4
0
void RecentProjectsModel::setLastRecentProject(const FilePath& filepath)
{
    // if the filepath is already in the list, we just have to move it to the top of the list
    for (int i = 0; i < mRecentProjects.count(); i++)
    {
        if (mRecentProjects.at(i).toStr() == filepath.toStr())
        {
            if (i == 0)
                return; // the filename is already on top of the list, so nothing to do here...

            beginMoveRows(QModelIndex(), i, i, QModelIndex(), 0);
            mRecentProjects.move(i, 0);
            endMoveRows();
            save();
            return;
        }
    }

    // limit the maximum count of entries in the list
    while (mRecentProjects.count() >= 5)
    {
        beginRemoveRows(QModelIndex(), mRecentProjects.count()-1, mRecentProjects.count()-1);
        mRecentProjects.takeLast();
        endRemoveRows();
    }

    // add the new filepath to the list
    beginInsertRows(QModelIndex(), 0, 0);
    mRecentProjects.prepend(filepath);
    endInsertRows();
    save();
}
コード例 #5
0
ファイル: clipboardmodel.cpp プロジェクト: GabLeRoux/CopyQ
void ClipboardModel::sortItems(const QModelIndexList &indexList, CompareItems *compare)
{
    QList<QPersistentModelIndex> list = validIndeces(indexList);
    qSort( list.begin(), list.end(), compare );

    int targetRow = topMostRow(list);

    foreach (const QPersistentModelIndex &ind, list) {
        if (ind.isValid()) {
            const int sourceRow = ind.row();

            if (targetRow != sourceRow) {
                beginMoveRows(QModelIndex(), sourceRow, sourceRow, QModelIndex(), targetRow);
                m_clipboardList.move(sourceRow, targetRow);
                endMoveRows();

                // If the moved item was removed or moved further (as reaction on moving the item),
                // stop sorting.
                if (!ind.isValid() || ind.row() != targetRow)
                    break;
            }

            ++targetRow;
        }
    }
}
コード例 #6
0
ファイル: timeline.cpp プロジェクト: emdash/QT-GES-Demo
void Timeline::
privMoveObject(int source, int dest)
{
  QModelIndex parent;

  /* FIXME: currently ignoring the 'n' parameter */
  /* FIXME: there's something I don't understand about the API,
     because it seems to be impossible to increment an item's position
     by one. So if the destination is one greater than the source,
     swap dest and source. It seems to work fine.
  */

  if (dest == (source + 1))
  {
    swap(source, dest);
  }

  qDebug() << source << dest;
  if (!beginMoveRows(parent, source, source, parent, dest))
  {
    qDebug() << "early exit";
    return;
  }
  endMoveRows();
}
コード例 #7
0
ファイル: listmodel.cpp プロジェクト: Pandahisham/outliner
QModelIndex ListModel::moveItemVertical(const QModelIndex& index, App::Direction direction)
{
    ListItem* item = itemFromIndex(index);
    if (!item)
        return index;

    int row = item->row();
    if (direction == App::Up && row == 0)
        return index;

    ListItem* parent = item->parent();
    if (direction == App::Down && row == (parent->childCount() - 1))
        return index;

    ListItem* otherItem = parent->child(direction == App::Up ? row - 1 : row + 1);
    int downRow = direction == App::Down ? row : row - 1; // the row that is being moved down

    QSqlDatabase db = QSqlDatabase::database();
    db.transaction();

    if (item->setRow(direction == App::Down ? row + 1 : row - 1) &&
        otherItem->setRow(row)) {
        db.commit();
        if (beginMoveRows(index.parent(), downRow, downRow, index.parent(), downRow + 2)) {
            parent->moveChild(downRow);
            endMoveRows();
            return indexFromItem(item);
        }
    } else
        db.rollback();
    return index;
}
コード例 #8
0
ファイル: CategoryModel.cpp プロジェクト: lawadr/gridiron
bool CategoryModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) {
    if (action == Qt::IgnoreAction)
        return true;

    if (!data->hasFormat("application/editor.categorymodel.index"))
        return false;

    QByteArray encodedData = data->data("application/editor.categorymodel.index");
    QDataStream stream(&encodedData, QIODevice::ReadOnly);

    QList<Item*> items;

    while (!stream.atEnd()) {
        quint64 address;
        stream >> address;
        Item* item = reinterpret_cast<Item*>(address);
        items.push_back(item);
    }

    Category* category = static_cast<Category*>(parent.internalPointer());

    for (QList<Item*>::const_iterator it = items.begin(); it != items.end(); ++it) {
        Item* item = *it;
        if (!item->isCategory() || !item->toCategory()->isAncestorOf(category)) {
            QModelIndex parentIndex = createIndex(item->parent()->childNumber(), 1, item->parent());
            if (parentIndex != parent) {
                beginMoveRows(parentIndex, item->childNumber(), item->childNumber(), parent, rowCount(parent));
                category->addChild(item);
                endMoveRows();
            }
        }
    }

    return true;
}
コード例 #9
0
Q_INVOKABLE void ApplicationListModel::moveItem(int row, int destination)
{
    if (row < 0 || destination < 0 || row >= m_applicationList.length() ||
        destination >= m_applicationList.length() || row == destination) {
        return;
    }
    if (destination > row) {
        ++destination;
    }

    beginMoveRows(QModelIndex(), row, row, QModelIndex(), destination);
    if (destination > row) {
        ApplicationData data = m_applicationList.at(row);
        m_applicationList.insert(destination, data);
        m_applicationList.takeAt(row);
    } else {
        ApplicationData data = m_applicationList.takeAt(row);
        m_applicationList.insert(destination, data);
    }


    m_appOrder.clear();
    m_appPositions.clear();
    int i = 0;
    for (auto app : m_applicationList) {
        m_appOrder << app.storageId;
        m_appPositions[app.storageId] = i;
        ++i;
    }


    emit appOrderChanged();
    endMoveRows();
}
コード例 #10
0
ファイル: qgscomposermodel.cpp プロジェクト: GeoCat/QGIS
bool QgsComposerModel::reorderItemToBottom( QgsComposerItem *item )
{
  if ( !item || !mItemsInScene.contains( item ) )
  {
    return false;
  }

  if ( mItemsInScene.last() == item )
  {
    //item is already lowest item present in scene, nothing to do
    return false;
  }

  //move item in z list
  QMutableListIterator<QgsComposerItem *> it( mItemZList );
  if ( it.findNext( item ) )
  {
    it.remove();
  }
  mItemZList.push_back( item );

  //also move item in scene items z list and notify of model changes
  QModelIndex itemIndex = indexForItem( item );
  if ( !itemIndex.isValid() )
  {
    return true;
  }

  //move item to bottom
  int row = itemIndex.row();
  beginMoveRows( QModelIndex(), row, row, QModelIndex(), rowCount() );
  refreshItemsInScene();
  endMoveRows();
  return true;
}
コード例 #11
0
bool TreeItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
    if (action == Qt::IgnoreAction){
        return true;
    }
    TreeItem* targetNode = getItem(parent);
    qDebug("Action = %d", action);
    qDebug("Original row = %d and col %d", row, column);
    int dstRow;
    if (row != -1)
        dstRow = row;
    else if (parent.isValid())
        dstRow = 0;
    else
        dstRow = rowCount(QModelIndex());

    const TreeModelMimeData * mimeData = dynamic_cast<const TreeModelMimeData*>(data);
    if(mimeData){
        foreach (const QModelIndex &index, mimeData->indexes()) {
            if (index.isValid()) {
                TreeItem* item = getItem(index);

                if(dstRow>=0 && dstRow<targetNode->childCount()){
                    TreeItem* sibling = targetNode->child(dstRow);
                    qDebug()<<"Sibling is "<<sibling->id();
                    if(!_modelPersistence->moveBeforeNode(item, sibling)){
                        return false;
                    }
                }
                else{
                    if(!_modelPersistence->reparentNode(item, targetNode)){
                        return false;
                    }

                }
                int srcRow = index.row();
                qDebug("beginMoveRows from %d to %d", srcRow, dstRow);
                qDebug()<<"Item is "<<index.row()<<" col "<<index.column()<<" with "<<srcRow;
                qDebug()<<"Parent is "<<parent.row()<<" col "<<parent.column()<<" with "<<dstRow;
                if(!beginMoveRows(index,srcRow,srcRow, parent,dstRow)){
                    qDebug("beginMoveRows returned false");
                    return false;
                }

                if(targetNode==item->parent()){
                    if(srcRow<=dstRow)
                        dstRow--;
                    qDebug("Moving from %d to %d", srcRow, dstRow);
                    item->parent()->moveChild(srcRow, dstRow);
                }
                else{
                    qDebug("Reparenting node to row %d", dstRow);
                    targetNode->insertChild(dstRow,item);
                }
                endMoveRows();
            }
        }
        return true;
    }
    else if(data->hasFormat(PART_MIME_TYPE)){
コード例 #12
0
ファイル: cellmodel.cpp プロジェクト: EPRC/project_kagami
bool CellModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
{
    Cell* srcCell;
    Cell* desCell;
    bool result = true;

    if (!sourceParent.isValid())
        srcCell = topCell;
    else
        srcCell = getCellByIndex(sourceParent);

    if (!destinationParent.isValid())
        desCell = topCell;
    else
        desCell = getCellByIndex(destinationParent);

    if (sourceRow+count-1 > srcCell->childCount() || destinationChild > desCell->childCount())
        return false;

    beginMoveRows(sourceParent,sourceRow,sourceRow+count-1,destinationParent,destinationChild);
        for (int i=0; i<count; i++){
            result &= desCell->insertChildren(destinationChild,1,srcCell->getChild(sourceRow));
            result &= srcCell->removeChildren(sourceRow,1,false);
        }
    endMoveRows();

    return result;
}
コード例 #13
0
bool SceneFilter::moveRows(const QModelIndex &sourceParent, int sourceRow,
                           int count, const QModelIndex &destinationParent,
                           int destinationChild)
{
    beginMoveRows(sourceParent, sourceRow, sourceRow+(count-1), destinationParent,
                  destinationChild);

    endMoveRows();
}
コード例 #14
0
void PagedProxyModel::sourceRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
{
    const int pageStart = (m_currentPage*m_pageSize);
    int newStart = qMin(m_pageSize, qMax(0, sourceStart - pageStart));
    int newEnd = qMin(m_pageSize, newStart + (sourceEnd - sourceStart));
    int newDestinationRow = qMin(m_pageSize, qMax(0, destinationRow - pageStart));

    emit beginMoveRows(sourceParent, newStart, newEnd, destinationParent, newDestinationRow);
    endMoveRows();
}
コード例 #15
0
void IOSignalModel::down(int index)
{
    if(index < 0 || index >= (mIOSignals.count() - 1))
        return;

    beginMoveRows(QModelIndex(), index + 1, index + 1, QModelIndex(), index);
    IOSignal *sig = mIOSignals.at(index);
    mIOSignals[index] = mIOSignals.at(index + 1);
    mIOSignals[index + 1] = sig;
    endMoveRows();
}
コード例 #16
0
ファイル: main.cpp プロジェクト: KDE/kdiagram
    void moveRow( int from, int to ) {
        if ( from == to ) return;
        if ( from >= m_tasks.size() || to >= m_tasks.size()+1 ) return;

        if ( beginMoveRows( QModelIndex(), from, from, QModelIndex(), to ) ) {
            m_tasks.move( from, to );
            endMoveRows();
        } else {
            assert( 0 );
        }
    }
コード例 #17
0
/**
 * @brief Moves a direction.
 * @param index Index of the direction to move.
 * @param new_direction_nb The new number of the direction.
 * @throws EditorException in case of error.
 */
void SpriteModel::move_direction(const Index& index, int new_direction_nb) {

  if (new_direction_nb == index.direction_nb) {
    // Nothing to do.
    return;
  }

  // Make some checks first.
  if (!direction_exists(index)) {
      QString nb = std::to_string(index.direction_nb).c_str();
      throw EditorException(
            tr("Direction %1 don't exists in animation '%2'").arg(
              nb, index.animation_name));
  }

  // Save and clear the selection.
  Index selection = get_selected_index();
  clear_selection();

  // Move the direction in the sprite file.
  get_animation(index).move_direction(index.direction_nb, new_direction_nb);

  // Call beginMoveRows() as requested by QAbstractItemModel.
  int above_row = new_direction_nb;
  if (new_direction_nb > index.direction_nb) {
    ++above_row;
  }
  QModelIndex model_index = get_model_index(Index(index.animation_name));
  beginMoveRows(model_index, index.direction_nb, index.direction_nb,
                model_index, above_row);

  // Update our animation model list.
  int animation_nb = get_animation_nb(index);
  animations[animation_nb].directions.move(index.direction_nb, new_direction_nb);

  // Update direction model indexes.
  int num_dir = animations[animation_nb].directions.size();
  for (int nb = 0; nb < num_dir; nb++) {
    animations[animation_nb].directions[nb].index->direction_nb = nb;
  }

  endMoveRows();

  // Notify people before restoring the selection, so that they have a
  // chance to know new indexes before receiving selection signals.
  emit direction_deleted(index);

  // Restore the selection.
  if (selection.direction_nb == index.direction_nb) {
    selection.direction_nb = new_direction_nb;
  }

  set_selected_index(selection);
}
コード例 #18
0
ファイル: levellistmodel.cpp プロジェクト: utamons/reditor
void LevelListModel::up(const QModelIndex &idx) {
    Level *l = levelFromIndex(idx);
    int row = idx.row();
    if (idx.isValid() && row > 0) {
        beginMoveRows(QModelIndex(),row,row,QModelIndex(),row-1);
        Level *before = (*levels)[row-1];
        (*levels)[row-1] = l;
        (*levels)[row] = before;
        endMoveRows();
    }
}
コード例 #19
0
void DataStore::moveItemDown( int row )
{
    if ( row >= 0 && row < m_datasetList.size() - 1 )
    {
        beginMoveRows( index( row, 0 ), row, row, index( row + 1, 0 ), row + 1 );
        m_datasetList.swap( row, row + 1 );
        endMoveRows();
        updateGlobals( row );
        emit ( dataChanged( index( 0, 0 ), index( 0, 0 ) ) );
    }
}
コード例 #20
0
ファイル: nmproxy.cpp プロジェクト: palinek/nm-tray
void NmProxy::onSourceRowsAboutToBeMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
{
    if (root == sourceParent)
    {
        if (root == destinationParent)
            beginMoveRows(mapFromSource(sourceParent), sourceStart, sourceEnd, destinationParent, destinationRow);
        else
            beginRemoveRows(mapFromSource(sourceParent), sourceStart, sourceEnd);
    } else if (root == destinationParent)
        beginInsertRows(mapFromSource(destinationParent), destinationRow, destinationRow + (sourceEnd - sourceStart));
}
コード例 #21
0
void IOSignalModel::up(int index)
{
    if(index < 1 || index >= mIOSignals.count())
        return;

    beginMoveRows(QModelIndex(), index, index, QModelIndex(), index - 1);
    IOSignal *sig = mIOSignals.at(index);
    mIOSignals[index] = mIOSignals.at(index - 1);
    mIOSignals[index - 1] = sig;
    endMoveRows();
}
コード例 #22
0
ファイル: playlistmodel.cpp プロジェクト: deedos/shotcut
bool PlaylistModel::removeRows(int row, int count, const QModelIndex& parent)
{
    if (!m_playlist) return false;
    if (row == m_dropRow) return false;
    beginMoveRows(parent, row, row, parent, m_dropRow);
    m_playlist->move(row, m_dropRow);
    endMoveRows();
    m_dropRow = -1;
    emit modified();
    return true;
}
コード例 #23
0
bool PersonsTableModel::moveDown(const QModelIndex &index)
{
    Q_D(PersonsTableModel);
    if(index.row() == d->persons.size()-1)
        return false;
    if(!beginMoveRows(QModelIndex(), index.row(), index.row(), QModelIndex(), index.row()+2))
        return false;
    d->persons.swap(index.row(), index.row()+1);
    endMoveRows();
    return true;
}
コード例 #24
0
ファイル: valuemodel.cpp プロジェクト: 4lenz1/qmlbook
// move a row to another position
void ValueModel::move(int fromRow, int toRow)
{
    if(fromRow < 0 || toRow < 0 || fromRow >= m_data.count() || toRow >= m_data.count()) {
        return;
    }
    if (!beginMoveRows(QModelIndex(), fromRow, fromRow, QModelIndex(), toRow > fromRow ? toRow+1 : toRow)) {
        return;
    }
    m_data.move(fromRow, toRow);
    endMoveRows();
}
コード例 #25
0
ファイル: qobjectlistmodel.cpp プロジェクト: saukko/lipstick
void QObjectListModel::move(int oldRow, int newRow)
{
    if (oldRow < 0 || oldRow >= _list->count())
        return;

    if (newRow < 0 || newRow >= _list->count())
        return;

    beginMoveRows(QModelIndex(), oldRow, oldRow, QModelIndex(), (newRow > oldRow) ? (newRow + 1) : newRow);
    _list->move(oldRow, newRow);
    endMoveRows();
}
コード例 #26
0
void PropertyBasedTableModel::moveRowDown(int position)
{
	int count = content->count();
	if (count < 2 || position < 0 || position > (count - 2))
		return;

	beginMoveRows(QModelIndex(), position, position, QModelIndex(), position+2);

	content->move(position, position + 1);

	endMoveRows();
}
コード例 #27
0
void PropertyBasedTableModel::moveRowUp(int position)
{
	int count = content->count();
	if (count < 2 || position < 1 || position >= count)
		return;

	beginMoveRows(QModelIndex(), position, position, QModelIndex(), position-1);

	content->move(position, position - 1);

	endMoveRows();
}
コード例 #28
0
ファイル: ModList.cpp プロジェクト: ACGaming/MultiMC5
bool ModList::moveModsDown(int first, int last)
{
	if (last == mods.size() - 1)
		return false;

	beginMoveRows(QModelIndex(), first, last, QModelIndex(), last + 2);
	mods.move(last + 1, first);
	endMoveRows();
	saveListFile();
	emit changed();
	return true;
}
コード例 #29
0
ファイル: ModList.cpp プロジェクト: ACGaming/MultiMC5
bool ModList::moveModsUp(int first, int last)
{
	if (first == 0)
		return false;

	beginMoveRows(QModelIndex(), first, last, QModelIndex(), first - 1);
	mods.move(first - 1, last);
	endMoveRows();
	saveListFile();
	emit changed();
	return true;
}
コード例 #30
0
    bool DragDropModel::dropMimeData(const QMimeData *data,
                                     Qt::DropAction /*action*/, int row, int /*column*/, const QModelIndex &parent)
    {
        if (!data->hasFormat("text/plain"))
            return false;

        QByteArray encodedData = data->data("text/plain");
        QDataStream stream(&encodedData, QIODevice::ReadOnly);

        qint64 _id;
        int _row;
        int _column;

        stream >> _id >> _row >> _column;

        QModelIndexList pers = persistentIndexList();
        foreach(const QModelIndex &idx, pers)
        {
            if (idx.row() == _row && idx.column() == _column && idx.internalId() == _id )
            {
                if ( idx.parent().internalId() == parent.internalId() )
                    return false;

                Tree *child = static_cast<Tree*>(idx.internalPointer());
                if ( child == 0 )
                    return false;

                Tree *oldParent = child->parent();
                if ( oldParent == 0 )
                    return false;

                Tree *newParent = static_cast<Tree*>(parent.internalPointer());
                if ( newParent == 0 )
                    return false;

                beginMoveRows(idx.parent(), idx.row(), idx.row(), parent, parent.row());

                try
                {
                    oldParent->removeChild(idx.row());
                    newParent->addChild(child, row);
                    child->setParent(newParent);
                }
                catch (SqlError&){}

                endMoveRows();

                return true;
            }
        }

        return true;
    }