void MainWindow::updateActionsState()
{
	QModelIndexList rows = _ui->listView->selectionModel()->selectedRows();
	_ui->actionDelete->setEnabled(!rows.empty());
	_ui->actionDownload->setEnabled(!rows.empty());
	_ui->actionRename->setEnabled(rows.size() == 1);
	_ui->actionGo_Down->setEnabled(rows.size() == 1);
	_ui->actionBack->setEnabled(!_history.empty());

	QStringList statusList;
	for(const auto & h : _history)
		statusList.push_back(h.first);
	_ui->statusBar->showMessage(statusList.join(QString::fromUtf8(" » ")));
}
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 */}
    }
}
void QmitkDataNodeSelectionProvider::SetSelection(berry::ISelection::ConstPointer selection,
        QItemSelectionModel::SelectionFlags flags)
{
    if (!qSelectionModel) return;

    mitk::DataNodeSelection::ConstPointer dataNodeSelection = selection.Cast<const mitk::DataNodeSelection>();
    if (dataNodeSelection)
    {
        const QAbstractItemModel* model = qSelectionModel->model();

        QItemSelection newSelection;
        const std::list<mitk::DataNode::Pointer> selectedNodes = dataNodeSelection->GetSelectedDataNodes();
        for (auto i = selectedNodes.begin();
                i != selectedNodes.end(); ++i)
        {
            QModelIndexList matched = model->match(model->index(0, 0), QmitkDataNodeRawPointerRole,
                                                   QVariant::fromValue<mitk::DataNode*>(i->GetPointer()), 1, Qt::MatchRecursive);
            if (!matched.empty())
            {
                newSelection.select(matched.front(), matched.front());
            }
        }
        qSelectionModel->select(newSelection, flags);
    }
    else
    {
        QtSelectionProvider::SetSelection(selection, flags);
    }
}
示例#4
0
void UserphraseModel::remove(QModelIndexList indexList)
{
    if (indexList.empty()) {
        qDebug() << "indexList is empty";
        return;
    }

    qSort(indexList.begin(), indexList.end(), qGreater<QModelIndex>());

    // XXX: indexList is in revsrsed order, so first is actual last, and vice
    // verse.
    auto first = indexList.last().row();
    auto last = indexList.first().row();

    emit beginRemoveRows(indexList.first().parent(), first, last);

    foreach(auto item, indexList) {
        auto index = item.row();

        qDebug() << userphrase_[index].phrase_
                 << userphrase_[index].bopomofo_;
        auto ret = chewing_userphrase_remove(
            ctx_.get(),
            userphrase_[index].phrase_.toUtf8().constData(),
            userphrase_[index].bopomofo_.toUtf8().constData());
        if (ret > 0) {
            // FIXME: std::vector::erase is an inefficient operation.
            userphrase_.erase(userphrase_.begin() + index);
        } else {
            qWarning() << "chewing_userphrase_remove() returns" << ret;
        }
        // FIXME: Handle chewing_userphrase_remove fails.
    }
示例#5
0
void KCompletionModel::Private::slotMatches(const QStringList &matches)
{   
    QModelIndexList indexesToRemove;
    QHashIterator<QString, QPersistentModelIndex> it(m_reverseIndexes);
    
    while (it.hasNext()) {
        it.next();
        if (!matches.contains(it.key())) {
            indexesToRemove.append(it.value());
        }
    }
    
    if (!indexesToRemove.empty()) {
        removeRows(indexesToRemove);
    }
    
    QList<QPair<QModelIndex, QVariant> > indexesToAppend;
    QList<QString>::const_iterator strIt;
    int count = m_strings.size();
    for (strIt = matches.constBegin(); strIt != matches.constEnd(); ++strIt) {
        if (!m_reverseIndexes.contains(*strIt)) {
            QPair<QModelIndex, QVariant> indexPair;
            indexPair.first = q->createIndex(count++, 0);
            indexPair.second = *strIt;
            
            indexesToAppend.append(indexPair);
        }
    }

    if (!indexesToAppend.empty()) {
        insertRows(indexesToAppend);
    }
}
示例#6
0
void PiqslImageView::setSelectedImage(const QModelIndexList& indexes)
{
    if(m_image)
        disconnect(m_image.data(), 0, this, 0);
    if(indexes.empty())
    {
      //        m_image.reset();
        update();
        return;
    }
    int prevWidth = 0;
    int prevHeight = 0;
    if(m_image)
    {
        prevWidth = m_image->frameWidth();
        prevHeight = m_image->frameHeight();
    }
    m_image = indexes[0].data().value<QSharedPointer<CqImage> >();
    if(prevWidth > 0 && m_image->frameWidth() > 0)
    {
        // Keep the center of the image in the same place when switching to an
        // image of different dimensions.
        m_tlPos += 0.5f*QPointF(prevWidth - m_image->frameWidth(),
                                prevHeight - m_image->frameHeight());
    }
    else
        centerImage();
    connect(m_image.data(), SIGNAL(updated(int,int,int,int)),
            this, SLOT(imageUpdated(int,int,int,int)));
    connect(m_image.data(), SIGNAL(resized()), this, SLOT(imageResized()));
    update();
}
示例#7
0
文件: BAMseek.cpp 项目: jtb/BAMseek
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);
  }
