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);
}
Example #2
0
void MainWindow::testsTree_selectionChanged(QItemSelection newSel, QItemSelection /*oldSel*/)
{
    bool enabled = newSel.count() > 0 && !_model.isRunning();

    _ui->actionRemove_test_executable->setEnabled(enabled);
    _ui->actionRefresh_tests->setEnabled(enabled);

    if (newSel.count() > 0) {
        updateOutput(static_cast<TestItemBase*>(newSel.first().indexes().first().internalPointer()));
    }
}
void MainWindow::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
    Q_UNUSED(deselected);
    bool value = selected.count();
    m_removeButton->setEnabled(value);
    m_toggleButton->setEnabled(value);
}
Example #4
0
File: view.cpp Project: 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());
}
Example #5
0
void MainForm::selectedGameChanged(const QItemSelection & selected, const QItemSelection & deselected) {
	if(selected.count()==1) {
		FrameOptionen->setEnabled(true);
		// Spiel ausgewählt --> Optionen rechts anzeigen
		if(Spieleliste->getItem(selected.indexes().first()).getOptions()->getEmulator()==CAbstraktOptions::GNUBOY) {
			ComboEmulator->blockSignals(true);
			ComboEmulator->setCurrentIndex(CAbstraktOptions::GNUBOY);
			ComboEmulator->blockSignals(false);
			GnuboyOptionenBox->setOptionsPtr(((CGnuboyOptions*)Spieleliste->getItem(selected.indexes().first()).getOptions()));
			VBAOptionenBox->setVisible(false);
			GnuboyOptionenBox->setVisible(true);
		}
		else {
			ComboEmulator->blockSignals(true);
			ComboEmulator->setCurrentIndex(CAbstraktOptions::VBA);
			ComboEmulator->blockSignals(false);
			VBAOptionenBox->setOptionsPtr(((CVBAOptions*)Spieleliste->getItem(selected.indexes().first()).getOptions()));
			GnuboyOptionenBox->setVisible(false);
			VBAOptionenBox->setVisible(true);
		}
	}
	else {
		FrameOptionen->setEnabled(false);
	}
}
Example #6
0
void ShowDetailWidget::currentEpisodeChanged(const QItemSelection &selected, const QItemSelection &)
{
    if (selected.count() == 0) {
        _episode = -1;
        return;
    }

    QSqlRecord record = episodeModel->record(selected.indexes()[0].row());
    _episode = record.value("episode").toInt();

    refreshEpisodesComboBox();

    QSqlQuery query;
    qint64 last_check_epoch = 0;
    qint64 expiration = 24 * 60 * 60 * 1000; // one day => TODO parametrable

    query.prepare("SELECT subtitles_last_check_date FROM episode WHERE show_id=:show_id AND season=:season AND episode=:episode");
    query.bindValue(":show_id", _showId);
    query.bindValue(":season", _season);
    query.bindValue(":episode", _episode);
    query.exec();
    if (query.next() && !query.value(0).isNull()) {
        last_check_epoch = query.value(0).toLongLong() * 1000;
    }
    if (QDateTime::currentDateTime().toMSecsSinceEpoch() - last_check_epoch > expiration) {
        // expired data, we need to launch the request
        int ticket = CommandManager::instance().subtitlesShow(_showId, _season, _episode);
        tickets.insert(ticket, _episode);
        LoadingWidget::showLoadingMask(ui->treeViewSubtitles);
    } else {
        refreshSubtitleTree(_episode);
    }
}
Example #7
0
void SelectionModel::select( const QItemSelection &selection, QItemSelectionModel::SelectionFlags command )
{
  // Don't allow the current selection to be cleared
  if ( !selection.count() && ( command & QItemSelectionModel::Clear ) ) {
    return;
  }
  QItemSelectionModel::select( selection, command );
}
Example #8
0
void AuthorGroupPage::updateDetails(const QItemSelection &newSelection, const QItemSelection &oldSelection)
{
    if (oldSelection.count())
    {
        QModelIndexList list = oldSelection.indexes();

        if (!list.isEmpty())
        {
            QModelIndex index = list.at(0);
            Author author = model->data(index, Qt::EditRole).value<Author>();

            author.userName = ui.userName->text();
            author.realName = ui.realName->text();
            author.email	= ui.email->text();
            author.homePage = ui.homePage->text();
            author.contributionStatus = ui.contributionStatus->text();
            author.contributionFrom = ui.contributionFrom->date();
            author.contributionTo = ui.contributionTo->date();

            model->setData(index, QVariant::fromValue(author));
        }
    }

    Author author;
    if (newSelection.count())
    {
        QModelIndexList list = newSelection.indexes();
        if (!list.isEmpty())
        {
            author = model->data(list.at(0), Qt::EditRole).value<Author>();
        }
    }

    ui.userName->setText(author.userName);
    ui.realName->setText(author.realName);
    ui.email->setText(author.email);

    ui.homePage->setText(author.homePage);
    ui.contributionStatus->setText(author.contributionStatus);
    ui.contributionFrom->setDate(author.contributionFrom);
    ui.contributionTo->setDate(author.contributionTo);

}
void QgsRuleBasedRendererWidget::removeRule()
{
  QItemSelection sel = viewRules->selectionModel()->selection();
  QgsDebugMsg( QString( "REMOVE RULES!!! ranges: %1" ).arg( sel.count() ) );
  Q_FOREACH ( const QItemSelectionRange &range, sel )
  {
    QgsDebugMsg( QString( "RANGE: r %1 - %2" ).arg( range.top() ).arg( range.bottom() ) );
    if ( range.isValid() )
      mModel->removeRows( range.top(), range.bottom() - range.top() + 1, range.parent() );
  }
Example #10
0
void medDatabaseView::onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
{
    if (selected.count() == 0)
    {
        emit noPatientOrSeriesSelected();
        return;
    }

    // If we're already holding down CTRL or SHIFT, change behaviour to not open but rather just select, so we can select multiple elements
    Qt::KeyboardModifiers activeKeyboardModifiers = QApplication::keyboardModifiers();

    if (activeKeyboardModifiers & (Qt::ControlModifier | Qt::ShiftModifier))
    {
        QVector<medDataIndex> test;
        for (int i = 0; i < selected.size(); i++)
        {
            QModelIndex index = selected.indexes()[i];
            medAbstractDatabaseItem* item = getItemFromIndex(index);

            if (item)
                test.push_back(item->dataIndex());

        }
        emit multipleEntriesSelected(test);
        return;
    }
        
    // If we don't have the modifer keys pressed, expand the selected element.
    QModelIndex index = selected.indexes()[0];
    medAbstractDatabaseItem *item = getItemFromIndex(index);

    if (!item)
        return;

    if (item->dataIndex().isValidForSeries())
    {
        this->setExpanded(index.parent().parent(), true);
        this->setExpanded(index.parent(), true);
        this->setExpanded(index, true);
        emit seriesClicked(item->dataIndex());
    }
    else if (item->dataIndex().isValidForStudy())
    {
        this->setExpanded(index, true);
        emit studyClicked(item->dataIndex());
    }
    else if (item->dataIndex().isValidForPatient())
    {
        this->setExpanded(index, true);
        emit patientClicked(item->dataIndex());
    }

}
Example #11
0
void LayerList::selectionChanged(const QItemSelection &selected)
{
	bool on = selected.count() > 0;

	if(on) {
		QModelIndex cs = currentSelection();
		dataChanged(cs,cs);
		_selected = cs.data().value<net::LayerListItem>().id;
	} else {
		_selected = 0;
	}

	updateLockedControls();

	emit layerSelected(_selected);
}
Example #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;
}
Example #13
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;
}
/*!
    \reimp
 */
