Beispiel #1
0
 /**
  * 
  * @param QModelIndexList indexes
  * @param bool returnSuperParents If TRUE, only indexes of super-parents will be in result list
  * @return QModelIndexList
  */
 QModelIndexList uniqueRows(QModelIndexList indexes, bool returnSuperParents)
 {
     QModelIndexList result;
     for (QModelIndexList::const_iterator it = indexes.begin(); it != indexes.end(); ++it)
     {
         QModelIndex isUnique = *it;
         Robomongo::BsonTreeItem *item = Robomongo::QtUtils::item<Robomongo::BsonTreeItem*>(isUnique);
         if (item) {
             for (QModelIndexList::const_iterator jt = result.begin(); jt != result.end(); ++jt)
             {
                 Robomongo::BsonTreeItem *jItem = Robomongo::QtUtils::item<Robomongo::BsonTreeItem*>(*jt);
                 if (jItem && jItem->superParent() == item->superParent()) {
                     isUnique = QModelIndex();
                     break;
                 }
             }
             if (isUnique.isValid()) {
                 if (returnSuperParents) {
                     // Move index onto "super parent" element before pushing it into result set
                     QModelIndex parent = isUnique.parent();
                     while (parent != QModelIndex()) {
                         isUnique = parent;
                         parent = parent.parent();
                     }
                 }
                 result.append(isUnique);
             }
         }
     }        
     return result;
 }
