QtBase  v6.3.1
recycledlistitem.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #include <QGraphicsGridLayout>
30 #include <QDebug>
31 
32 #include "recycledlistitem.h"
33 #include "listmodel.h"
34 
35 static const int MinItemHeight = 70;
36 static const int MinItemWidth = 276;
37 
40  m_item(new ListItem(this)),
41  m_item2(0),
42  m_model(0),
43  m_layout(new QGraphicsGridLayout())
44 {
45  m_item->setMinimumWidth(MinItemWidth);
46  setContentsMargins(0,0,0,0);
48  m_layout->addItem(m_item, 0, 0);
49  setLayout(m_layout);
50  m_layout->setContentsMargins(0,0,0,0);
51  m_layout->setSpacing(0);
52  m_layout->setHorizontalSpacing(0.0);
53  m_layout->setVerticalSpacing(0.0);
54 }
55 
57 {
58 }
59 
61 {
62  m_model = model;
63 }
64 
65 /*virtual*/
67 {
69  return item;
70 }
71 
73 {
74  QSizeF s = m_item->effectiveSizeHint(which,constraint);
75  if (m_item2)
76  s.setWidth(s.width()*2);
77  if (s.height()<MinItemHeight)
78  s.setHeight(MinItemHeight);
79  return s;
80 }
81 
83 {
84  if (m_item && role == Qt::DisplayRole)
85  return m_item->data();
86 
87  return QVariant();
88 }
89 
91 {
92  if (m_item && role == Qt::DisplayRole) {
93  m_item->setData(value);
94  if (m_item2) {
95  m_item2->setData(value);
96  }
97  }
98 }
99 
100 /*virtual*/
102 {
104 }
105 
107 {
109  if (m_model && m_index.isValid())
111 }
112 
114 {
115  if (m_item2 && enabled)
116  return;
117 
118  if (enabled) {
119  m_item2 = new ListItem();
120  m_item2->setMinimumWidth(MinItemWidth);
121  m_layout->addItem(m_item2, 0, 1);
123  }
124  else {
125  if (m_layout->count() > 1) {
126  m_layout->removeAt(1);
127  }
128  delete m_item2;
129  m_item2 = 0;
130  }
131 
132  if (!m_layout->isActivated())
133  m_layout->activate();
134 }
QPersistentModelIndex m_index
virtual void updateItemContents()
void setData(const QVariant &value, int role=Qt::DisplayRole)
Definition: listitem.cpp:182
QVariant data(int role=Qt::DisplayRole) const
Definition: listitem.cpp:134
The QAbstractItemModel class provides the abstract interface for item model classes.
virtual Q_INVOKABLE QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View.
void setHorizontalSpacing(qreal spacing)
void removeAt(int index) override
void setVerticalSpacing(qreal spacing)
void addItem(QGraphicsLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment=Qt::Alignment())
void setSpacing(qreal spacing)
int count() const override
bool isActivated() const
void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom)
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
void setSizePolicy(const QSizePolicy &policy)
void setMinimumWidth(qreal width)
The QGraphicsSceneResizeEvent class provides events for widget resizing in the graphics view framewor...
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
void setLayout(QGraphicsLayout *layout)
void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom)
virtual void resizeEvent(QGraphicsSceneResizeEvent *event)
The QSizeF class defines the size of a two-dimensional object using floating point precision.
Definition: qsize.h:235
constexpr void setWidth(qreal w) noexcept
Definition: qsize.h:355
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
virtual void setData(const QVariant &value, int role=Qt::DisplayRole)
virtual void resizeEvent(QGraphicsSceneResizeEvent *event)
ListItem * item()
virtual QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
virtual QVariant data(int role) const
virtual AbstractViewItem * newItemInstance()
virtual ~RecycledListItem()
void setTwoColumns(const bool enabled)
virtual void setModel(QAbstractItemModel *model)
virtual void updateItemContents()
RecycledListItem(QGraphicsWidget *parent=0)
#define this
Definition: dialogs.cpp:56
@ DisplayRole
Definition: qnamespace.h:1502
SizeHint
Definition: qnamespace.h:1589
EGLOutputLayerEXT EGLint EGLAttrib value
GLenum GLenum GLsizei const GLuint GLboolean enabled
struct _cl_event * event
Definition: qopenglext.h:2998
GLdouble s
[6]
Definition: qopenglext.h:235
QSqlQueryModel * model
[16]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent