Ejemplo n.º 1
0
void TutorialTreeSelectionManager::handleSelectionChanged(
                                            const QItemSelection& selected,
                                            const QItemSelection& deselected) {
    //Only single selections are supported
    Q_ASSERT(selected.count() <= 1);
    Q_ASSERT(deselected.count() <= 1);

    TreeItem* selectedItem = 0;
    TreeItem* deselectedItem = 0;

    if (selected.count() == 1) {
        Q_ASSERT(selected.at(0).indexes().count() == 1);

        QModelIndex index = selected.at(0).indexes().at(0);
        selectedItem = static_cast<TreeItem*>(index.internalPointer());
    }

    if (deselected.count() == 1) {
        Q_ASSERT(deselected.at(0).indexes().count() == 1);

        QModelIndex index = deselected.at(0).indexes().at(0);
        deselectedItem = static_cast<TreeItem*>(index.internalPointer());
    }

    updateStepSelection(selectedItem, deselectedItem);
    updateReactionSelection(selectedItem, deselectedItem);
}
Ejemplo n.º 2
0
Archivo: view.cpp Proyecto: Fale/qtmoko
QRect LinearView::selectionViewportRect(const QItemSelection &selection) const
{
    int ranges = selection.count();

    if (ranges == 0)
        return QRect();

    // Note that we use the top and bottom functions of the selection range
    // since the data is stored in rows.

    int firstRow = selection.at(0).top();
    int lastRow = selection.at(0).top();

    for (int i = 0; i < ranges; ++i) {
        firstRow = qMin(firstRow, selection.at(i).top());
        lastRow = qMax(lastRow, selection.at(i).bottom());
    }

    QModelIndex firstItem = model()->index(qMin(firstRow, lastRow), 0,
        QModelIndex());
    QModelIndex lastItem = model()->index(qMax(firstRow, lastRow), 0,
        QModelIndex());

    QRect firstRect = itemViewportRect(firstItem);
    QRect lastRect = itemViewportRect(lastItem);

    return QRect(firstRect.left(), firstRect.top(),
        lastRect.right() - firstRect.left(), firstRect.height());
}
Ejemplo n.º 3
0
void DevicesWidget::on_actionEditDeviceGroup_triggered()
{
    QItemSelection selection = deviceGroupList->selectionModel()->selection();

    // Ensure we have only one range selected which contains only one row
    if ((selection.size() == 1) && (selection.at(0).height() == 1))
        on_deviceGroupList_activated(selection.at(0).topLeft());
}
Ejemplo n.º 4
0
void K3b::DataViewImpl::slotRemove()
{
    // Remove items directly from sort model to avoid unnecessary mapping of indexes
    const QItemSelection selection = m_fileView->selectionModel()->selection();
    const QModelIndex parentDirectory = m_fileView->rootIndex();
    for( int i = selection.size() - 1; i >= 0; --i ) {
        m_sortModel->removeRows( selection.at(i).top(), selection.at(i).height(), parentDirectory );
    }
}
// Custom processing the Selection Changed in the Scene Graph model. Returns
// TRUE if no further processing needed.
bool ParticlesEditorSceneModelHelper::ProcessSelectionChanged(const QItemSelection &selected,
                                                         const QItemSelection &deselected)
{
    int32 deselectedSize = deselected.size();
    int32 selectedSize = selected.size();

    if (selectedSize <= 0)
    {
        // De-selection happened - allow processing by caller.
        ParticlesEditorController::Instance()->CleanupSelectedNode();
        return false;
    }
    
    // Determine whether the selected node belongs to Particle Editor.
    QItemSelectionRange selectedRange = selected.at(0);
    SceneGraphItem *selectedItem = static_cast<SceneGraphItem*>(selectedRange.topLeft().internalPointer());

    if (ParticlesEditorController::Instance()->IsBelongToParticlesEditor(selectedItem))
    {
        // Our one. Select and emit the appropriate event.
        ParticlesEditorController::Instance()->SetSelectedNode(selectedItem, true);
        return !ParticlesEditorController::Instance()->ShouldDisplayPropertiesInSceneEditor(selectedItem);
    }

    // Not ours. Cleanup the selected node and return control back to the caller.
    ParticlesEditorController::Instance()->CleanupSelectedNode();
    return false;
}
Ejemplo n.º 6
0
void ActionInspectorWidget::selectionChanged(const QItemSelection& selection)
{
    if (selection.isEmpty())
        return;
    const auto idx = selection.at(0).topLeft();
    ui->actionView->scrollTo(idx);
}
Ejemplo n.º 7
0
void SignalMonitorWidget::selectionChanged(const QItemSelection& selection)
{
    if (selection.isEmpty())
        return;
    const auto idx = selection.at(0).topLeft();
    ui->objectTreeView->scrollTo(idx);
}
Ejemplo n.º 8
0
void DevicesWidget::on_actionNewDeviceGroup_triggered()
{
    // In case nothing is selected, insert 1 row at the top
    int row = 0, count = 1;
    QItemSelection selection = deviceGroupList->selectionModel()->selection();

    if (!portGroups_)
       return;

    // In case we have a single range selected; insert as many rows as
    // in the singe selected range before the top of the selected range
    if (selection.size() == 1) {
        row = selection.at(0).top();
        count = selection.at(0).height();
    }

    portGroups_->getDeviceGroupModel()->insertRows(row, count);
}
Ejemplo n.º 9
0
bool ProxyEditWindow::canChangeProxy(const QItemSelection &selection)
{
    if (selection.size() == 0)
        return true;

    if (selection.size() != 1)
        return false;

    QModelIndex selectedItem = selection.at(0).topLeft();
    NetworkProxy proxy = selectedItem.data(NetworkProxyRole).value<NetworkProxy>();

    if (ForceProxyChange)
        return true;

    ConfigurationValueState currenState = state(proxy);
    if (StateNotChanged == currenState)
        return true;

    if (StateChangedDataValid == currenState)
    {
        QMessageBox::StandardButton result = QMessageBox::question(this, tr("Proxy"),
                                             tr("You have unsaved changes in current proxy.<br />Do you want to save them?"),
                                             QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes);

        switch (result)
        {
        case QMessageBox::Yes:
            saveProxy(proxy);
            return true;

        case QMessageBox::No:
            return true;

        default:
            return false;
        }
    }

    if (StateChangedDataInvalid == currenState)
    {
        QMessageBox::StandardButton result = QMessageBox::question(this, tr("Proxy"),
                                             tr("You have unsaved changes in current proxy.<br />This data is invalid, so you will loose all changes.<br />Do you want to go back to edit them?"),
                                             QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

        switch (result)
        {
        case QMessageBox::No:
            return true;

        default:
            return false;
        }
    }

    return true;
}
Ejemplo n.º 10
0
QModelIndex
selectedRowIdx(QItemSelection const &selection) {
    if (selection.isEmpty())
        return {};

    auto indexes = selection.at(0).indexes();
    if (indexes.isEmpty() || !indexes.at(0).isValid())
        return {};

    auto idx = indexes.at(0);
    return idx.sibling(idx.row(), 0);
}
Ejemplo n.º 11
0
QRegion PieView::visualRegionForSelection(const QItemSelection &selection) const
{
    int ranges = selection.count();

    if (ranges == 0)
        return QRect();

    QRegion region;
    for (int i = 0; i < ranges; ++i) {
        QItemSelectionRange range = selection.at(i);
        for (int row = range.top(); row <= range.bottom(); ++row) {
            for (int col = range.left(); col <= range.right(); ++col) {
                QModelIndex index = model()->index(row, col, rootIndex());
                region += visualRect(index);
            }
        }
    }
    return region;
}
Ejemplo n.º 12
0
QModelIndexList QtTreeWidget::getSelectedIndexes() const {
    // Not using selectedIndexes(), because this seems to cause a crash in Qt (4.7.0) in the
    // QModelIndexList destructor.
    // This is a workaround posted in http://www.qtcentre.org/threads/16933 (although this case
    // was resolved by linking against the debug libs, ours isn't, and we're not alone)
    QItemSelection ranges = selectionModel()->selection();
    QModelIndexList selectedIndexList;
    for (int i = 0; i < ranges.count(); ++i) {
        QModelIndex parent = ranges.at(i).parent();
        int right = ranges.at(i).model()->columnCount(parent) - 1;
        if (ranges.at(i).left() == 0 && ranges.at(i).right() == right) {
            for (int r = ranges.at(i).top(); r <= ranges.at(i).bottom(); ++r) {
                selectedIndexList.append(ranges.at(i).model()->index(r, 0, parent));
            }
        }
    }
    return selectedIndexList;
}
Ejemplo n.º 13
0
void VideoView::selectionChanged(const QItemSelection &selected, const QItemSelection &)
{
    if (selected.isEmpty()) {
        return;
    }

    QModelIndex selectedIndex = selected.at(0).indexes().at(0);
    _currentVideoRow = selectedIndex.row();

    _view->setScene(_videos.at(_currentVideoRow).scene);
    _view->fitInView(_view->sceneRect(), Qt::KeepAspectRatio);

    _playBar->setPlayData(model()->rowCount(
                              model()->index(
                                  _currentVideoRow,
                                  VideoModel::FramesColumn)),
                          model()->data(
                              model()->index(_currentVideoRow,
                                             VideoModel::FrameDurationColumn)).toInt());
}
Ejemplo n.º 14
0
void CourseEditUI::tableViewSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected )
{
	if(selected.count() > 0)
	{
		QModelIndexList selectedList = selected.at(0).indexes();
		if(selectedList.count() > 0)
		{
			QString question = selectedList.value(0).data().toString();
			QString answer = selectedList.value(1).data().toString();
			txtQuestion->setText(question);
			txtAnswer->setText(answer);
			for(Items::const_iterator it = _items.begin(); it != _items.end(); ++it)
			{
				if(it->get()->GetQuestion() == question.toStdString() && it->get()->GetAnswer() == answer.toStdString())
				{
					_currentItem = *it;
					return;
				}
				
			}
			_currentItem = ItemPtr();
		}
	}
}
Ejemplo n.º 15
0
int SearchPopup::selectedItem() const
{
	QItemSelection selection = listView_->selectionModel()->selection();
	return (selection.length() == 0) ? -1 : selection.at(0).top();
}