示例#1
0
bool MultiModelI::list2Model(QString& strError, const bool bNew)
{
    //1 - for each selected index: see the id and create a new record on the main table with it
    QModelIndexList mil = m_listView->selectionModel()->selectedIndexes();

    if (!bNew){
        bool bRemove=false;
        foreach (QModelIndex index, m_selectedIndexes)
        {
            if (!mil.contains(index)){
                bRemove=true;
                break;
            }
        }

        if (bRemove){

            if (m_output->rowCount()< 1) return false;// oops! somthing went wrong here! :->
            int fid=m_output->index(0,1).data().toInt();
            bool bHasDependants;
            if (!checkDependants(fid,bHasDependants)) return false;
            if (!bHasDependants){
                if (!m_output->removeRows(0,m_output->rowCount())) return false;
            }else{
                strError=QObject::tr("Could not update ") + m_output->tableName()
                    + QObject::tr(" since there are dependant records!");
                return false;
            }
        }
    }
 /** A method that simplifies checking a view's current item and selection */
 static void verifyCurrentItemAndSelection(const QAbstractItemView& view, const QModelIndex& expectedCurrent, const QModelIndexList& expectedSelection) {
     QCOMPARE(view.currentIndex(), expectedCurrent);
     const QModelIndexList selectedIndexes = view.selectionModel()->selectedIndexes();
     QCOMPARE(selectedIndexes.count(), expectedSelection.count());
     foreach(const QModelIndex& index, expectedSelection) {
         QVERIFY(selectedIndexes.contains(index));
     }
示例#3
0
void GameList::slotContextMenu(const QPoint& pos)
{
    QModelIndex cell = indexAt(pos);
    QModelIndexList selection = selectedIndexes();
    // Make sure the right click occured on a cell!
    if(cell.isValid() && selection.contains(cell))
    {
        QMenu menu(tr("Game list"), this);
        menu.addAction(tr("Copy games..."), this, SLOT(slotCopyGame()));
        menu.addAction(tr("Filter twins"), this, SLOT(slotFindDuplicate()));
        QMenu* mergeMenu = menu.addMenu(tr("Merge into current game"));
        mergeMenu->addAction(tr("All Games"), this, SLOT(slotMergeAllGames()));
        mergeMenu->addAction(tr("Filter"), this, SLOT(slotMergeFilter()));
        mergeMenu->addAction(tr("Selected games"), this, SLOT(slotMergeGame()));
        menu.addSeparator();
        QAction* deleteAction = menu.addAction(tr("Delete game"), this, SLOT(slotDeleteGame()));
        deleteAction->setCheckable(true);
        deleteAction->setEnabled(!m_model->filter()->database()->isReadOnly());
        menu.addSeparator();
        menu.addAction(tr("Hide game"), this, SLOT(slotHideGame()));

        QModelIndex index = GetSourceIndex(cell);
        int n = m_model->filter()->indexToGame(index.row());
        deleteAction->setChecked(m_model->filter()->database()->deleted(n));
        menu.exec(mapToGlobal(pos));
    }
}
示例#4
0
void
ColumnView::onCustomContextMenu( const QPoint& pos )
{
    m_contextMenu->clear();

    QModelIndex idx = indexAt( pos );
    idx = idx.sibling( idx.row(), 0 );
    m_contextMenuIndex = idx;

    if ( !idx.isValid() )
        return;

    QList<query_ptr> queries;
    QList<artist_ptr> artists;
    QList<album_ptr> albums;

    QModelIndexList indexes = selectedIndexes();
    if ( !indexes.contains( idx ) )
    {
        indexes.clear();
        indexes << idx;
    }

    foreach ( const QModelIndex& index, indexes )
    {
        if ( index.column() || indexes.contains( index.parent() ) )
            continue;

        PlayableItem* item = m_proxyModel->itemFromIndex( m_proxyModel->mapToSource( index ) );

        if ( item && !item->result().isNull() )
            queries << item->result()->toQuery();
        else if ( item && !item->query().isNull() )
            queries << item->query();
        if ( item && !item->artist().isNull() )
            artists << item->artist();
        if ( item && !item->album().isNull() )
            albums << item->album();
    }

    m_contextMenu->setQueries( queries );
    m_contextMenu->setArtists( artists );
    m_contextMenu->setAlbums( albums );
    m_contextMenu->setPlaylistInterface( proxyModel()->playlistInterface() );

    m_contextMenu->exec( viewport()->mapToGlobal( pos ) );
}
示例#5
0
void DesktopWindow::childDropEvent(QDropEvent* e) {
    const QMimeData* mimeData = e->mimeData();
    bool moveItem = false;
    if(e->source() == listView_ && e->keyboardModifiers() == Qt::NoModifier) {
        // drag source is our list view, and no other modifier keys are pressed
        // => we're dragging desktop items
        if(mimeData->hasFormat("application/x-qabstractitemmodeldatalist")) {
            QModelIndex dropIndex = listView_->indexAt(e->pos());
            if(dropIndex.isValid()) { // drop on an item
                QModelIndexList selected = selectedIndexes(); // the dragged items
                if(selected.contains(dropIndex)) { // drop on self, ignore
                    moveItem = true;
                }
            }
            else { // drop on a blank area
                moveItem = true;
            }
        }
    }
    if(moveItem) {
        e->accept();
    }
    else {
        auto delegate = static_cast<Fm::FolderItemDelegate*>(listView_->itemDelegateForColumn(0));
        auto grid = delegate->itemSize();
        Fm::FolderView::childDropEvent(e);
        // position dropped items successively, starting with the drop rectangle
        if(mimeData->hasUrls()
           && (e->dropAction() == Qt::CopyAction
               || e->dropAction() == Qt::MoveAction
               || e->dropAction() == Qt::LinkAction)) {
            QList<QUrl> urlList = mimeData->urls();
            for(int i = 0; i < urlList.count(); ++i) {
                std::string name = urlList.at(i).fileName().toUtf8().constData();
                if(!name.empty()) { // respect the positions of existing files
                    QString desktopDir = XdgDir::readDesktopDir() + QString(QLatin1String("/"));
                    if(!QFile::exists(desktopDir + QString::fromStdString(name))) {
                        QRect workArea = qApp->desktop()->availableGeometry(screenNum_);
                        workArea.adjust(12, 12, -12, -12);
                        QPoint pos = mapFromGlobal(e->pos());
                        alignToGrid(pos, workArea.topLeft(), grid, listView_->spacing());
                        if(i > 0)
                            pos.setY(pos.y() + grid.height() + listView_->spacing());
                        if(pos.y() + grid.height() > workArea.bottom() + 1) {
                            pos.setX(pos.x() + grid.width() + listView_->spacing());
                            pos.setY(workArea.top());
                        }
                        customItemPos_[name] = pos;
                    }
                }
            }
            saveItemPositions();
        }
    }
}
示例#6
0
文件: nickview.cpp 项目: AlD/quassel
QModelIndexList NickView::selectedIndexes() const
{
    QModelIndexList indexList = TreeViewTouch::selectedIndexes();

    // make sure the item we clicked on is first
    if (indexList.contains(currentIndex())) {
        indexList.removeAll(currentIndex());
        indexList.prepend(currentIndex());
    }

    return indexList;
}
示例#7
0
文件: sheet.cpp 项目: djfm/ycell
bool Sheet::isEmpty(const QModelIndex &tl, const QModelIndex &br, const QModelIndexList &except_maybe) const
{
    for(int row = tl.row(); row <= br.row(); ++row)
    {
        for(int column = tl.column(); column <= br.column(); ++column)
        {
            QModelIndex i = model->index(row, column);
            if(except_maybe.contains(i))continue;
            else
            {
                if(!isEmpty(i))return false;
            }
        }
    }
    return true;
}
示例#8
0
/*!
Copied from Qt

Return true if this is a move from ourself and \a index is a child of the selection that
is being moved.
*/
bool TableWidgetDragRows::droppingOnItself(QDropEvent *event, const QModelIndex &index)
{
  Qt::DropAction dropAction = event->dropAction();
  if (this->dragDropMode() == QAbstractItemView::InternalMove)
  {
    dropAction = Qt::MoveAction;
  }
  if (event->source() == this
    && event->possibleActions() & Qt::MoveAction
    && dropAction == Qt::MoveAction) 
  {
    QModelIndexList selectedIndexes = this->selectedIndexes();
    QModelIndex child = index;
    while (child.isValid() && child != rootIndex()) 
    {
      if (selectedIndexes.contains(child))
        return true;
      child = child.parent();
    }
  }
  return false;
}
示例#9
0
void LibraryModel::filteredIndexes(const QModelIndex &index,
                                   const std::function<bool (const LibraryEntry *)> &filterFunction,
                                   QModelIndexList &result) const
{
    int numChildren = rowCount(index);
    if(numChildren) {
        bool allChildrenAdded = true;
        for(int i = 0 ; i < numChildren ; ++i) {
            QModelIndex child = index.child(i, index.column());
            filteredIndexes(child, filterFunction, result);
            if(allChildrenAdded && !result.contains(child)) {
                allChildrenAdded = false;
            }
        }
        // All children have been added, add the parent
        if(allChildrenAdded) {
            result << index;
        }
    } else {
        if(filterFunction(entryFromIndex(index))) {
            result << index;
        }
    }
}
示例#10
0
void DesktopWindow::childDropEvent(QDropEvent* e) {
  bool moveItem = false;
  if(e->source() == listView_ && e->keyboardModifiers() == Qt::NoModifier) {
    // drag source is our list view, and no other modifier keys are pressed
    // => we're dragging desktop items
    const QMimeData *mimeData = e->mimeData();
    if(mimeData->hasFormat("application/x-qabstractitemmodeldatalist")) {
      QModelIndex dropIndex = listView_->indexAt(e->pos());
      if(dropIndex.isValid()) { // drop on an item
        QModelIndexList selected = selectedIndexes(); // the dragged items
        if(selected.contains(dropIndex)) { // drop on self, ignore
          moveItem = true;
        }
      }
      else { // drop on a blank area
        moveItem = true;
      }
    }
  }
  if(moveItem)
    e->accept();
  else
    Fm::FolderView::childDropEvent(e);
}