Exemple #1
0
QModelIndex TiledListView::indexAt(const QPoint &point_) const
{
    QPoint point(point_);
    point.rx() += horizontalScrollBar()->value();
    point.ry() += verticalScrollBar()->value();
    calculateRectsIfNecessary();
    QHashIterator<int, QRectF> i(rectForRow);
    while (i.hasNext()) {
        i.next();
        if (i.value().contains(point))
            return model()->index(i.key(), 0, rootIndex());
    }
    return QModelIndex();
}
void GroupListView::Paste()
{
    int row=-1;
    if(currentIndex().isValid())
        row=currentIndex().row();

    const QMimeData *mime = QApplication::clipboard()->mimeData();
    foreach( const QString &t, MimeTypes() ) {
        if(mime->hasFormat(t)) {
            model()->dropMimeData( mime, Qt::CopyAction, row, 0, rootIndex() );
            return;
        }
    }
}
void PieView::rowsInserted(const QModelIndex &parent, int start, int end)
{
    for (int row = start; row <= end; ++row) {
        QModelIndex index = model()->index(row, 1, rootIndex());
        double value = model()->data(index).toDouble();

        if (value > 0.0) {
            totalValue += value;
            ++validItems;
        }
    }

    QAbstractItemView::rowsInserted(parent, start, end);
}
Exemple #4
0
/** ***************************************************************************/
void ProposalList::reset() {
    // Reset the views state
    QListView::reset();
    scrollToTop(); // Why is this needed?

    // Show if not empty and make first item current
    if (model()!=nullptr && model()->hasChildren(rootIndex())) {
        show();
        // Make the size of this widget be adjusted (size hint changed)
        updateGeometry();
    }
    else
        hide();
}
QRect PieView::itemRect(const QModelIndex &index) const
{
    if (!index.isValid())
        return QRect();

    // Check whether the index's row is in the list of rows represented
    // by slices.
    QModelIndex valueIndex;

    if (index.column() != 1)
        valueIndex = model()->index(index.row(), 1, rootIndex());
    else
        valueIndex = index;

    if (model()->data(valueIndex).toDouble() <= 0.0)
        return QRect();

    int listItem = 0;
    for (int row = index.row()-1; row >= 0; --row) {
        if (model()->data(model()->index(row, 1, rootIndex())).toDouble() > 0.0)
            listItem++;
    }

    double itemHeight;

    switch (index.column()) {
    case 0:
        itemHeight = QFontMetrics(viewOptions().font).height();

        return QRect(totalSize,
                     int(margin + listItem*itemHeight),
                     totalSize - margin, int(itemHeight));
    case 1:
        return viewport()->rect();
    }
    return QRect();
}
QModelIndex PieView::indexAt(const QPoint &point) const
{
    if (validItems == 0)
        return QModelIndex();

    int wx = point.x() + horizontalScrollBar()->value();
    int wy = point.y() + verticalScrollBar()->value();

    if (wx < totalSize) {
        double cx = wx - totalSize/2;
        double cy = totalSize/2 - wy;

        double d = pow(pow(cx, 2) + pow(cy, 2), 0.5);

        if (d == 0 || d > pieSize/2)
            return QModelIndex();

        double angle = (180 / M_PI) * acos(cx/d);
        if (cy < 0)
            angle = 360 - angle;

        double startAngle = 0.0;

        for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {

            QModelIndex index = model()->index(row, 1, rootIndex());
            double value = model()->data(index).toDouble();

            if (value > 0.0) {
                double sliceAngle = 360*value/totalValue;

                if (angle >= startAngle && angle < (startAngle + sliceAngle))
                    return model()->index(row, 1, rootIndex());

                startAngle += sliceAngle;
            }
        }
    } else {
        double itemHeight = QFontMetrics(viewOptions().font).height();
        int listItem = int((wy - margin) / itemHeight);
        int validRow = 0;

        for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {

            QModelIndex index = model()->index(row, 1, rootIndex());
            if (model()->data(index).toDouble() > 0.0) {

                if (listItem == validRow)
                    return model()->index(row, 0, rootIndex());

                validRow++;
            }
        }
    }

    return QModelIndex();
}
Exemple #7
0
void EditTableView::removeSelected()
{
    if (!model() || !selectionModel() || !selectionModel()->hasSelection())
        return;

    QModelIndexList selectedRows = selectionModel()->selectedRows();
    if (selectedRows.isEmpty())
        return;

    int newSelectedRow = selectedRows.at(0).row();
    for (int i = selectedRows.count() - 1; i >= 0; --i) {
        QModelIndex idx = selectedRows.at(i);
        model()->removeRow(idx.row(), rootIndex());
    }

    // select the item at the same position
    QModelIndex newSelectedIndex = model()->index(newSelectedRow, 0, rootIndex());
    // if that was the last item
    if (!newSelectedIndex.isValid())
        newSelectedIndex = model()->index(newSelectedRow - 1, 0, rootIndex());

    selectionModel()->select(newSelectedIndex, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
    setCurrentIndex(newSelectedIndex);
}
Exemple #8
0
QRegion PieView::itemRegion(const QModelIndex &index) const
{
    if (!index.isValid())
        return QRegion();

    if (index.column() != 1)
        return itemRect(index);

    if (model()->data(index).toDouble() <= 0.0)
        return QRegion();

    double startAngle = 0.0;
    for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {

        QModelIndex sliceIndex = model()->index(row, 1, rootIndex());
        double value = model()->data(sliceIndex).toDouble();

        if (value > 0.0) {
            double angle = 360*value/totalValue;

            if (sliceIndex == index) {
                QPainterPath slicePath;
                slicePath.moveTo(totalSize/2, totalSize/2);
                slicePath.arcTo(margin, margin, margin+pieSize, margin+pieSize,
                                startAngle, angle);
                slicePath.closeSubpath();

                return QRegion(slicePath.toFillPolygon().toPolygon());
            }

            startAngle += angle;
        }
    }

    return QRegion();
}
bool DataSourceView::navigateToDirectory(const QString &path)
{
	// find the common root path. Then ise the index.
	// note: all QFileSystemModels have the index(path) so we need to
	// handle prefixes. ::match() did not work here.
	QString root = m_model->filePath(m_proxy->mapToSource(rootIndex()));
	if (!path.startsWith(root))
		return false;

	auto index = m_proxy->mapFromSource(m_model->index(path));
	setCurrentIndex(index);
	setExpanded(index, true);

	return true;
}
Exemple #10
0
void TableView::cdUp()
{
    QWidget* w = parentWidget();
    if(w == NULL)
        return;

    ViewPanelTab* vp = dynamic_cast<ViewPanelTab*>(w);
    if(vp == NULL)
        return;

    setCurrentIndex(model()->index(0, 0, rootIndex()));

    model()->removeRows(0, model()->rowCount());
    vp->cdUp();
}
Exemple #11
0
void TableView::openItem(const QModelIndex &index)
{
    QWidget* w = parentWidget();
    if(w == NULL)
        return;

    ViewPanelTab* vp = dynamic_cast<ViewPanelTab*>(w);
    if(vp == NULL)
        return;

    setCurrentIndex(model()->index(0, 0, rootIndex()));

    model()->removeRows(0, model()->rowCount());
    vp->openItem(index.row());
}
Exemple #12
0
QModelIndex PieView::indexAt(const QPoint &point) const
{
    QPoint newPoint(point.x(),point.y());
    QRegion region;
    foreach(region,RegionList)				// 销售数量 列
    {
        if (region.contains(newPoint))
        {
            int row = RegionList.indexOf(region);
            QModelIndex index = model()->index(row,1,rootIndex());
            return index;
        }
    }
    return QModelIndex();
}
QRegion TiledListView::visualRegionForSelection(
        const QItemSelection &selection) const
{
    QRegion region;
    foreach (const QItemSelectionRange &range, selection) {
        for (int row = range.top(); row <= range.bottom(); ++row) {
            for (int column = range.left(); column < range.right();
                 ++column) {
                QModelIndex index = model()->index(row, column,
                                                   rootIndex());
                region += visualRect(index);
            }
        }
    }
    return region;
}
Exemple #14
0
void TTreeWidget::mousePressEvent( QMouseEvent *event )
{
    QModelIndex indexClicked = indexAt(event->pos());
    if( mIsVarTree && indexClicked.isValid() )
    {
        QRect vrect = visualRect(indexClicked);
        int itemIndentation = vrect.x() - visualRect(rootIndex()).x();
        QRect rect = QRect(header()->sectionViewportPosition(0) + itemIndentation,
                           vrect.y(), style()->pixelMetric(QStyle::PM_IndicatorWidth), vrect.height());
        if(rect.contains(event->pos()))
        {
            mClickedItem = indexClicked;
            QTreeWidget::mousePressEvent(event);
            return;
        }
    }
    QTreeWidget::mousePressEvent(event);
}
Exemple #15
0
void DeviceExplorerView::paintEvent(QPaintEvent* event)
{
  QTreeView::paintEvent(event);
  if (model() && model()->rowCount(rootIndex()) > 0)
    return;

  QPainter p{this->viewport()};
  const auto& skin = score::Skin::instance();
  auto font = skin.Bold12Pt;
  font.setPointSize(24);
  p.setFont(font);
  auto pen = p.pen();
  auto col = pen.color();
  col.setAlphaF(0.5);
  pen.setColor(col);
  p.setPen(pen);
  p.drawText(rect(), Qt::AlignCenter, "Right-click\nto add a device");
}
Exemple #16
0
void RosterTreeView::selectFirst()
{
	for(int i = 0; i < model()->rowCount(); ++i) {
		QModelIndex idx = model()->index(i, 0, rootIndex());
		QModelIndex index = dynamic_cast<RosterSortProxy*>(model())->mapToSource(idx);

		if(index.data(RosterItem::TypeRole).toInt() == RosterItem::Contact) {
			selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
			return;
		} else if(index.data(RosterItem::TypeRole).toInt() == RosterItem::Group) {
			if(model()->rowCount(idx)) {
				selectionModel()->setCurrentIndex(model()->index(0, 0, idx), QItemSelectionModel::ClearAndSelect);
				return;
			}
		}
	}

}
Exemple #17
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;
}
Exemple #18
0
void TTreeWidget::mouseReleaseEvent( QMouseEvent *event )
{
    QModelIndex indexClicked = indexAt(event->pos());
    if( mIsVarTree && indexClicked.isValid() && mClickedItem == indexClicked )
    {
        QRect vrect = visualRect(indexClicked);
        int itemIndentation = vrect.x() - visualRect(rootIndex()).x();
        QRect rect = QRect(header()->sectionViewportPosition(0) + itemIndentation,
                           vrect.y(), style()->pixelMetric(QStyle::PM_IndicatorWidth), vrect.height());
        if(rect.contains(event->pos()))
        {
            QTreeWidgetItem * clicked = itemFromIndex( indexClicked );
            if ( ! ( clicked->flags()&Qt::ItemIsUserCheckable ) )
                return;
            if ( clicked->checkState( 0 ) == Qt::Unchecked )
            {
                clicked->setCheckState( 0, Qt::Checked );
                //get all children and see what ones we can save
                QList< QTreeWidgetItem * > list;
                getAllChildren( clicked, list );
                QListIterator< QTreeWidgetItem * > it(list);
                LuaInterface * lI = mpHost->getLuaInterface();
                VarUnit * vu = lI->getVarUnit();
                while( it.hasNext() )
                {
                    QTreeWidgetItem * item = it.next();
                    if ( ! vu->shouldSave( item ) )
                        item->setCheckState( 0, Qt::Unchecked );
                }
            }
            else
            {
                clicked->setCheckState( 0, Qt::Unchecked );
            }
            return;
        }
    }
    QTreeWidget::mouseReleaseEvent(event);
}
/*!
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;
}
void CExplorerView::SetProjectPath(const QString& a_sProjectPath)
{
    m_sRoot = QString(a_sProjectPath);
//    m_pFileModel = new CFileSystemModel(this);
    m_pFileModel->setFilter(QDir::NoDot | QDir::Files | QDir::Dirs);
    m_pFileModel->sort(1);
    setModel(m_pFileModel);
    m_pFileModel->setReadOnly(false);
    SetCurrentDir(a_sProjectPath);
    setCurrentIndex(rootIndex());
    setSelectionMode( QAbstractItemView::ExtendedSelection );
    CreateContextMenuActions();

    this->show();
    this->setEditTriggers(QAbstractItemView::EditKeyPressed | QAbstractItemView::SelectedClicked);
    this->setAcceptDrops(true);
    this->setDropIndicatorShown(true);
    this->setDragDropMode(QAbstractItemView::DragDrop);
    this->setDragDropOverwriteMode(true);
    this->setContextMenuPolicy(Qt::DefaultContextMenu);

    m_oTimer->setSingleShot(true);
    connect(m_oTimer, SIGNAL(timeout()), this, SLOT(dragIdle()));
}
Exemple #21
0
void BookmarksToolBar::removeBookmark()
{
    QModelIndex index = ModelToolBar::index(qobject_cast<QAction*>(sender()));

    m_bookmarksModel->removeRow(index.row(), rootIndex());
}
Exemple #22
0
void BookmarksToolBar::newBookmark()
{
    AddBookmarkDialog dialog;
    dialog.setCurrentIndex(rootIndex());
    dialog.exec();
}
Exemple #23
0
void ColorGridView::paintEvent(QPaintEvent *event)
{
    // To make it clear, we do not use delegate at all
    //    QItemSelectionModel *selections = selectionModel();
    QStyleOptionViewItem option = viewOptions();
    QStyle::State state = option.state;

    QBrush background = option.palette.base();
    QPen foreground(option.palette.color(QPalette::WindowText));
    QPen textPen(option.palette.color(QPalette::Text));
    QPen highlightedPen(option.palette.color(QPalette::HighlightedText));

    QPainter painter(viewport());
    // close anti aliasing to make it more clear
    //        painter.setRenderHint(QPainter::Antialiasing);

    painter.fillRect(event->rect(), background);
    painter.setPen(Qt::white);
    QBrush brush;
    brush.setTextureImage(backgroundImg);
    painter.setBrush(brush);

    painter.translate(margin - horizontalScrollBar()->value(),
                      margin - verticalScrollBar()->value());
    for(int i = 0; i<gridCount; ++i){
        for(int j=0; j<gridCount; ++j){
            painter.drawImage(i*(gridMargin+gridWidth),j*(gridMargin+gridWidth),
                              backgroundImg);
        }
    }

    if( !model() )return;
    for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
        for(int column = 0; column < model()->columnCount(rootIndex()); ++column)
        {
            QModelIndex index = model()->index(row, column, rootIndex());
            QColor color = model()->data(index).value<QColor>();

            int j = index.row();
            int i = index.column();
            if(color.isValid()){
                //draw white background to prevent disturbings of background if transparent color
                painter.setBrush(Qt::white);
                painter.drawRect(i*(gridMargin+gridWidth),j*(gridMargin+gridWidth),
                                 gridWidth,gridWidth);
                painter.setBrush(color);
                painter.drawRect(i*(gridMargin+gridWidth),j*(gridMargin+gridWidth),
                                 gridWidth,gridWidth);
            }
        }
    }
    QModelIndexList list = selectedIndexes();
    if( !list.isEmpty() ){
        QModelIndex index = list.at(0);
        //        Qt::ItemFlags flags = index.flags();
        //        if(flags.testFlag(QItemSelectionModel::Select)){
        painter.setPen(textPen);
        //        }
        //        if(flags.testFlag(QItemSelectionModel::Toggle)){
        //            painter.setPen(highlightedPen);
        //        }
        int row = index.row();
        int column = index.column();
        //        QPointF start(column*(gridMargin+gridWidth),row*(gridMargin+gridWidth));
        //        QRadialGradient gradient(start+QPointF(gridWidth/2,gridWidth/2),0.1,start+QPointF(gridWidth,gridWidth));
        //        gradient.setColorAt(0.5,Qt::transparent);
        //        gradient.setColorAt(1.0,Qt::black);
        //        foreground = QPen(Qt::black);

        //        QBrush brush(gradient);
        //        brush.setStyle(Qt::RadialGradientPattern);
        painter.setBrush(Qt::NoBrush);
        //        painter.setBrush(brush);
        painter.drawRect(column*(gridMargin+gridWidth),row*(gridMargin+gridWidth),
                         gridWidth,gridWidth);
    }
}
Exemple #24
0
void EditTreeView::removeAll()
{
    if (!model())
        return;
    model()->removeRows(0, model()->rowCount(rootIndex()), rootIndex());
}
QString ModelDescriptorListWidget::experimentType() const
{
    return rootIndex().data(Qt::DisplayRole).toString();
}
Exemple #26
0
QModelIndex PieView::indexAt(const QPoint &point) const
{
    if (validItems == 0)
        return QModelIndex();

    // Transform the view coordinates into contents widget coordinates.
    int wx = point.x() + horizontalScrollBar()->value();
    int wy = point.y() + verticalScrollBar()->value();

    if (wx < totalSize) {
        double cx = wx - totalSize/2;
        double cy = totalSize/2 - wy; // positive cy for items above the center

        // Determine the distance from the center point of the pie chart.
        double d = pow(pow(cx, 2) + pow(cy, 2), 0.5);

        if (d == 0 || d > pieSize/2)
            return QModelIndex();

        // Determine the angle of the point.
        double angle = (180 / M_PI) * acos(cx/d);
        if (cy < 0)
            angle = 360 - angle;

        // Find the relevant slice of the pie.
        double startAngle = 0.0;

        for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {

            QModelIndex index = model()->index(row, 1, rootIndex());
            double value = model()->data(index).toDouble();

            if (value > 0.0) {
                double sliceAngle = 360*value/totalValue;

                if (angle >= startAngle && angle < (startAngle + sliceAngle))
                    return model()->index(row, 1, rootIndex());

                startAngle += sliceAngle;
            }
        }
    } else {
        double itemHeight = QFontMetrics(viewOptions().font).height();
        int listItem = int((wy - margin) / itemHeight);
        int validRow = 0;

        for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {

            QModelIndex index = model()->index(row, 1, rootIndex());
            if (model()->data(index).toDouble() > 0.0) {

                if (listItem == validRow)
                    return model()->index(row, 0, rootIndex());

                // Update the list index that corresponds to the next valid row.
                validRow++;
            }
        }
    }

    return QModelIndex();
}
Exemple #27
0
void PieView::paintEvent(QPaintEvent *event)
{
    QItemSelectionModel *selections = selectionModel();
    QStyleOptionViewItem option = viewOptions();
    QStyle::State state = option.state;

    QBrush background = option.palette.base();
    QPen foreground(option.palette.color(QPalette::WindowText));
    QPen textPen(option.palette.color(QPalette::Text));
    QPen highlightedPen(option.palette.color(QPalette::HighlightedText));

    QPainter painter(viewport());
    painter.setRenderHint(QPainter::Antialiasing);

    painter.fillRect(event->rect(), background);
    painter.setPen(foreground);

    // Viewport rectangles
    QRect pieRect = QRect(margin, margin, pieSize, pieSize);
    QPoint keyPoint = QPoint(totalSize - horizontalScrollBar()->value(),
                             margin - verticalScrollBar()->value());

    if (validItems > 0) {

        painter.save();
        painter.translate(pieRect.x() - horizontalScrollBar()->value(),
                          pieRect.y() - verticalScrollBar()->value());
        painter.drawEllipse(0, 0, pieSize, pieSize);
        double startAngle = 0.0;
        int row;

        for (row = 0; row < model()->rowCount(rootIndex()); ++row) {

            QModelIndex index = model()->index(row, 1, rootIndex());
            double value = model()->data(index).toDouble();

            if (value > 0.0) {
                double angle = 360*value/totalValue;

                QModelIndex colorIndex = model()->index(row, 0, rootIndex());
                QColor color = QColor(model()->data(colorIndex,
                                Qt::DecorationRole).toString());

                if (currentIndex() == index)
                    painter.setBrush(QBrush(color, Qt::Dense4Pattern));
                else if (selections->isSelected(index))
                    painter.setBrush(QBrush(color, Qt::Dense3Pattern));
                else
                    painter.setBrush(QBrush(color));

                painter.drawPie(0, 0, pieSize, pieSize, int(startAngle*16),
                                int(angle*16));

                startAngle += angle;
            }
        }
        painter.restore();

        int keyNumber = 0;

        for (row = 0; row < model()->rowCount(rootIndex()); ++row) {

            QModelIndex index = model()->index(row, 1, rootIndex());
            double value = model()->data(index).toDouble();

            if (value > 0.0) {
                QModelIndex labelIndex = model()->index(row, 0, rootIndex());

                QStyleOptionViewItem option = viewOptions();
                option.rect = visualRect(labelIndex);
                if (selections->isSelected(labelIndex))
                    option.state |= QStyle::State_Selected;
                if (currentIndex() == labelIndex)
                    option.state |= QStyle::State_HasFocus;
                itemDelegate()->paint(&painter, option, labelIndex);

                keyNumber++;
            }
        }
    }
}
Exemple #28
0
/** ***************************************************************************/
bool ProposalList::eventFilter(QObject*, QEvent *event) {
    if (model() == nullptr)
        return false;

    if (event->type() == QEvent::KeyPress) {
        QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
        int key = keyEvent->key();

        // Mods changed -> refresh
        if (key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Alt || key == Qt::Key_Meta) {
            update(currentIndex());
            return true;
        }

        // Navigation
        if (key == Qt::Key_Down
                || (key == Qt::Key_Up && currentIndex().isValid()) /* No current -> command history */
                || key == Qt::Key_PageDown
                || key == Qt::Key_PageUp) {
            keyPressEvent(keyEvent);
            return true;
        }

        // Selection
        if (key == Qt::Key_Return || key == Qt::Key_Enter) {

            // Ignore empty results
            if (!model()->hasChildren(rootIndex()))
                return true;

            // Select first if none is selected
            if (!currentIndex().isValid())
                setCurrentIndex(model()->index(0, 0, rootIndex()));

            keyPressEvent(keyEvent); // emits activated
            // Do not accept since the inpuline needs
            //to store the request in history
            return false;
        }

        // Show actions
        if (key == Qt::Key_Tab) {

            // Skip if view is empty
            if (!model()->hasChildren(rootIndex()))
                return true;

            // If none is selected use the first
            QModelIndex midx;
            if (currentIndex().isValid())
                midx = currentIndex();
            else
                midx = model()->index(0, 0, rootIndex());

            // If view is in a subtree...
            if (rootIndex().isValid()){
                // Change to Toplevel
                setRootIndex(QModelIndex());
                setCurrentIndex(midx.parent());
            } else {
                // Change to children if there are any
                if (model()->hasChildren(midx)){
                    setRootIndex(midx);
                    setCurrentIndex(QModelIndex());
                }
            }

            updateGeometry();
            return true;
        }
    }

    if (event->type() == QEvent::KeyRelease) {
        QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
        int key = keyEvent->key();

        // Display different subtexts according to the KeyboardModifiers
        if (key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Alt || key == Qt::Key_Meta) {
            update(currentIndex());
            return true;
        }
    }
    return false;
}
QStyleOptionHeader HierarchicalHeaderView::styleOptionForCell(int logicalInd) const
{
	QStyleOptionHeader opt;
	initStyleOption(&opt);
	if (window()->isActiveWindow())
		opt.state |= QStyle::State_Active;
	opt.textAlignment = Qt::AlignCenter;
	opt.iconAlignment = Qt::AlignVCenter;
	opt.section = logicalInd;

	int visual = visualIndex(logicalInd);

	if (count() == 1)
		opt.position = QStyleOptionHeader::OnlyOneSection;
	else
	{
		if (visual == 0)
			opt.position = QStyleOptionHeader::Beginning;
		else
			opt.position=(visual==count()-1 ? QStyleOptionHeader::End : QStyleOptionHeader::Middle);
	}

    if(isClickable())
	{
/*
        if (logicalIndex == d->hover)
            state |= QStyle::State_MouseOver;
        if (logicalIndex == d->pressed)
		{
            state |= QStyle::State_Sunken;
		}
        else*/
		{
			if(highlightSections() && selectionModel()) 
			{
                if(orientation()==Qt::Horizontal)
                {
				    if(selectionModel()->columnIntersectsSelection(logicalInd, rootIndex()))
					    opt.state |= QStyle::State_On;
                    if(selectionModel()->isColumnSelected(logicalInd, rootIndex()))
                        opt.state |= QStyle::State_Sunken;
                }
                else
                {
				    if(selectionModel()->rowIntersectsSelection(logicalInd, rootIndex()))
					    opt.state |= QStyle::State_On;
                    if(selectionModel()->isRowSelected(logicalInd, rootIndex()))
                        opt.state |= QStyle::State_Sunken;
                }
			}
        }
    }
	if(selectionModel())
	{
	    bool previousSelected=false;
        if(orientation()==Qt::Horizontal)
            previousSelected = selectionModel()->isColumnSelected(logicalIndex(visual - 1), rootIndex());
        else
            previousSelected = selectionModel()->isRowSelected(logicalIndex(visual - 1), rootIndex());
		bool nextSelected=false;
        if(orientation()==Qt::Horizontal)
            nextSelected = selectionModel()->isColumnSelected(logicalIndex(visual + 1), rootIndex());
        else
            nextSelected = selectionModel()->isRowSelected(logicalIndex(visual + 1), rootIndex());
		if (previousSelected && nextSelected)
			opt.selectedPosition = QStyleOptionHeader::NextAndPreviousAreSelected;
		else 
		{
			if (previousSelected)
				opt.selectedPosition = QStyleOptionHeader::PreviousIsSelected;
			else
			{
				if (nextSelected)
					opt.selectedPosition = QStyleOptionHeader::NextIsSelected;
				else
					opt.selectedPosition = QStyleOptionHeader::NotAdjacent;
			}
		}
	}
	return opt;
}
Exemple #30
0
void EditTableView::removeAll()
{
    if (model())
        model()->removeRows(0, model()->rowCount(rootIndex()), rootIndex());
}