Beispiel #2
0
QModelIndexList CSVWorld::RegionMap::getUnselectedCells() const
{
    const QAbstractItemModel *model = QTableView::model();

    int rows = model->rowCount();
    int columns = model->columnCount();

    QModelIndexList selected = selectionModel()->selectedIndexes();
    std::sort (selected.begin(), selected.end());

    QModelIndexList all;

    for (int y=0; y<rows; ++y)
        for (int x=0; x<columns; ++x)
        {
            QModelIndex index = model->index (y, x);
            if (model->data (index, Qt::BackgroundRole)!=QBrush (Qt::DiagCrossPattern))
                all.push_back (index);
        }

    std::sort (all.begin(), all.end());

    QModelIndexList list;

    std::set_difference (all.begin(), all.end(), selected.begin(), selected.end(),
                         std::back_inserter (list));

    return list;
}
Beispiel #3
0
QModelIndexList CSVWorld::RegionMap::getMissingRegionCells() const
{
    const QAbstractItemModel *model = QTableView::model();

    QModelIndexList selected = selectionModel()->selectedIndexes();

    std::set<std::string> regions;

    for (QModelIndexList::const_iterator iter (selected.begin()); iter!=selected.end(); ++iter)
    {
        std::string region =
            model->data (*iter, CSMWorld::RegionMap::Role_Region).toString().toUtf8().constData();

        if (!region.empty())
            regions.insert (region);
    }

    QModelIndexList list;

    QModelIndexList unselected = getUnselectedCells();

    for (QModelIndexList::const_iterator iter (unselected.begin()); iter!=unselected.end(); ++iter)
    {
        std::string region =
            model->data (*iter, CSMWorld::RegionMap::Role_Region).toString().toUtf8().constData();

        if (!region.empty() && regions.find (region)!=regions.end())
            list.push_back (*iter);
    }

    return list;
}
Beispiel #4
0
void PublicHubs::slotContextMenu(){
    QItemSelectionModel *sel_model = treeView->selectionModel();
    QModelIndexList indexes = sel_model->selectedRows(0);

    if (indexes.isEmpty())
        return;

    if (proxy)
        std::transform(indexes.begin(), indexes.end(), indexes.begin(), [&](QModelIndex i) { return proxy->mapToSource(i); });

    WulforUtil *WU = WulforUtil::getInstance();

    QMenu *m = new QMenu();
    QAction *connect = new QAction(WU->getPixmap(WulforUtil::eiCONNECT), tr("Connect"), m);
    QAction *add_fav = new QAction(WU->getPixmap(WulforUtil::eiBOOKMARK_ADD), tr("Add to favorites"), m);
    QAction *copy    = new QAction(WU->getPixmap(WulforUtil::eiEDITCOPY), tr("Copy &address to clipboard"), m);

    m->addActions(QList<QAction*>() << connect << add_fav << copy);

    QAction *ret = m->exec(QCursor::pos());

    m->deleteLater();

    if (ret == connect){
        PublicHubItem * item = NULL;
        MainWindow *MW = MainWindow::getInstance();

        foreach (const QModelIndex &i, indexes){
            item = reinterpret_cast<PublicHubItem*>(i.internalPointer());

            if (item)
                MW->newHubFrame(item->data(COLUMN_PHUB_ADDRESS).toString(), "");

            item = NULL;
        }
Beispiel #5
0
std::vector<Range> SheetTableView::selectedRanges() const
{
    QModelIndexList list = selectionModel()->selectedIndexes();
    std::vector<Range> result;

    // Insert selected cells into set. This variable should ideally be a hash_set
    // but that is not part of standard stl.
    std::set<std::pair<int, int> > cells;
    for (QModelIndexList::const_iterator it = list.begin(); it != list.end(); ++it)
        cells.insert(std::make_pair<int,int>((*it).row(), (*it).column()));

    // Create rectangular cells from the unordered collection of selected cells
    std::map<std::pair<int, int>, std::pair<int, int> > rectangles;
    createRectangles(cells, rectangles);

    std::map<std::pair<int, int>, std::pair<int, int> >::const_iterator i = rectangles.begin();
    for (; i != rectangles.end(); ++i) {
        std::pair<int, int> ul = (*i).first;
        std::pair<int, int> size = (*i).second;

        result.push_back(Range(ul.first, ul.second,
                               ul.first + size.first - 1, ul.second + size.second - 1));
    }

    return result;
}
Beispiel #6
0
void Clean_tree_view::keyPressEvent(QKeyEvent* ev)
{
	if (ev->key() == Qt::Key_Delete)
	{
		QModelIndexList indexes = selectedIndexes();
		int row = -1;
		int first_row = -1;
		for (QModelIndexList::iterator i = indexes.begin(); i != indexes.end(); ++i)
		{
			if (row != i->row())
			{
				row = i->row();

				if (first_row == -1)
					first_row = i->row();

				model()->removeRow(i->row(), i->parent());
			}
		}
		// All rows removed

		// Now select the new one selected row for fast massive deleting
		if (first_row != -1)
		{
			selectionModel()->select(model()->index(first_row, 0, QModelIndex()), 
				QItemSelectionModel::Select);
		}

		emit clean_updated();
	}
}
void BedItemModel::slotDelete(QModelIndexList lst) {
    if (lst.size() < 1) {
        return;
    }

    QStringList names;
    QList<Bed*> beds;

    for (QModelIndexList::iterator it = lst.begin(); it != lst.end(); it++) {
        BedItem* itm = (BedItem*) itemFromIndex(*it);
        names << QString::number(itm->getBed()->getPosition());

        beds << itm->getBed();
    }

    if (QMessageBox::Yes != QMessageBox::question((static_cast<ProfileLogger*>(QApplication::instance()))->getMainWindow(),
            tr("Delete beds?"),
            tr("Delete beds %1?").arg(names.join(", ")),
            QMessageBox::Yes | QMessageBox::No)) {
        return;
    }

    for (QList<Bed*>::iterator it = beds.begin(); it != beds.end(); it++) {
        _profile->deleteBed(*it);
    }

    reload();
}
Beispiel #8
0
void BAMseek::copyCells(){
  QAbstractItemModel * model = tableview->model();
  QItemSelectionModel * selection = tableview->selectionModel();
  QModelIndexList indexes = selection->selectedIndexes();
  std::sort(indexes.begin(), indexes.end());

  QString selected_text;
  int row = 0;
  if(!indexes.empty()){
    row = indexes.first().row();
    selected_text.append(model->data(indexes.first()).toString());
    indexes.removeFirst();
  }
  QModelIndex current;
  foreach(current, indexes){
    QVariant data = model->data(current);
    QString text = data.toString();
    
    if(current.row() != row){
      selected_text.append('\n');
    }else{
      selected_text.append('\t');
    }
    row = current.row();

    selected_text.append(text);
  }
Beispiel #9
0
void CSVWorld::RegionMap::selectRegions()
{
    QModelIndexList unselected = getMissingRegionCells();

    for (QModelIndexList::const_iterator iter (unselected.begin()); iter!=unselected.end(); ++iter)
        selectionModel()->select (*iter, QItemSelectionModel::Select);
}
Beispiel #10
0
RemoveGlobalQuantityRowsCommand::RemoveGlobalQuantityRowsCommand(
  QModelIndexList rows, CQGlobalQuantityDM * pGlobalQuantityDM, const QModelIndex&)
  : CCopasiUndoCommand("Global Quantity", GLOBALQUANTITY_REMOVE)
  , mpGlobalQuantityDM(pGlobalQuantityDM)
  , mRows(rows)
  , mpGlobalQuantityData()
  , mFirstTime(true)
{

  CCopasiDataModel * pDataModel = pGlobalQuantityDM->getDataModel();
  assert(pDataModel != NULL);
  CModel * pModel = pDataModel->getModel();
  assert(pModel != NULL);

  QModelIndexList::const_iterator i;

  for (i = rows.begin(); i != rows.end(); ++i)
    {
      CModelValue* pModelValue = &pModel->getModelValues()[i->row()];

      if (pGlobalQuantityDM->isDefaultRow(*i) || pModelValue == NULL)
        continue;

      UndoGlobalQuantityData *data = new UndoGlobalQuantityData(pModelValue);
      mpGlobalQuantityData.append(data);
    }

  setText(QObject::tr(": Removed Global Quantity"));
}
Beispiel #11
0
void NotesModel::matchSelToMain()
{
    QModelIndexList lSelFiles (m_pCommonData->m_pFilesG->selectionModel()->selection().indexes());

    set<int> sSel;
    for (QModelIndexList::iterator it = lSelFiles.begin(), end = lSelFiles.end(); it != end; ++it)
    {
        int nCol (it->column());
        if (nCol > 0) // skip file name
        {
            sSel.insert(nCol - 1);
        }
    }

    QItemSelectionModel* pNotesSelModel (m_pCommonData->m_pNotesG->selectionModel());
    pNotesSelModel->clearSelection();
    bool bFirstFound (false);
    for (int i = 0, nNoteCnt = cSize(m_pCommonData->getCrtNotes()); i < nNoteCnt; ++i)
    {
        const Note* pNote (m_pCommonData->getCrtNotes()[i]);
        int nPos (m_pCommonData->findPos(pNote));
        if (sSel.count(nPos) > 0)
        {
            if (!bFirstFound)
            {
                bFirstFound = true;
                m_pCommonData->m_pNotesG->setCurrentIndex(index(i, 0));
            }
            pNotesSelModel->select(index(i, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows);
        }
    }
}
Beispiel #12
0
void GraphicalUriArray::moveItems( int step )
{
  QModelIndexList selected = m_listView->selectionModel()->selectedRows();
  QModelIndexList::iterator it = selected.begin();
  QStringList items = m_model->stringList();
  QList<int> newSelection;

  // move the elements
  for( ; it != selected.end() ; ++it )
  {
      int row = it->row();
      int newRow = row + step;

//      if(  newRow >= 0 && newRow < items.count() )
      items.move( row, newRow );    // move the row
      newSelection.append( newRow );
  }

  m_model->setStringList(items); // set the new items

  // select items that were just moved
  QList<int>::iterator itNewSelect = newSelection.begin();
  for( ; itNewSelect != newSelection.end(); ++ itNewSelect)
    m_listView->selectionModel()->select( m_model->index(*itNewSelect), QItemSelectionModel::Select );

  // update buttons enabled states
  selectionChanged(QItemSelection(), QItemSelection());
}
Beispiel #13
0
std::vector<std::string> CSVWorld::Table::listRevertableSelectedIds() const
{
    /// \todo Do not use hardcoded column numbers
    std::vector<std::string> revertableIds;

    if (mProxyModel->columnCount()>0)
    {
        QModelIndexList selectedRows = selectionModel()->selectedRows();

        for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end();
             ++iter)
        {
            QModelIndex index = mProxyModel->mapToSource (mProxyModel->index (iter->row(), 0));

            CSMWorld::RecordBase::State state =
                static_cast<CSMWorld::RecordBase::State> (
                mModel->data (mModel->index (index.row(), 1)).toInt());

            if (state!=CSMWorld::RecordBase::State_BaseOnly)
            {
                std::string id = mModel->data (mModel->index (index.row(), 0)).
                    toString().toUtf8().constData();

                revertableIds.push_back (id);
            }
        }
    }

    return revertableIds;
}
void TorrentContentTreeView::keyPressEvent(QKeyEvent *event) {
  if (event->key() != Qt::Key_Space && event->key() != Qt::Key_Select) {
    QTreeView::keyPressEvent(event);
    return;
  }

  event->accept();

  QModelIndex current = currentNameCell();

  QVariant value = current.data(Qt::CheckStateRole);
  if (!value.isValid()) {
    Q_ASSERT(false);
    return;
  }

  Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
                       ? Qt::Unchecked : Qt::Checked);

  QModelIndexList selection = selectionModel()->selectedRows(TorrentContentModelItem::COL_NAME);

  for (QModelIndexList::const_iterator i = selection.begin(); i != selection.end(); ++i) {
    QModelIndex index = *i;
    Q_ASSERT(i->column() == TorrentContentModelItem::COL_NAME);
    model()->setData(index, state, Qt::CheckStateRole);
  }
}
Beispiel #15
0
void MainWindow::on_upButton_clicked()
{
    QItemSelectionModel *select = ui->targetListTable->selectionModel();
    QModelIndexList selectedRows = select->selectedRows();
    QList<int> moveOrder;

    if (select->hasSelection()) {
        // Makes sure everything is moved in the correct order
        for (QList<QModelIndex>::iterator i = selectedRows.begin(); i != selectedRows.end(); i++) {
            moveOrder.append(i->row());
        }
        qSort(moveOrder.begin(), moveOrder.end());

        ui->targetListTable->selectionModel()->clearSelection(); // Deselects all rows
        QItemSelection selectedItems = ui->targetListTable->selectionModel()->selection();
        if (moveOrder[0] != 0) {
            for (int i = 0; i < moveOrder.length(); i++) {
                ui->targetListTable->selectRow(moveOrder[i]-1);
                selectedItems.merge(ui->targetListTable->selectionModel()->selection(), QItemSelectionModel::Select);

                targetList->moveUp(moveOrder[i]);
            }
            ui->targetListTable->selectionModel()->select(selectedItems, QItemSelectionModel::Select); // Reselects new rows
        }
    }
}
Beispiel #16
0
void MainWindow::on_edit_clicked()
{
    QItemSelectionModel *select = ui->targetListTable->selectionModel();
    QModelIndexList selectedRows = select->selectedRows();

    if (select->hasSelection() && selectedRows.length() == 1) { // only 1 item can be selected
        QList<QModelIndex>::iterator i = selectedRows.begin();
        int selectedRow = i->row(); // gets the selected row number

        // Creates edit window
        targetEditor = new TargetMaker(this);
        targetEditor->setModal(true);
        targetEditor->setWindowTitle("Edit Target");

        // Sets default values
        targetEditor->defaultFileInput = targetList->rows->at(selectedRow)->imageFilePath;
        targetEditor->defaultNameInput = targetList->rows->at(selectedRow)->name->text();
        targetEditor->defaultCoordInput = targetList->rows->at(selectedRow)->coord->text();
        targetEditor->defaultDescInput = targetList->rows->at(selectedRow)->desc->text();
        targetEditor->setDefaultInputs();

        // Opens edit window
        targetEditor->exec();

        if (targetEditor->accepted) {
            targetList->editRow(selectedRow, targetEditor->getImageFilePath(), targetEditor->getName(), targetEditor->getCoord(), targetEditor->getDesc());
        }
    }
}
// ---
void VSWSCReleasesDataListTree::keyReleaseEvent (QKeyEvent* evnt)
{
	QModelIndexList selected = selectedIndexes ();
	QModelIndexList::iterator i = selected.begin ();
	if (i == selected.end ()) 
	{
		QTreeView::keyReleaseEvent (evnt); 
		// None has been selected, then it is sent to the parent...
		return;
	}

	// When a button is released, 
	// then depending on the button one or other thing is done...
	QModelIndex index = *i;
	VSWSCReleasesDataListModel::Item* item = 
		static_cast <VSWSCReleasesDataListModel::Item*> (index.internalPointer ());
	evnt -> accept(); // But in any case, the event is just treated...
	if (item -> type () == 2) // Button works just for releases...
	{
		// What ever the key selected is...
		// The information has to be highlighted
		QTreeView::keyReleaseEvent (evnt); // Default treatement...
		emit (releaseSelectedSignal (item -> parent () -> value (),
			item -> value ())); // ...the data in the right side has to change...
	}
}
Beispiel #18
0
void NotesModel::matchSelToStreams()
{
    QModelIndexList lSelStreams (m_pCommonData->m_pStreamsG->selectionModel()->selection().indexes());

    const vector<DataStream*>& vCrtStreams (m_pCommonData->getViewHandlers()[m_pCommonData->getFilesGCrtRow()]->getStreams());
    vector<const DataStream*> vSelStreams;
    for (QModelIndexList::iterator it = lSelStreams.begin(), end = lSelStreams.end(); it != end; ++it)
    {
        int nRow (it->row());
        vSelStreams.push_back(vCrtStreams[nRow]);
    }

    QItemSelectionModel* pNotesSelModel (m_pCommonData->m_pNotesG->selectionModel());
    pNotesSelModel->clearSelection();
    bool bFirstFound (false);

    for (int i = 0, nNoteCnt = cSize(m_pCommonData->getCrtNotes()); i < nNoteCnt; ++i)
    {
        const Note* pNote (m_pCommonData->getCrtNotes()[i]);
        if (isInList(pNote, vSelStreams))
        {
            if (!bFirstFound)
            {
                bFirstFound = true;
                m_pCommonData->m_pNotesG->setCurrentIndex(index(i, 0));
            }
            pNotesSelModel->select(index(i, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows);
        }
    }
}
Beispiel #19
0
void Filemanager::filesDelete()
{
	// getting the selected items
	QModelIndexList selectedItems = m_files->selectionModel()->selectedIndexes();
	
	// removing each item from File System
	for( QModelIndexList::iterator item = selectedItems.begin(); item != selectedItems.end(); ++item )
	{
		QString itemDisplayName = m_filesModel->data(*item,Qt::DisplayRole).toString();
		if( (itemDisplayName == "..") || (itemDisplayName == ".") )
			continue;
		
		QString itemName = m_filesModel->data(*item,Qt::StatusTipRole).toString();
		if( QFileInfo(itemName).isFile() )
		{
			if( false == removeFile(itemName) )
				BaloonNotificationManager::showBaloonNotification(QString(ERROR_ON_FILE_REMOVE).arg(itemName));
		}
		else 
		{
			if( false == removeFolder(itemName) )
				BaloonNotificationManager::showBaloonNotification(QString(ERROR_ON_FOLDER_REMOVE).arg(itemName));
		}
	}
	
	// refreshing the content for current folder
	refreshCurrentFolder();
}
Beispiel #20
0
void CSVWorld::RegionMap::viewInTable()
{
    std::ostringstream hint;
    hint << "f:!or(";

    QModelIndexList selected = getSelectedCells();

    bool first = true;

    for (QModelIndexList::const_iterator iter (selected.begin()); iter!=selected.end(); ++iter)
    {
        std::string cellId = model()->data (*iter, CSMWorld::RegionMap::Role_CellId).
                             toString().toUtf8().constData();

        if (first)
            first = false;
        else
            hint << ",";

        hint << "string(ID,\"" << cellId << "\")";
    }

    hint << ")";

    emit editRequest (CSMWorld::UniversalId::Type_Cells, hint.str());
}
Beispiel #21
0
void CSVWorld::RegionMap::setRegion (const std::string& regionId)
{
    QModelIndexList selected = getSelectedCells();

    QAbstractItemModel *regionModel = model();

    CSMWorld::IdTable *cellsModel = &dynamic_cast<CSMWorld::IdTable&> (*
                                    mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_Cells));

    QString regionId2 = QString::fromUtf8 (regionId.c_str());

    if (selected.size()>1)
        mDocument.getUndoStack().beginMacro (tr ("Set Region"));

    for (QModelIndexList::const_iterator iter (selected.begin()); iter!=selected.end(); ++iter)
    {
        std::string cellId = regionModel->data (*iter, CSMWorld::RegionMap::Role_CellId).
                             toString().toUtf8().constData();

        QModelIndex index = cellsModel->getModelIndex (cellId,
                            cellsModel->findColumnIndex (CSMWorld::Columns::ColumnId_Region));

        mDocument.getUndoStack().push (
            new CSMWorld::ModifyCommand (*cellsModel, index, regionId2));
    }

    if (selected.size()>1)
        mDocument.getUndoStack().endMacro();
}
Beispiel #22
0
void CSVWorld::Table::moveDownRecord()
{
    if (mEditLock || (mModel->getFeatures() & CSMWorld::IdTableBase::Feature_Constant))
        return;

    QModelIndexList selectedRows = selectionModel()->selectedRows();

    if (selectedRows.size()==1)
    {
        int row =selectedRows.begin()->row();

        if (row<mProxyModel->rowCount()-1)
        {
            int row2 = row+1;

            row = mProxyModel->mapToSource (mProxyModel->index (row, 0)).row();
            row2 = mProxyModel->mapToSource (mProxyModel->index (row2, 0)).row();

            if (row2<=row)
                throw std::runtime_error ("Inconsistent row order");

            std::vector<int> newOrder (row2-row+1);
            newOrder[0] = row2-row;
            newOrder[row2-row] = 0;
            for (int i=1; i<row2-row; ++i)
                newOrder[i] = i;

            mDocument.getUndoStack().push (new CSMWorld::ReorderRowsCommand (
                dynamic_cast<CSMWorld::IdTable&> (*mModel), row, newOrder));
        }
    }
}
Beispiel #23
0
void CSVWorld::RegionMap::view()
{
    std::ostringstream hint;
    hint << "c:";

    QModelIndexList selected = selectionModel()->selectedIndexes();

    bool first = true;

    for (QModelIndexList::const_iterator iter (selected.begin()); iter!=selected.end(); ++iter)
    {
        std::string cellId = model()->data (*iter, CSMWorld::RegionMap::Role_CellId).
                             toString().toUtf8().constData();

        if (first)
            first = false;
        else
            hint << "; ";

        hint << cellId;
    }

    emit editRequest (CSMWorld::UniversalId (CSMWorld::UniversalId::Type_Scene, "sys::default"),
                      hint.str());
}
Beispiel #24
0
void CSVWorld::Table::moveDownRecord()
{
    QModelIndexList selectedRows = selectionModel()->selectedRows();

    if (selectedRows.size()==1)
    {
        int row =selectedRows.begin()->row();

        if (row<mProxyModel->rowCount()-1)
        {
            int row2 = row+1;

            row = mProxyModel->mapToSource (mProxyModel->index (row, 0)).row();
            row2 = mProxyModel->mapToSource (mProxyModel->index (row2, 0)).row();

            if (row2<=row)
                throw std::runtime_error ("Inconsistent row order");

            std::vector<int> newOrder (row2-row+1);
            newOrder[0] = row2-row;
            newOrder[row2-row] = 0;
            for (int i=1; i<row2-row; ++i)
                newOrder[i] = i;

            mUndoStack.push (new CSMWorld::ReorderRowsCommand (*mModel, row, newOrder));
        }
    }
}
void BedCorrelationItemView::slotDelete() {
    QModelIndexList selected = selectedIndexes();

    if (selected.isEmpty()) {
        return;
    }

    QStringList names;
    for (QModelIndexList::iterator it = selected.begin(); it != selected.end(); it++) {
        BedCorrelationItem* itm = (BedCorrelationItem*) ((BedCorrelationItemModel*) model())->itemFromIndex(*it);
        if (itm) {
            names << tr("Name: %1, ID: %2")
                    .arg(itm->getBedCorrelation()->getName())
                    .arg(itm->getBedCorrelation()->getId());
        }
    }

    if (QMessageBox::Yes == QMessageBox::warning(this,
            tr("Really Delete?"),
            tr("Really delete this BedCorrelations?\n%1")
            .arg(names.join(", ")),
            QMessageBox::Yes | QMessageBox::No)) {
        emit deleteRequest(selected);
    }
}
Beispiel #26
0
std::vector<std::string> CSVWorld::Table::listDeletableSelectedIds() const
{
    std::vector<std::string> deletableIds;

    if (mProxyModel->columnCount()>0)
    {
        QModelIndexList selectedRows = selectionModel()->selectedRows();

        for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end();
            ++iter)
        {
            QModelIndex index = mProxyModel->mapToSource (mProxyModel->index (iter->row(), 0));

            CSMWorld::RecordBase::State state =
                static_cast<CSMWorld::RecordBase::State> (
                mModel->data (mModel->index (index.row(), 1)).toInt());

            if (state!=CSMWorld::RecordBase::State_Deleted)
            {
                int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id);

                std::string id = mModel->data (mModel->index (index.row(), columnIndex)).
                    toString().toUtf8().constData();

                deletableIds.push_back (id);
            }
        }
    }

    return deletableIds;
}
Beispiel #27
0
template<class T> std::vector<T> getSelectedIds(
  const QTableView* view,
  const QSqlQueryModel* model,
  const QString& colName)
{
  QModelIndexList selected = view->selectionModel()->selectedIndexes();
  std::vector<T> selectedIds;
  std::set<int> rows;
  for(
    QModelIndexList::const_iterator it = selected.begin();
    it != selected.end();
    ++it
  )
  {
    rows.insert(it->row()); 
  }
  for(
    std::set<int>::const_iterator it = rows.begin();
    it != rows.end();
    ++it
  )
  {
    QSqlRecord selectedRecord = model->record(*it);
    selectedIds.push_back(
      selectedRecord.value(colName).value<library_song_id_t>());
  }
  return selectedIds;
}
void QuadDataManager::perform_tva_action ( const eTreeViewActions &action, const bool & state )
{

  QModelIndexList indexes = m_ui->datapiece_treeView->selectionModel()->selectedIndexes();

  for ( QModelIndexList::iterator ind_it = indexes.begin();ind_it != indexes.end(); ++ind_it )
  {
    TreeModel::_treeitem *item = static_cast<TreeModel::_treeitem*> ( ( *ind_it ).internalPointer() );

    switch ( action )
    {
    case TVA_SURF             :
      item->node->m_bShowSurface            = state;
      break;
    case TVA_CPS              :
      item->node->m_bShowCps                = state;
      break;
    case TVA_GRAPH            :
      item->node->m_bShowMsGraph            = state;
      break;
    case TVA_QUADS            :
      item->node->m_bShowMsQuads            = state;
      break;
    case TVA_GRAD             :
      item->node->m_bShowGrad               = state;
      break;
    case TVA_CANCELABLE_PAIRS :
      item->node->m_bShowCancelablePairs    = state;
      break;
    default:
      break;
    }
  }

}
QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
{
    PlMimeData *plMimeData = new PlMimeData();
    QModelIndexList list;

    foreach( const QModelIndex &index, indexes ) {
        if( index.isValid() && index.column() == 0 )
            list.append(index);
    }

    qSort(list.begin(), list.end(), modelIndexLessThen);

    AbstractPLItem *item = NULL;
    foreach( const QModelIndex &index, list ) {
        if( item )
        {
            AbstractPLItem *testee = getItem( index );
            while( testee->parent() )
            {
                if( testee->parent() == item ||
                    testee->parent() == item->parent() ) break;
                testee = testee->parent();
            }
            if( testee->parent() == item ) continue;
            item = getItem( index );
        }
        else
            item = getItem( index );

        plMimeData->appendItem( static_cast<PLItem*>(item)->inputItem() );
    }

    return plMimeData;
}
void QuotesTableView::onSendRequest(bool subscribe)
{
    QModelIndexList idxs = selectedIndexes();
    if( idxs.empty() ) 
        return;

    qint16 row = idxs.begin()->row();
    if( row < 0)
        return;

    Instrument inst = model()->getByOrderRow(row);
    if( inst.second != -1 )
    {
        bool sendSubscription = false;
        QSharedPointer<QReadLocker> autolock;
        Snapshot* snap = model()->getSnapshot(model()->getByOrderRow(row).first.c_str(),autolock);
        if(snap) 
            sendSubscription = (snap->statuscode_ & Snapshot::StatUnSubscribed);
        autolock.reset();

        if( sendSubscription && subscribe)
            emit model()->activateRequest(inst);
        else if( !(sendSubscription || subscribe) )
            emit model()->activateRequest( Instrument("Disable_" + inst.first, inst.second) );
        else
        { /*do nothing */}
    }
}