44 #ifndef QT_NO_COLUMNVIEW 58 #define ANIMATION_DURATION_MSEC 150 113 #ifndef QT_NO_ANIMATION 116 currentAnimation.setTargetObject(hbar);
117 currentAnimation.setPropertyName(
"value");
119 #endif //QT_NO_ANIMATION 145 if (
d->showResizeGrips == visible)
148 for (
int i = 0; i <
d->columns.count(); ++i) {
165 return d->showResizeGrips;
174 if (model ==
d->model)
193 if (view->selectionModel())
194 view->selectionModel()->deleteLater();
199 d->updateScrollbars();
217 for (
int i = 0; i <
d->columns.size(); ++i) {
218 QPoint topLeft =
d->columns.at(i)->frameGeometry().topLeft();
219 QPoint adjustedPoint(point.
x() - topLeft.
x(), point.
y() - topLeft.
y());
236 for (
int i = 0; i <
d->columns.size(); ++i) {
237 QRect rect =
d->columns.at(i)->visualRect(index);
239 rect.
translate(
d->columns.at(i)->frameGeometry().topLeft());
252 if (
d->columns.isEmpty() || dx == 0)
256 for (
int i = 0; i <
d->columns.count(); ++i)
257 d->columns.at(i)->move(
d->columns.at(i)->x() + dx, 0);
269 if (!index.
isValid() ||
d->columns.isEmpty())
272 #ifndef QT_NO_ANIMATION 276 d->currentAnimation.stop();
277 #endif //QT_NO_ANIMATION 280 d->closeColumns(index,
true);
284 int currentColumn = 0;
286 while (currentColumn < d->columns.size()) {
287 if (indexParent ==
d->columns.at(currentColumn)->rootIndex())
289 leftEdge +=
d->columns.at(currentColumn)->width();
294 if (currentColumn ==
d->columns.size())
297 int indexColumn = currentColumn;
299 int visibleWidth =
d->columns.at(currentColumn)->width();
301 if (currentColumn + 1 <
d->columns.size()) {
303 visibleWidth +=
d->columns.at(currentColumn)->width();
306 int rightEdge = leftEdge + visibleWidth;
309 rightEdge = leftEdge - visibleWidth;
310 qSwap(rightEdge, leftEdge);
316 d->columns.at(indexColumn)->scrollTo(index);
317 d->_q_changeCurrentColumn();
321 int newScrollbarValue = 0;
336 newScrollbarValue = leftEdge;
340 #ifndef QT_NO_ANIMATION 341 d->currentAnimation.setEndValue(newScrollbarValue);
342 d->currentAnimation.start();
345 #endif //QT_NO_ANIMATION 368 switch (cursorAction) {
371 return (current.
parent());
397 d->updateScrollbars();
399 int diff =
event->oldSize().width() -
event->size().width();
414 #ifndef QT_NO_ANIMATION 417 #endif //QT_NO_ANIMATION 420 int horizontalLength = 0;
421 if (!columns.isEmpty()) {
422 horizontalLength = (columns.last()->x() + columns.last()->width()) - columns.first()->x();
423 if (horizontalLength <= 0)
424 horizontalLength = (columns.first()->x() + columns.first()->width()) - columns.last()->x();
428 if (horizontalLength < viewportSize.
width() && hbar->value() == 0) {
429 hbar->setRange(0, 0);
431 int visibleLength =
qMin(horizontalLength + q->horizontalOffset(), viewportSize.
width());
432 int hiddenLength = horizontalLength - visibleLength;
433 if (hiddenLength != hbar->maximum())
434 hbar->setRange(0, hiddenLength);
436 if (!columns.isEmpty()) {
437 int pageStepSize = columns.at(0)->width();
438 if (pageStepSize != hbar->pageStep())
439 hbar->setPageStep(pageStepSize);
441 bool visible = (hbar->maximum() > 0);
442 if (visible != hbar->isVisible())
443 hbar->setVisible(visible);
468 int ranges = selection.
count();
475 int firstRow = selection.
at(0).
top();
476 int lastRow = selection.
at(0).
top();
477 for (
int i = 0; i < ranges; ++i) {
478 firstRow =
qMin(firstRow, selection.
at(i).
top());
485 if (firstIdx == lastIdx)
490 return firstRegion.
unite(lastRegion);
508 for (
int i = 0; i <
d->columns.size(); ++i) {
510 d->columns.at(i)->setSelectionModel(newSelectionModel);
524 for (
int i = 0; i <
d->columns.size(); ++i) {
525 sizeHint +=
d->columns.at(i)->sizeHint();
541 if (q->isRightToLeft())
542 offset = -1 * offset;
545 for (
int i = 0; i < columns.size(); ++i) {
546 if (!found && columns.at(i)->cornerWidget() == grip) {
548 columnSizes[i] = columns.at(i)->width();
549 if (q->isRightToLeft())
550 columns.at(i)->move(columns.at(i)->x() + offset, 0);
556 int currentX = columns.at(i)->x();
557 columns.at(i)->move(currentX + offset, 0);
575 if (columns.isEmpty())
578 bool clearAll = !parent.
isValid();
579 bool passThroughRoot =
false;
584 int currentColumn = -1;
586 while (currentColumn == -1 && parentIndex.
isValid()) {
587 if (columns.isEmpty())
589 parentIndex = parentIndex.
parent();
590 if (root == parentIndex)
591 passThroughRoot =
true;
594 for (
int i = columns.size() - 1; i >= 0; --i) {
595 if (columns.at(i)->rootIndex() == parentIndex) {
600 if (currentColumn == -1)
601 dirsToAppend.
append(parentIndex);
606 if (!clearAll && !passThroughRoot && currentColumn == -1)
609 if (currentColumn == -1 && parent.
isValid())
613 bool alreadyExists =
false;
614 if (build && columns.size() > currentColumn + 1) {
615 bool viewingParent = (columns.at(currentColumn + 1)->rootIndex() ==
parent);
617 && !columns.at(currentColumn + 1)->rootIndex().isValid());
618 if (viewingParent || viewingChild) {
620 alreadyExists =
true;
625 for (
int i = columns.size() - 1; i > currentColumn; --i) {
629 if (notShownAnymore != previewColumn)
633 if (columns.isEmpty()) {
639 while (!dirsToAppend.
isEmpty()) {
645 if (build && !alreadyExists)
654 for (
int column = 0; column < columns.count(); ++column) {
655 if (columns.at(column)->rootIndex() ==
parent) {
656 columnClicked = columns[column];
660 if (q->selectionModel() && columnClicked) {
664 q->selectionModel()->setCurrentIndex(index, flags);
686 view = q->createColumn(index);
692 view = previewColumn;
712 if (showResizeGrips) {
715 q->connect(grip,
SIGNAL(gripMoved(
int)), q,
SLOT(_q_gripMoved(
int)));
718 if (columnSizes.count() > columns.count()) {
722 if (q->isRightToLeft())
726 columnSizes.resize(
qMax(columnSizes.count(), columns.count() + 1));
727 columnSizes[columns.count()] = initialWidth;
729 if (!columns.isEmpty() && columns.last()->isHidden())
730 columns.last()->setVisible(
true);
732 columns.append(view);
765 if (
model()->canFetchMore(index))
790 #ifndef QT_NO_DRAGANDDROP 809 QMapIterator<int, QPointer<QAbstractItemDelegate> > i(
d->rowDelegates);
810 while (i.hasNext()) {
829 return d->previewWidget;
844 d->setPreviewWidget(widget);
854 if (!columns.isEmpty() && columns.last() == previewColumn)
855 columns.removeLast();
856 previewColumn->deleteLater();
860 previewColumn = column;
861 previewColumn->
hide();
865 previewColumn->setMinimumWidth(
qMax(previewColumn->verticalScrollBar()->width(),
866 previewColumn->minimumWidth()));
883 for (; (i < list.
count() && i <
d->columns.count()); ++i) {
884 d->columns.at(i)->resize(list.
at(i),
d->columns.at(i)->height());
885 d->columnSizes[i] = list.
at(i);
887 for (; i < list.
count(); ++i)
888 d->columnSizes.append(list.
at(i));
900 for (
int i = 0; i <
d->columns.count(); ++i)
901 list.
append(
d->columnSizes.at(i));
911 d_func()->checkColumnCreation(parent);
927 if (currentParent == previous.
parent()
929 for (
int i = 0; i <
d->columns.size(); ++i) {
930 if (currentParent ==
d->columns.at(i)->rootIndex()) {
931 if (
d->columns.size() > i + 1) {
942 if (currentParent == previous) {
943 for (
int i = 0; i <
d->columns.size(); ++i) {
944 if (currentParent ==
d->columns.at(i)->rootIndex()) {
946 if (
d->columns.size() < i + 2) {
947 d->createColumn(current,
false);
954 d->closeColumns(current,
true);
956 if (!
model()->hasChildren(current))
969 if (columns.isEmpty())
977 closeColumns(current,
true);
980 int currentColumn =
qMax(0, columns.size() - 2);
984 q->setFocusProxy(parentColumn);
987 for (
int i = 0; i < columns.size(); ++i) {
988 if (columns.at(i)->selectionModel() == q->selectionModel()) {
993 replacementSelectionModel->
select(
998 if (columns.size() > i + 1)
1003 parentColumn->selectionModel()->deleteLater();
1005 parentColumn->setSelectionModel(q->selectionModel());
1007 if (currentColumn > 0) {
1008 parentColumn = columns.at(currentColumn - 1);
1009 if (parentColumn->currentIndex() != current.
parent())
1010 parentColumn->setCurrentIndex(current.
parent());
1013 if (columns.last()->isHidden()) {
1014 columns.last()->setVisible(
true);
1016 if (columns.last()->selectionModel())
1017 columns.last()->selectionModel()->clear();
1032 if (indexList.
count() >= 1)
1034 if (indexList.
count() == 1) {
1035 parent = indexList.
at(0);
1036 if (!
model()->hasChildren(parent))
1037 parent = parent.
parent();
1044 model()->columnCount(parent) - 1,
1055 ,showResizeGrips(true)
1120 if (q->isRightToLeft()) {
1125 if (x != view->
x() || viewportHeight != view->
height())
1131 int currentColumnWidth = view->
width();
1132 if (x != view->
x() || viewportHeight != view->
height())
1133 view->
setGeometry(x, 0, currentColumnWidth, viewportHeight);
1134 x += currentColumnWidth;
1153 drawBackground(painter, option, index );
1156 int width = ((option.
rect.
height() * 2) / 3);
1187 #include "moc_qcolumnview.cpp" 1189 #endif // QT_NO_COLUMNVIEW #define ANIMATION_DURATION_MSEC
The QPainter class performs low-level painting on widgets and other paint devices.
void setItemDelegateForRow(int row, QAbstractItemDelegate *delegate)
Sets the given item delegate used by this view and model for the given row.
void setPreviewWidget(QWidget *widget)
Sets the preview widget.
The QAbstractItemDelegate class is used to display and edit data items from a model.
void setSelectionMode(QAbstractItemView::SelectionMode mode)
The QItemSelectionModel class keeps track of a view's selected items.
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
void setDragDropOverwriteMode(bool overwrite)
QPointer< QWidget > widget
void setRootIndex(const QModelIndex &index)
Reimplemented Function
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
Sets the current selection model to the given selectionModel.
QAbstractItemView * createColumn(const QModelIndex &index, bool show)
Create a new column for index.
ScrollMode horizontalScrollMode() const
void setAlternatingRowColors(bool enable)
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
QStyle::State state
the style flags that are used when drawing the control
void _q_columnsInserted(const QModelIndex &parent, int start, int end)
void clicked(const QModelIndex &index)
This signal is emitted when a mouse button is clicked.
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
QModelIndexList selectedIndexes() const
Returns a list of all selected model item indexes.
static C reverse(const C &l)
void setIconSize(const QSize &size)
int verticalOffset() const
Reimplemented Function
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
DragDropMode dragDropMode() const
void setEditTriggers(EditTriggers triggers)
The QItemSelectionRange class manages information about a range of selected items in a model...
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
int width() const
Returns the width of the rectangle.
int bottom() const
Returns the row index corresponding to the lowermost selected row in the selection range...
int count(const T &t) const
Returns the number of occurrences of value in the list.
QRect visualRect(const QModelIndex &index) const
Reimplemented Function
static QStyle * style()
Returns the application's style object.
int height() const
Returns the height of the rectangle.
void rowsInserted(const QModelIndex &parent, int start, int end)
Reimplemented Function
QAbstractItemDelegate * itemDelegate() const
Returns the item delegate used by this view and model.
void setPreviewWidget(QWidget *widget)
The QObject class is the base class of all Qt objects.
void setColumnWidths(const QList< int > &list)
Sets the column widths to the values given in the list.
bool tabKeyNavigation() const
bool showDropIndicator() const
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
void setPreviewWidget(QWidget *widget)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void setAutoScroll(bool enable)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
virtual void _q_columnsInserted(const QModelIndex &parent, int start, int end)
This slot is called when columns have been inserted.
void setTabKeyNavigation(bool enable)
void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
QSize sizeHint() const
Reimplemented Function
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
int width() const
Returns the width.
void append(const T &t)
Inserts value at the end of the list.
void entered(const QModelIndex &index)
This signal is emitted when the mouse cursor enters the item specified by index.
#define QT_BEGIN_NAMESPACE
This macro expands to.
void setSelectionModel(QItemSelectionModel *selectionModel)
Reimplemented Function
void setModel(QAbstractItemModel *model)
Reimplemented Function
ScrollMode verticalScrollMode() const
void setDropIndicatorShown(bool enable)
QColumnView(QWidget *parent=0)
Constructs a column view with a parent to represent a model's data.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Draws a delegate with a > if an object has children.
int horizontalOffset() const
Reimplemented Function
QAbstractItemView * previewColumn
virtual bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Returns true if parent has any children; otherwise returns false.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
void setRootIndex(const QModelIndex &index)
QItemSelectionModel * selectionModel() const
Returns the current selection model.
bool isSelected(const QModelIndex &index) const
Returns true if the given model item index is selected.
int row() const
Returns the row this model index refers to.
QList< int > columnWidths() const
Returns a list of the width of all the columns in this view.
bool resizeGripsVisible() const
const T & at(int i) const
Returns the item at index position i in the list.
virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
This slot is called when a new item becomes the current item.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
void resizeEvent(QResizeEvent *event)
Reimplemented Function
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
The QResizeEvent class contains event parameters for resize events.
void setCurrentIndex(const QModelIndex &index)
Sets the current item to be the item at index.
void setTextElideMode(Qt::TextElideMode mode)
bool showDecorationSelected
whether the decoration should be highlighted on selected items
QWidget * previewWidget() const
Returns the preview widget, or 0 if there is none.
void setDragDropMode(DragDropMode behavior)
QModelIndex currentIndex() const
Returns the model index of the current item.
bool alternatingRowColors() const
The QRegion class specifies a clip region for a painter.
void activated(const QModelIndex &index)
This signal is emitted when the item specified by index is activated by the user. ...
void setFrameShape(Shape)
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
Reimplemented Function
void checkColumnCreation(const QModelIndex &parent)
Makes sure we create a corresponding column as a result of changing the model.
QAbstractItemView::SelectionBehavior selectionBehavior() const
This is a delegate that will paint the triangle.
~QColumnView()
Destroys the column view.
void doLayout()
Place all of the columns where they belong inside of the viewport, resize as necessary.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
void qSwap(T &value1, T &value2)
QAbstractItemView::SelectionMode selectionMode() const
The QAbstractItemModel class provides the abstract interface for item model classes.
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)
Reimplemented Function
virtual void fetchMore(const QModelIndex &parent)
Fetches any available data for the items with the parent specified by the parent index.
QRegion unite(const QRegion &r) const
Use united(r) instead.
bool hasAutoScroll() const
Qt::TextElideMode textElideMode() const
The QAbstractItemView class provides the basic functionality for item view classes.
The QItemSelection class manages information about selected items in a model.
The QListView class provides a list or icon view onto a model.
void pressed(const QModelIndex &index)
This signal is emitted when a mouse button is pressed.
int y() const
Returns the y-coordinate of the rectangle's top edge.
void setHorizontalScrollMode(ScrollMode mode)
void resizeEvent(QResizeEvent *event)
This function is called with the given event when a resize event is sent to the widget.
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
Reimplemented Function Move left should go to the parent index Move right should go to the child inde...
bool isIndexHidden(const QModelIndex &index) const
Reimplemented Function
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().
void initializeColumn(QAbstractItemView *column) const
Copies the behavior and options of the column view and applies them to the column such as the iconSiz...
void scrollContentsBy(int dx, int dy)
Reimplemented Function
int x() const
Returns the x-coordinate of the rectangle's left edge.
QObject * parent() const
Returns a pointer to the parent object.
bool dragDropOverwriteMode() const
void setVerticalScrollMode(ScrollMode mode)
The QPoint class defines a point in the plane using integer precision.
T & last()
Returns a reference to the last item in the list.
The QModelIndex class is used to locate data in a data model.
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
Reimplemented Function
int size() const
Returns the number of items in the list.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
QModelIndex indexAt(const QPoint &point) const
Reimplemented Function
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
The QRect class defines a rectangle in the plane using integer precision.
The QColumnView class provides a model/view implementation of a column view.
QRegion visualRegionForSelection(const QItemSelection &selection) const
Reimplemented Function
void _q_changeCurrentColumn()
int y() const
Returns the y coordinate of this point.
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
This slot is called when rows are inserted.
int top() const
Returns the row index corresponding to the uppermost selected row in the selection range...
T takeLast()
Removes the last item in the list and returns it.
The QSize class defines the size of a two-dimensional object using integer point precision.
void setItemDelegate(QAbstractItemDelegate *delegate)
Sets the item delegate for this view and its model to delegate.
CursorAction
This enum describes the different ways to navigate between items,.
void updatePreviewWidget(const QModelIndex &index)
This signal is emitted when the preview widget should be updated to provide rich information about in...
int x() const
Returns the x coordinate of this point.
void doubleClicked(const QModelIndex &index)
This signal is emitted when a mouse button is double-clicked.
The QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
QModelIndex rootIndex() const
Returns the model index of the model's root item.
QAbstractItemModel * model() const
Returns the model that this view is presenting.
EditTriggers editTriggers() const
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
static const KeyPair *const end
bool event(QEvent *event)
Reimplemented Function
void closeColumns(const QModelIndex &parent=QModelIndex(), bool build=false)
Find where the current columns intersect parent's columns.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
QAbstractItemModel * model
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Renders the delegate using the given painter and style option for the item specified by index...
void deleteLater()
Schedules this object for deletion.
QRect rect
the area that should be used for various calculations and painting
void _q_gripMoved(int offset)
void _q_clicked(const QModelIndex &index)
void selectAll()
Reimplemented Function
void setResizeGripsVisible(bool visible)
int column() const
Returns the column this model index refers to.
QList< QAbstractItemView * > columns
virtual QAbstractItemView * createColumn(const QModelIndex &rootIndex)
To use a custom widget for the final column when you select an item overload this function and return...