void VectorEditionWidget::removeRows() {
  QModelIndexList selection = ui->listView->selectionModel()->selectedRows();

  if(!selection.empty()) {
    ui->listView->model()->removeRows(selection.first().row(),selection.count());
  }
}
void DirectusFileExplorer::mouseReleaseEvent(QMouseEvent* event)
{
    // Clear the hierarchy and the inspector
    m_hierarchy->clearSelection();
    m_inspector->Clear();

    // See if anything was actually clicked,
    QModelIndexList selectedItems = this->selectionModel()->selectedIndexes();
    if (selectedItems.empty())
        return;

    // If something was indeed clicked, get it's path.
    string filePath = m_fileModel->fileInfo(selectedItems[0]).filePath().toStdString();

    // Display file in the inspector
    if (FileSystem::IsEngineMaterialFile(filePath))
    {
        m_inspector->InspectMaterialFile(filePath);
    }

    // Load scene
    if (FileSystem::IsEngineSceneFile(filePath))
    {
        m_inspector->GetContext()->GetSubsystem<Scene>()->LoadFromFile(filePath);
    }
}
void ListingTable::contextMenuRequested(const QPoint& pos)
{
	QMenu menu;

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

	QAction* addAction = new QAction(QIcon::fromTheme("document-new", QIcon(":/icons/document-new.png")),
			tr("Add Part"), &menu);
	connect(addAction, SIGNAL(triggered()), this, SLOT(addPartRequestedSlot()));
	menu.addAction(addAction);

	QAction* removeAction = new QAction(QIcon::fromTheme("edit-delete", QIcon(":/icons/edit-delete.png")),
			tr("Delete Parts"), &menu);
	connect(removeAction, SIGNAL(triggered()), this, SLOT(deletePartsRequestedSlot()));
	menu.addAction(removeAction);

	QAction* duplicateAction = new QAction(QIcon::fromTheme("edit-copy", QIcon(":/icons/edit-copy.png")),
			tr("Duplicate Parts"), &menu);
	connect(duplicateAction, SIGNAL(triggered()), this, SLOT(duplicatePartsRequestedSlot()));
	menu.addAction(duplicateAction);

	if (selIndices.empty()) {
		removeAction->setEnabled(false);
		duplicateAction->setEnabled(false);
	}

	menu.addSeparator();

	QMenu* headerMenu = new QMenu(tr("Sections"), &menu);
	buildHeaderSectionMenu(headerMenu);
	menu.addMenu(headerMenu);

	menu.exec(viewport()->mapToGlobal(pos));
}
示例#11
0
void MainWindow::delCar()
{
    QModelIndexList selection = carView->selectionModel()->selectedRows(0);

    if (!selection.empty()) {
        QModelIndex idIndex = selection.at(0);
        int id = idIndex.data().toInt();
        QString name = idIndex.sibling(idIndex.row(), 1).data().toString();
        QString factory = idIndex.sibling(idIndex.row(), 2).data().toString();

        QMessageBox::StandardButton button;
        button = QMessageBox::question(this, tr("删除汽车记录"),
                                       QString(tr("确认删除由'%1'生产的'%2'吗?"))
                                              .arg(factory).arg(name),
                                       QMessageBox::Yes | QMessageBox::No);

        if (button == QMessageBox::Yes) {
            removeCarFromFile(id);
            removeCarFromDatabase(idIndex);
            decreaseCarCount(indexOfFactory(factory));
        }
    } else {
        QMessageBox::information(this, tr("删除汽车记录"),
                                 tr("请选择要删除的记录。"));
    }
}
示例#12
0
void core::BasicTable::cutClick()
{
	if(!getCutAction()->isEnabled() || !getCutAction()->isVisible()) return;

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

	if(selList.empty()){
		return;
	}else{
		clipboard = QApplication::clipboard();

		QString output;
		QXmlStreamWriter writer(&output);
		writer.setAutoFormatting(true);
		writer.setAutoFormattingIndent(3);

		writer.writeStartElement(STR_TABLE);
		for(int i = 0; i < selList.size(); i++){
			writer.writeEmptyElement(STR_ITEM);
			writer.writeAttribute(STR_ROW, QString::number(selList[i].row()));
			writer.writeAttribute(STR_COL, QString::number(selList[i].column()));
			writer.writeAttribute(STR_DATA, selList[i].data().toString());

			model()->setData(selList[i], "");
		}
		writer.writeEndElement();

		clipboard->setText(output);
	}
}
DeviceProcessItem DeviceProcessesDialogPrivate::selectedProcess() const
{
    const QModelIndexList indexes = procView->selectionModel()->selectedIndexes();
    if (indexes.empty() || !processList)
        return DeviceProcessItem();
    return processList->at(proxyModel.mapToSource(indexes.first()).row());
}
示例#14
0
void DemandListModel::removeSelectedTuples(const QModelIndexList &selecteds){

	if(selecteds.empty()){
		return; //nothing to do.
	}

	QVector<int> rows;

	for(QModelIndex selected: selecteds) {
		if(!rows.contains(selected.row())){
			rows.push_back(selected.row());
		}
	}

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

	for(int i = 0; i < rows.size(); i++){

		beginRemoveRows(QModelIndex(), rows[i]-i, rows[i]-i);
		_usedIndexes.remove(_tuples[rows[i]-i].index);
		_tuples.removeAt(rows[i]-i);
		endRemoveRows();
	}

	emit(changedDatas());

}
示例#15
0
void TableWidget::keyPressEvent(QKeyEvent * event)
{
    // if ctrl_C
    QAbstractItemModel* model = this->model();

    if(event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier) ) {
        QModelIndexList cells = selectedIndexes();

        qSort(cells); // Necessary, otherwise they are in column order
        QString text;

        int numrows = 0;
        if(!cells.empty() ) {
           QString header =model->headerData(cells[0].column() ,Qt::Horizontal ).toString();
           numrows = header.split('\n').size();
        }

        QList<int> colList;
        int curRow = -1;
        foreach (const QModelIndex& cell, cells) {
            if(curRow!= - 1 && curRow!= cell.row()) break;
            colList.append(cell.column());
            curRow = cell.row();
        }

        for(int i = 0; i < 3; i ++) {
            foreach (int col, colList) {
               text += "\t";
               QStringList components= model->headerData(col ,Qt::Horizontal ).toString().split("\n");
               text += components[i];
           }
           text +="\n";
        }
示例#16
0
void ObjectInspector::ObjectInspectorPrivate::getSelection(Selection &s) const
{
    s.clear();

    if (!m_formWindow)
        return;

    const QModelIndexList currentSelectedIndexes = m_treeView->selectionModel()->selectedRows(0);
    if (currentSelectedIndexes.empty())
        return;

    // sort objects
    foreach (const QModelIndex &index, currentSelectedIndexes)
        if (QObject *object = m_model->objectAt(index))
            switch (selectionType(m_formWindow, object)) {
            case NoSelection:
                break;
            case QObjectSelection:
                // It is actually possible to select an action twice if it is in a menu bar
                // and in a tool bar.
                if (!s.objects.contains(object))
                    s.objects.push_back(object);
                break;
            case UnmanagedWidgetSelection:
                s.unmanaged.push_back(qobject_cast<QWidget *>(object));
                break;
            case ManagedWidgetSelection:
                s.managed.push_back(qobject_cast<QWidget *>(object));
                break;
            }
}
void DialogSelectScenario::sysSelectionChanged() {
    if (!_curScene) return;

    // which system within the scenario was selected?
    QItemSelectionModel* sel = _systable->selectionModel();
    if (!sel) return;
    QModelIndexList selli  = sel->selectedRows();
    if (selli.empty()) return;
    int row =selli.first().row();

    std::stringstream ss;

    // get it from active scenario
    std::vector<const MavSystem*> systems = _curScene->getSystems();
    if (row >= 0 && row < (int)systems.size()) {
        const MavSystem*s = systems[row];
        if (s) {

            std::string summary;
            s->get_summary(summary);
            ss << summary << endl;
        }
    }
    _stext->setText(QString::fromStdString(ss.str()));
}
void MainWindow::deleteAlbum()
{
    QModelIndexList selection = albumView->selectionModel()->selectedRows(0);

    if (!selection.empty()) {
        QModelIndex idIndex = selection.at(0);
        int id = idIndex.data().toInt();
        QString title = idIndex.sibling(idIndex.row(), 1).data().toString();
        QString artist = idIndex.sibling(idIndex.row(), 2).data().toString();

        QMessageBox::StandardButton button;
        button = QMessageBox::question(this, tr("Delete Album"),
                                       tr("Are you sure you want to "
                                          "delete '%1' by '%2'?")
                                       .arg(title, artist),
                                       QMessageBox::Yes | QMessageBox::No);

        if (button == QMessageBox::Yes) {
            removeAlbumFromFile(id);
            removeAlbumFromDatabase(idIndex);
            decreaseAlbumCount(indexOfArtist(artist));

            showImageLabel();
        }
    } else {
        QMessageBox::information(this, tr("Delete Album"),
                                 tr("Select the album you want to delete."));
    }
}
示例#19
0
void MainWindow::onTreeSelectionChanged(QItemSelection const & selected, QItemSelection const & /*deselected*/)
{
  if (m_ignoreTableSelection)
    return;

  QModelIndexList lst = selected.indexes();
  if (lst.empty())
    return;

  QModelIndex index = lst.first();
  QModelIndex currentRoot = m_ui->m_fileTable->rootIndex();
  if (m_fileModel->isDir(m_model->mapToSource(index)) && index != currentRoot)
  {
    m_ui->m_fileTable->setRootIndex(index);
    m_ui->m_fileTable->selectionModel()->clear();
  }
  else
  {
    QModelIndex idxParent = index.parent();
    if (idxParent != currentRoot)
      m_ui->m_fileTable->setRootIndex(idxParent);

    m_ui->m_fileTable->selectionModel()->select(selected, QItemSelectionModel::ClearAndSelect);
  }
}
示例#20
0
void WndSets::actDisable()
{
    QModelIndexList rows = view->selectionModel()->selectedRows();
    if(rows.empty())
        return;

    model->toggleRow(rows.first().row(), false);
}
示例#21
0
/**
  * Get the index of the selected parent account.
  *
  * @return The model index of the selected parent account.
  */
QModelIndex HierarchyFilterProxyModel::getSelectedParentAccountIndex() const
{
  QModelIndexList list = match(index(0, 0), AccountsModel::AccountIdRole, m_currentAccountId, -1, Qt::MatchFlags(Qt::MatchExactly | Qt::MatchCaseSensitive | Qt::MatchRecursive));
  if (!list.empty()) {
    return list.front().parent();
  }
  return QModelIndex();
}
/******************************************************************************
* Returns the currently selected item in the modification list.
******************************************************************************/
ModificationListItem* ModificationListModel::selectedItem() const
{
	QModelIndexList selection = _selectionModel->selectedRows();
	if(selection.empty())
		return nullptr;
	else
		return item(selection.front().row());
}
示例#23
0
void FilterLvl::locateItem (QString const & item, bool scrollto, bool expand)
{
	QModelIndexList indexList = m_model->match(m_model->index(0, 0), Qt::DisplayRole, item);
	if (!indexList.empty())
	{
		QModelIndex const selectedIndex(indexList.first());
		getWidget()->setCurrentIndex(selectedIndex);
	}
}
示例#24
0
void CQMiriamWidget::slotCopyEvent()
{
  CQSortFilterProxyModel* pProxyModel = NULL;
  CQBaseDataModel* pBaseDM = NULL;
  CQTableView* pTbl = NULL;

  if (mpTblAuthors->hasFocus())
    {
      pProxyModel = mpCreatorPDM;
      pBaseDM = mpCreatorDM;
      pTbl = mpTblAuthors;
    }
  else if (mpTblReferences->hasFocus())
    {
      pProxyModel = mpReferencePDM;
      pBaseDM = mpReferenceDM;
      pTbl = mpTblReferences;
    }
  else if (mpTblModified->hasFocus())
    {
      pProxyModel = mpModifiedPDM;
      pBaseDM = mpModifiedDM;
      pTbl = mpTblModified;
    }
  else if (mpTblDescription->hasFocus())
    {
      pProxyModel = mpBiologicalDescriptionPDM;
      pBaseDM = mpBiologicalDescriptionDM;
      pTbl = mpTblDescription;
    }

  QModelIndexList selRows = pTbl->selectionModel()->selectedRows(0);

  if (selRows.empty())
    {return;}

  QString str;
  QModelIndexList::const_iterator i;

  for (i = selRows.begin(); i != selRows.end(); ++i)
    {
      for (int x = 0; x < pBaseDM->columnCount(); ++x)
        {
          if (!pTbl->isColumnHidden(x))
            {
              if (!str.isEmpty())
                str += "\t";

              str += pBaseDM->index(pProxyModel->mapToSource(*i).row(), x).data().toString();
            }
        }

      str += "\n";
    }

  QApplication::clipboard()->setText(str);
}
void DeviceProcessesDialogPrivate::killProcess()
{
    const QModelIndexList indexes = procView->selectionModel()->selectedIndexes();
    if (indexes.empty() || !processList)
        return;
    updateListButton->setEnabled(false);
    killProcessButton->setEnabled(false);
    processList->killProcess(proxyModel.mapToSource(indexes.first()).row());
}
示例#26
0
int
StageListView::selectedRow() const
{
	QModelIndexList const selection(selectionModel()->selectedRows(0));
	if (selection.empty()) {
		return - 1;
	}
	return selection.front().row();
}
void DialogSpectraTemplates::on_pushEdit_clicked()
{
  QModelIndexList ixl = ui->spectraSetupView->selectionModel()->selectedRows();
  if (ixl.empty())
    return;
  int i = ixl.front().row();
  DialogSpectrumTemplate* newDialog = new DialogSpectrumTemplate(templates_.get(i), current_dets_, true, this);
  connect(newDialog, SIGNAL(templateReady(Qpx::Spectrum::Template)), this, SLOT(change_template(Qpx::Spectrum::Template)));
  newDialog->exec();
}
QString QgsAuthConfigEditor::selectedConfigId()
{
  QModelIndexList selection = tableViewConfigs->selectionModel()->selectedRows( 0 );

  if ( selection.empty() )
    return QString();

  QModelIndex indx = selection.at( 0 );
  return indx.sibling( indx.row(), 0 ).data().toString();
}
示例#29
0
void
PlaylistModel::showSelectedItem()
{
    QModelIndexList list = slct->selectedRows();
    if (list.empty()) return;

    dataChangeNotice(list[0].row(), img_num);
    showImages();
    emit changePlaylistStatus();
}
示例#30
0
bool TreeView::getSelectedRows(QModelIndexList& rowList)
{
  //bool success = false;
  QItemSelectionModel * selectionMod = NULL;
  selectionMod = selectionModel();
  if(selectionMod){
    //success = true;
    rowList = selectionMod->selectedRows();
  }
  return !rowList.empty();
}