QItemSelection QIdentityProxyModel::mapSelectionToSource(const QItemSelection& selection) const
{
    Q_D(const QIdentityProxyModel);
    QItemSelection sourceSelection;

    if (!d->model)
        return sourceSelection;

    QItemSelection::const_iterator it = selection.constBegin();
    const QItemSelection::const_iterator end = selection.constEnd();
    sourceSelection.reserve(selection.count());
    for ( ; it != end; ++it) {
        Q_ASSERT(it->model() == this);
        const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight()));
        sourceSelection.append(range);
    }

    return sourceSelection;
}
Example #15
0
void TileAssetView::selectionChanged(const QItemSelection &selected, const QItemSelection& deselected)
{
    QListView::selectionChanged(selected, deselected);
    MapEditSettings editSettings;

    if (selected.count() == 0) {
        editSettings.editState = MapEditSettings::Idle;
        editSettings.setAssetId = 0;
    } else {
        TileAssetModel* libModel = qobject_cast<TileAssetModel *>(model());
        QVariant v = libModel->data(selected.indexes().at(0),Qt::EditRole);
        TAssetDef* assetDef = v.value<TAssetDef*>();
        
        editSettings.editState = MapEditSettings::Background;
        editSettings.setAssetId = assetDef->id;
    }

    emit mapEditSettingsChanged(editSettings);
}
Example #16
0
QItemSelection FlatProxyModel::mapSelectionToSource(const QItemSelection& proxySelection) const
{
    QItemSelection sourceSelection;

    for (int i = 0; i < proxySelection.count(); i++) {
        const QItemSelectionRange& range = proxySelection[i];

        SourceItem* topLeftItem = nullptr;
        SourceItem* bottomRightItem = nullptr;
        auto* currentItem = static_cast<SourceItem*>(range.topLeft().internalPointer());
        int row = range.topLeft().row();
        int left = range.topLeft().column();
        int right = range.bottomRight().column();
        while (currentItem && row <= range.bottomRight().row()) {
            Q_ASSERT(currentItem->pos() == row);
            if (!topLeftItem)
                topLeftItem = currentItem;

            if (currentItem->parent() == topLeftItem->parent()) {
                bottomRightItem = currentItem;
            }
            else {
                Q_ASSERT(topLeftItem && bottomRightItem);
                sourceSelection << QItemSelectionRange(mapToSource(createIndex(topLeftItem->pos(), left, topLeftItem)),
                                                       mapToSource(createIndex(bottomRightItem->pos(), right, bottomRightItem)));
                topLeftItem = nullptr;
                bottomRightItem = nullptr;
            }

            // update loop vars
            currentItem = currentItem->next();
            row++;
        }

        if (topLeftItem && bottomRightItem) {  // there should be one range left.
            sourceSelection << QItemSelectionRange(mapToSource(createIndex(topLeftItem->pos(), left, topLeftItem)),
                                                   mapToSource(createIndex(bottomRightItem->pos(), right, bottomRightItem)));
        }
    }

    return sourceSelection;
}
void medDatabaseView::onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
{
    if (selected.count() == 0)
    {
        emit noPatientOrSeriesSelected();
        return;
    }
        
    // so far we only allow single selection
    QModelIndex index = selected.indexes()[0];

    medAbstractDatabaseItem *item = NULL;

    if(QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(this->model()))
        item = static_cast<medAbstractDatabaseItem *>(proxy->mapToSource(index).internalPointer());
    else if (dynamic_cast<QAbstractItemModel *>(this->model()))
        item = static_cast<medAbstractDatabaseItem *>(index.internalPointer());

    if (!item)
        return;

    if (item->dataIndex().isValidForSeries())
    {
        this->setExpanded(index.parent().parent(), true);
        this->setExpanded(index.parent(), true);
        this->setExpanded(index, true);
        emit seriesClicked(item->dataIndex());
    }
    else if (item->dataIndex().isValidForStudy())
    {
        this->setExpanded(index, true);
        emit studyClicked(item->dataIndex());
    }
    else if (item->dataIndex().isValidForPatient())
    {
        this->setExpanded(index, true);
        emit patientClicked(item->dataIndex());
    }
}
Example #18
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();
		}
	}
}
Example #19
0
QItemSelection FlatProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const
{
    QList<_RangeRect> newRanges;
    QHash<QModelIndex, SourceItem *> itemLookup;
    // basics steps of the loop:
    // 1. convert each source ItemSelectionRange to a mapped Range (internal one for easier post processing)
    // 2. insert it into the list of previously mapped Ranges sorted by top location
    for (int i = 0; i < sourceSelection.count(); i++) {
        const QItemSelectionRange &currentRange = sourceSelection[i];
        QModelIndex currentParent = currentRange.topLeft().parent();
        Q_ASSERT(currentParent == currentRange.bottomRight().parent());

        SourceItem *parentItem = 0;
        if (!itemLookup.contains(currentParent)) {
            parentItem = sourceToInternal(currentParent);
            itemLookup[currentParent] = parentItem;
        }
        else {
            parentItem = itemLookup[currentParent];
        }

        _RangeRect newRange = { currentRange.topLeft().column(), currentRange.bottomRight().column(),
                                currentRange.topLeft().row(), currentRange.bottomRight().row(),
                                parentItem->child(currentRange.topLeft().row()), parentItem->child(currentRange.bottomRight().row()) };

        if (newRanges.isEmpty()) {
            newRanges << newRange;
            continue;
        }

        _RangeRect &first = newRanges[0];
        if (newRange < first) {
            newRanges.prepend(newRange);
            continue;
        }

        bool inserted = false;
        for (int j = 0; j < newRanges.count() - 1; j++) {
            _RangeRect &a = newRanges[j];
            _RangeRect &b = newRanges[j + 1];

            if (a < newRange && newRange < b) {
                newRanges[j + 1] = newRange;
                inserted = true;
                break;
            }
        }
        if (inserted)
            continue;

        _RangeRect &last = newRanges[newRanges.count() - 1];
        if (last < newRange) {
            newRanges.append(newRange);
            continue;
        }

        Q_ASSERT(false);
    }

    // we've got a sorted list of ranges now. so we can easily check if there is a possibility to merge
    for (int i = newRanges.count() - 1; i > 0; i--) {
        _RangeRect &a = newRanges[i - 1];
        _RangeRect &b = newRanges[i];
        if (a.left != b.left || a.right != b.right)
            continue;

        if (a.bottom < b.top - 1) {
            continue;
        }

        // all merge checks passed!
        if (b.bottom > a.bottom) {
            a.bottom = b.bottom;
            a.bottomItem = b.bottomItem;
        } // otherwise b is totally enclosed in a -> nothing to do but drop b.
        newRanges.removeAt(i);
    }

    QItemSelection proxySelection;
    for (int i = 0; i < newRanges.count(); i++) {
        _RangeRect &r = newRanges[i];
        proxySelection << QItemSelectionRange(createIndex(r.top, r.left, r.topItem), createIndex(r.bottom, r.right, r.bottomItem));
    }
    return proxySelection;
}
void CategoriesWidget::slotSelectionChanged(const QItemSelection& selected, const QItemSelection&)
{
    m_buttonEditCategory->setEnabled(selected.count() == 1);
    m_buttonRemoveCategory->setEnabled(selected.count() > 0);
}