Skip to content

Commit cd965f4

Browse files
author
timlinux
committedJul 15, 2008
Refactored detaileditemdelegate to avoid code duplication and try to resolve some issues needed for grass refactoring. Also fixed clipping of checkbox and checkbox logic is not entirely encapsulated based on the values of qgsdetaileditemdata.
git-svn-id: http://svn.osgeo.org/qgis/trunk@8787 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent db036f6 commit cd965f4

File tree

5 files changed

+271
-178
lines changed

5 files changed

+271
-178
lines changed
 

‎src/app/qgspluginmanager.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,13 @@ sharedLibExtension = "*.so*";
305305
myData.setTitle(pName());
306306
myData.setDetail(pDesc());
307307
myData.setRenderAsWidget(false);
308-
QVariant myVariant = qVariantFromValue(myData);
308+
myData.setCheckable(true);
309+
myData.setChecked(false); //start unchecked - we will check it later if needed
310+
309311
//round trip test - delete this...no need to uncomment
310312
//QgsDetailedItemData myData2 = qVariantValue<QgsDetailedItemData>(myVariant);
311313
//Q_ASSERT(myData.title() == myData2.title());
312314
//round trip test ends
313-
mypDetailItem->setData(myVariant,PLUGIN_DATA_ROLE);
314-
// Let the first col have a checkbox
315-
mypDetailItem->setCheckable(true);
316-
mypDetailItem->setEditable(false);
317315

318316
QgsDebugMsg("Getting an instance of the QgsPluginRegistry");
319317

@@ -332,9 +330,11 @@ sharedLibExtension = "*.so*";
332330
if (libName == myLib->fileName())
333331
{
334332
// set the checkbox
335-
mypDetailItem->setCheckState(Qt::Checked);
333+
myData.setChecked(true);
336334
}
337335
}
336+
QVariant myVariant = qVariantFromValue(myData);
337+
mypDetailItem->setData(myVariant,PLUGIN_DATA_ROLE);
338338
// Add items to model
339339
mModelPlugins->appendRow(mypDetailItem);
340340

@@ -437,8 +437,13 @@ void QgsPluginManager::selectAll()
437437
// select all plugins
438438
for (int row=0;row < mModelPlugins->rowCount();row++)
439439
{
440-
QStandardItem *myItem=mModelPlugins->item(row,0);
441-
myItem->setCheckState(Qt::Checked);
440+
QStandardItem *mypItem=mModelPlugins->item(row,0);
441+
QgsDetailedItemData myData =
442+
qVariantValue<QgsDetailedItemData>(mypItem->data(PLUGIN_DATA_ROLE));
443+
myData.setChecked(true);
444+
QVariant myVariant = qVariantFromValue(myData);
445+
mypItem->setData(myVariant,PLUGIN_DATA_ROLE);
446+
442447
}
443448
}
444449

@@ -447,8 +452,12 @@ void QgsPluginManager::clearAll()
447452
// clear all selection checkboxes
448453
for (int row=0;row < mModelPlugins->rowCount();row++)
449454
{
450-
QStandardItem *myItem=mModelPlugins->item(row,0);
451-
myItem->setCheckState(Qt::Unchecked);
455+
QStandardItem *mypItem=mModelPlugins->item(row,0);
456+
QgsDetailedItemData myData =
457+
qVariantValue<QgsDetailedItemData>(mypItem->data(PLUGIN_DATA_ROLE));
458+
myData.setChecked(false);
459+
QVariant myVariant = qVariantFromValue(myData);
460+
mypItem->setData(myVariant,PLUGIN_DATA_ROLE);
452461
}
453462
}
454463

@@ -463,14 +472,18 @@ void QgsPluginManager::on_vwPlugins_clicked(const QModelIndex &theIndex )
463472
//
464473
QStandardItem * mypItem =
465474
mModelPlugins->findItems(theIndex.data(Qt ::DisplayRole).toString()).first();
466-
if ( mypItem->checkState() == Qt::Checked )
475+
QgsDetailedItemData myData =
476+
qVariantValue<QgsDetailedItemData>(mypItem->data(PLUGIN_DATA_ROLE));
477+
if ( myData.isChecked() )
467478
{
468-
mypItem->setCheckState(Qt::Unchecked);
479+
myData.setChecked(false);
469480
}
470481
else
471482
{
472-
mypItem->setCheckState(Qt::Checked);
483+
myData.setChecked(true);
473484
}
485+
QVariant myVariant = qVariantFromValue(myData);
486+
mypItem->setData(myVariant,PLUGIN_DATA_ROLE);
474487
}
475488
}
476489

‎src/gui/qgsdetaileditemdata.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,59 +26,59 @@ QgsDetailedItemData::~QgsDetailedItemData()
2626
{
2727
}
2828

29-
void QgsDetailedItemData::setTitle(QString theTitle)
29+
void QgsDetailedItemData::setTitle(const QString theTitle)
3030
{
3131
mTitle=theTitle;
3232
}
3333

34-
void QgsDetailedItemData::setDetail(QString theDetail)
34+
void QgsDetailedItemData::setDetail(const QString theDetail)
3535
{
3636
mDetail=theDetail;
3737
}
3838

39-
void QgsDetailedItemData::setIcon(QPixmap theIcon)
39+
void QgsDetailedItemData::setIcon(const QPixmap theIcon)
4040
{
4141
mPixmap = theIcon;
4242
}
43-
void QgsDetailedItemData::setCheckable(bool theFlag)
43+
void QgsDetailedItemData::setCheckable(const bool theFlag)
4444
{
4545
mCheckableFlag = theFlag;
4646
}
47-
void QgsDetailedItemData::setChecked(bool theFlag)
47+
void QgsDetailedItemData::setChecked(const bool theFlag)
4848
{
4949
mCheckedFlag = theFlag;
5050
}
51-
void QgsDetailedItemData::setRenderAsWidget(bool theFlag)
51+
void QgsDetailedItemData::setRenderAsWidget(const bool theFlag)
5252
{
5353
mRenderAsWidgetFlag = theFlag;
5454
}
5555

56-
QString QgsDetailedItemData::title()
56+
QString QgsDetailedItemData::title() const
5757
{
5858
return mTitle;
5959
}
6060

61-
QString QgsDetailedItemData::detail()
61+
QString QgsDetailedItemData::detail() const
6262
{
6363
return mDetail;
6464
}
6565

66-
QPixmap QgsDetailedItemData::icon()
66+
QPixmap QgsDetailedItemData::icon() const
6767
{
6868
return mPixmap;
6969
}
7070

71-
bool QgsDetailedItemData::isCheckable()
71+
bool QgsDetailedItemData::isCheckable() const
7272
{
7373
return mCheckableFlag;
7474
}
7575

76-
bool QgsDetailedItemData::isChecked()
76+
bool QgsDetailedItemData::isChecked() const
7777
{
7878
return mCheckedFlag;
7979
}
8080

81-
bool QgsDetailedItemData::isRenderedAsWidget()
81+
bool QgsDetailedItemData::isRenderedAsWidget() const
8282
{
8383
return mRenderAsWidgetFlag;
8484
}

‎src/gui/qgsdetaileditemdata.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class GUI_EXPORT QgsDetailedItemData
3131
public:
3232
QgsDetailedItemData();
3333
~QgsDetailedItemData();
34-
void setTitle(QString theTitle);
35-
void setDetail(QString theDetail);
36-
void setIcon(QPixmap theIcon);
37-
void setCheckable(bool theFlag);
38-
void setChecked(bool theFlag);
34+
void setTitle(const QString theTitle);
35+
void setDetail(const QString theDetail);
36+
void setIcon(const QPixmap theIcon);
37+
void setCheckable(const bool theFlag);
38+
void setChecked(const bool theFlag);
3939
/** This is a hint to the delegate to render using
4040
* a widget rather than manually painting every
4141
* part of the list item.
@@ -44,12 +44,12 @@ class GUI_EXPORT QgsDetailedItemData
4444
*/
4545
void setRenderAsWidget(bool theFlag);
4646

47-
QString title();
48-
QString detail();
49-
QPixmap icon();
50-
bool isCheckable();
51-
bool isChecked();
52-
bool isRenderedAsWidget();
47+
QString title() const;
48+
QString detail() const;
49+
QPixmap icon() const;
50+
bool isCheckable() const;
51+
bool isChecked() const;
52+
bool isRenderedAsWidget() const;
5353

5454
private:
5555
QString mTitle;

‎src/gui/qgsdetaileditemdelegate.cpp

Lines changed: 190 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ QgsDetailedItemDelegate::QgsDetailedItemDelegate(QObject * parent) :
3333

3434
{
3535
//mpWidget->setFixedHeight(80);
36-
mpCheckBox->resize(16,16);
36+
mpCheckBox->resize(mpCheckBox->sizeHint().height(),mpCheckBox->sizeHint().height());
37+
setVerticalSpacing (3);
38+
setHorizontalSpacing (5);
3739
}
3840

3941
QgsDetailedItemDelegate::~QgsDetailedItemDelegate()
@@ -55,138 +57,18 @@ void QgsDetailedItemDelegate::paint(QPainter * thepPainter,
5557
bool myCheckState = theIndex.model()->data(theIndex, Qt::CheckStateRole).toBool();
5658
if (myData.isRenderedAsWidget())
5759
{
58-
mpWidget->setChecked(myCheckState);
59-
mpWidget->setData(myData);
60-
mpWidget->resize(theOption.rect.width(),mpWidget->height());
61-
mpWidget->setAutoFillBackground(false);
62-
mpWidget->repaint();
63-
64-
if (theOption.state & QStyle::State_Selected)
65-
{
66-
QColor myColor1 = theOption.palette.highlight().color();
67-
QColor myColor2 = myColor1;
68-
myColor2 = myColor2.lighter(110); //10% lighter
69-
QLinearGradient myGradient(QPointF(0,theOption.rect.y()),
70-
QPointF(0,theOption.rect.y() + mpWidget->height()));
71-
myGradient.setColorAt(0, myColor1);
72-
myGradient.setColorAt(0.1, myColor2);
73-
myGradient.setColorAt(0.5, myColor1);
74-
myGradient.setColorAt(0.9, myColor2);
75-
myGradient.setColorAt(1, myColor1);
76-
thepPainter->fillRect(theOption.rect, QBrush(myGradient));
77-
}
78-
QPixmap myPixmap = QPixmap::grabWidget(mpWidget);
79-
thepPainter->drawPixmap(theOption.rect.x(),
80-
theOption.rect.y(),
81-
myPixmap);
82-
} //render as widget
60+
paintAsWidget(thepPainter,theOption,myData);
61+
}
8362
else //render by manually painting
8463
{
85-
//
86-
// Get the strings and check box properties
87-
//
88-
bool myCheckState = theIndex.model()->data(theIndex, Qt::CheckStateRole).toBool();
89-
mpCheckBox->setChecked(myCheckState);
90-
QPixmap myCbxPixmap(mpCheckBox->size());
91-
mpCheckBox->render(&myCbxPixmap); //we will draw this onto the widget further down
92-
93-
//
94-
// Calculate the widget height and other metrics
95-
//
96-
QFont myFont = theOption.font;
97-
QFont myTitleFont = myFont;
98-
myTitleFont.setBold(true);
99-
myTitleFont.setPointSize(myFont.pointSize() + 3);
100-
QFontMetrics myTitleMetrics(myTitleFont);
101-
QFontMetrics myDetailMetrics(myFont);
102-
int myVerticalSpacer = 3; //spacing between title and description
103-
int myHorizontalSpacer = 5; //spacing between checkbox / icon and description
104-
int myTextStartX = theOption.rect.x() + myHorizontalSpacer;
105-
int myTextStartY= theOption.rect.y() + myVerticalSpacer;
106-
int myHeight = myTitleMetrics.height() + myVerticalSpacer;
107-
108-
//
109-
// Draw the item background with a gradient if its highlighted
110-
//
111-
if (theOption.state & QStyle::State_Selected)
112-
{
113-
QColor myColor1 = theOption.palette.highlight().color();
114-
QColor myColor2 = myColor1;
115-
myColor2 = myColor2.lighter(110); //10% lighter
116-
int myHeight = myTitleMetrics.height() + myVerticalSpacer;
117-
QLinearGradient myGradient(QPointF(0,theOption.rect.y()),
118-
QPointF(0,theOption.rect.y() + myHeight*2));
119-
myGradient.setColorAt(0, myColor1);
120-
myGradient.setColorAt(0.1, myColor2);
121-
myGradient.setColorAt(0.5, myColor1);
122-
myGradient.setColorAt(0.9, myColor2);
123-
myGradient.setColorAt(1, myColor2);
124-
thepPainter->fillRect(theOption.rect, QBrush(myGradient));
125-
}
126-
127-
//
128-
// Draw the checkbox
129-
//
130-
bool myCheckableFlag = true;
131-
if (theIndex.flags() == Qt::ItemIsUserCheckable)
132-
{
133-
myCheckableFlag = false;
134-
}
135-
if (myCheckableFlag)
136-
{
137-
thepPainter->drawPixmap(theOption.rect.x(),
138-
theOption.rect.y() + mpCheckBox->height(),
139-
myCbxPixmap);
140-
myTextStartX = theOption.rect.x() + myCbxPixmap.width() + myHorizontalSpacer;
141-
}
142-
//
143-
// Draw the decoration (pixmap)
144-
//
145-
bool myIconFlag = false;
146-
QPixmap myDecoPixmap = myData.icon();
147-
if (!myDecoPixmap.isNull())
148-
{
149-
thepPainter->drawPixmap(myTextStartX,
150-
myTextStartY + (myDecoPixmap.height() / 2),
151-
myDecoPixmap);
152-
myTextStartX += myDecoPixmap.width() + myHorizontalSpacer;
153-
}
154-
//
155-
// Draw the title
156-
//
157-
myTextStartY += myHeight/2;
158-
thepPainter->setFont(myTitleFont);
159-
thepPainter->drawText( myTextStartX ,
160-
myTextStartY ,
161-
myData.title());
162-
//
163-
// Draw the description with word wrapping if needed
164-
//
165-
thepPainter->setFont(myFont); //return to original font set by client
166-
if (myIconFlag)
167-
{
168-
myTextStartY += myVerticalSpacer;
169-
}
170-
else
171-
{
172-
myTextStartY += myDetailMetrics.height() + myVerticalSpacer;
173-
}
174-
QStringList myList =
175-
wordWrap( myData.detail(), myDetailMetrics, theOption.rect.width() - myTextStartX );
176-
QStringListIterator myLineWrapIterator(myList);
177-
while (myLineWrapIterator.hasNext())
178-
{
179-
QString myLine = myLineWrapIterator.next();
180-
thepPainter->drawText( myTextStartX,
181-
myTextStartY,
182-
myLine);
183-
myTextStartY += myDetailMetrics.height() - myVerticalSpacer;
184-
}
185-
} //render by manual painting
64+
paintManually(thepPainter,theOption,myData);
65+
}
18666
} //can convert item data
18767
thepPainter->restore();
18868
}
18969

70+
71+
19072
QSize QgsDetailedItemDelegate::sizeHint(
19173
const QStyleOptionViewItem & theOption,
19274
const QModelIndex & theIndex ) const
@@ -201,22 +83,8 @@ QSize QgsDetailedItemDelegate::sizeHint(
20183
}
20284
else // fall back to hand calculated & hand drawn item
20385
{
204-
QFont myFont = theOption.font;
205-
QFont myTitleFont = myFont;
206-
myTitleFont.setBold(true);
207-
myTitleFont.setPointSize(myFont.pointSize() + 3);
208-
QFontMetrics myTitleMetrics(myTitleFont);
209-
QFontMetrics myDetailMetrics(myFont);
210-
int myVerticalSpacer = 3; //spacing between title and description
211-
int myHorizontalSpacer = 5; //spacing between checkbox / icon and description
212-
int myHeight = myTitleMetrics.height() + myVerticalSpacer;
213-
QString myDetailString = theIndex.model()->data(theIndex, Qt::UserRole).toString();
214-
QStringList myList = wordWrap( myDetailString,
215-
myDetailMetrics,
216-
theOption.rect.width() - (mpCheckBox->width() + myHorizontalSpacer));
217-
myHeight += (myList.count() + 1) * (myDetailMetrics.height() - myVerticalSpacer);
21886
//for some reason itmes are non selectable if using rect.width() on osx and win
219-
return QSize(50, myHeight + myVerticalSpacer);
87+
return QSize(50, height(theOption,myData));
22088
//return QSize(theOption.rect.width(), myHeight + myVerticalSpacer);
22189
}
22290
}
@@ -226,6 +94,162 @@ QSize QgsDetailedItemDelegate::sizeHint(
22694
}
22795
}
22896

97+
void QgsDetailedItemDelegate::paintManually(QPainter * thepPainter,
98+
const QStyleOptionViewItem & theOption,
99+
const QgsDetailedItemData theData) const
100+
{
101+
//
102+
// Get the strings and check box properties
103+
//
104+
//bool myCheckState = theIndex.model()->data(theIndex, Qt::CheckStateRole).toBool();
105+
mpCheckBox->setChecked(theData.isChecked());
106+
QPixmap myCbxPixmap(mpCheckBox->size());
107+
mpCheckBox->render(&myCbxPixmap); //we will draw this onto the widget further down
108+
109+
//
110+
// Calculate the widget height and other metrics
111+
//
112+
113+
QFontMetrics myTitleMetrics(titleFont(theOption));
114+
QFontMetrics myDetailMetrics(detailFont(theOption));
115+
int myTextStartX = theOption.rect.x() + horizontalSpacing();
116+
int myTextStartY= theOption.rect.y() + verticalSpacing();
117+
int myHeight = myTitleMetrics.height() + verticalSpacing();
118+
119+
//
120+
// Draw the item background with a gradient if its highlighted
121+
//
122+
if (theOption.state & QStyle::State_Selected)
123+
{
124+
drawHighlight(theOption,thepPainter, height(theOption, theData));
125+
}
126+
127+
//
128+
// Draw the checkbox
129+
//
130+
if (theData.isCheckable())
131+
{
132+
thepPainter->drawPixmap(theOption.rect.x(),
133+
theOption.rect.y() + mpCheckBox->height(),
134+
myCbxPixmap);
135+
myTextStartX = theOption.rect.x() + myCbxPixmap.width() + horizontalSpacing();
136+
}
137+
//
138+
// Draw the decoration (pixmap)
139+
//
140+
bool myIconFlag = false;
141+
QPixmap myDecoPixmap = theData.icon();
142+
if (!myDecoPixmap.isNull())
143+
{
144+
thepPainter->drawPixmap(myTextStartX,
145+
myTextStartY + (myDecoPixmap.height() / 2),
146+
myDecoPixmap);
147+
myTextStartX += myDecoPixmap.width() + horizontalSpacing();
148+
}
149+
//
150+
// Draw the title
151+
//
152+
myTextStartY += myHeight/2;
153+
thepPainter->setFont(titleFont(theOption));
154+
thepPainter->drawText( myTextStartX ,
155+
myTextStartY ,
156+
theData.title());
157+
//
158+
// Draw the description with word wrapping if needed
159+
//
160+
thepPainter->setFont(detailFont(theOption)); //return to original font set by client
161+
if (myIconFlag)
162+
{
163+
myTextStartY += verticalSpacing();
164+
}
165+
else
166+
{
167+
myTextStartY += myDetailMetrics.height() + verticalSpacing();
168+
}
169+
QStringList myList =
170+
wordWrap( theData.detail(), myDetailMetrics, theOption.rect.width() - myTextStartX );
171+
QStringListIterator myLineWrapIterator(myList);
172+
while (myLineWrapIterator.hasNext())
173+
{
174+
QString myLine = myLineWrapIterator.next();
175+
thepPainter->drawText( myTextStartX,
176+
myTextStartY,
177+
myLine);
178+
myTextStartY += myDetailMetrics.height() - verticalSpacing();
179+
}
180+
} //render by manual painting
181+
182+
183+
void QgsDetailedItemDelegate::paintAsWidget(QPainter * thepPainter,
184+
const QStyleOptionViewItem & theOption,
185+
const QgsDetailedItemData theData) const
186+
{
187+
QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &theOption, thepPainter, 0);
188+
mpWidget->setChecked(theData.isChecked());
189+
mpWidget->setData(theData);
190+
mpWidget->resize(theOption.rect.width(),mpWidget->height());
191+
mpWidget->setAutoFillBackground(true);
192+
//mpWidget->setAttribute(Qt::WA_OpaquePaintEvent);
193+
mpWidget->repaint();
194+
195+
if (theOption.state & QStyle::State_Selected)
196+
{
197+
drawHighlight(theOption,thepPainter,height(theOption,theData));
198+
}
199+
QPixmap myPixmap = QPixmap::grabWidget(mpWidget);
200+
thepPainter->drawPixmap(theOption.rect.x(),
201+
theOption.rect.y(),
202+
myPixmap);
203+
}//render as widget
204+
205+
void QgsDetailedItemDelegate::drawHighlight(const QStyleOptionViewItem &theOption,
206+
QPainter * thepPainter,
207+
int theHeight) const
208+
{
209+
QColor myColor1 = theOption.palette.highlight().color();
210+
QColor myColor2 = myColor1;
211+
myColor2 = myColor2.lighter(110); //10% lighter
212+
QLinearGradient myGradient(QPointF(0,theOption.rect.y()),
213+
QPointF(0,theOption.rect.y() + theHeight));
214+
myGradient.setColorAt(0, myColor1);
215+
myGradient.setColorAt(0.1, myColor2);
216+
myGradient.setColorAt(0.5, myColor1);
217+
myGradient.setColorAt(0.9, myColor2);
218+
myGradient.setColorAt(1, myColor2);
219+
thepPainter->fillRect(theOption.rect, QBrush(myGradient));
220+
}
221+
222+
int QgsDetailedItemDelegate::height(const QStyleOptionViewItem & theOption,
223+
const QgsDetailedItemData theData) const
224+
{
225+
QFontMetrics myTitleMetrics( titleFont( theOption ) );
226+
QFontMetrics myDetailMetrics( detailFont( theOption ) );
227+
//we dont word wrap the title so its easy to measure
228+
int myHeight = myTitleMetrics.height() + verticalSpacing();
229+
//the detail needs to be measured though
230+
QStringList myList = wordWrap( theData.detail(),
231+
myDetailMetrics,
232+
theOption.rect.width() - ( mpCheckBox->width() + horizontalSpacing() ) );
233+
myHeight += ( myList.count() + 1 ) * ( myDetailMetrics.height() - verticalSpacing() );
234+
return myHeight;
235+
}
236+
237+
238+
QFont QgsDetailedItemDelegate::detailFont(const QStyleOptionViewItem &theOption) const
239+
{
240+
QFont myFont = theOption.font;
241+
return myFont;
242+
}
243+
244+
QFont QgsDetailedItemDelegate::titleFont(const QStyleOptionViewItem &theOption) const
245+
{
246+
QFont myTitleFont = detailFont(theOption);
247+
myTitleFont.setBold(true);
248+
myTitleFont.setPointSize(myTitleFont.pointSize() + 1);
249+
return myTitleFont;
250+
}
251+
252+
229253
QStringList QgsDetailedItemDelegate::wordWrap(QString theString,
230254
QFontMetrics theMetrics,
231255
int theWidth) const
@@ -272,3 +296,27 @@ QStringList QgsDetailedItemDelegate::wordWrap(QString theString,
272296

273297
}
274298

299+
300+
301+
int QgsDetailedItemDelegate::verticalSpacing() const
302+
{
303+
return mVerticalSpacing;
304+
}
305+
306+
307+
void QgsDetailedItemDelegate::setVerticalSpacing( int theValue )
308+
{
309+
mVerticalSpacing = theValue;
310+
}
311+
312+
313+
int QgsDetailedItemDelegate::horizontalSpacing() const
314+
{
315+
return mHorizontalSpacing;
316+
}
317+
318+
319+
void QgsDetailedItemDelegate::setHorizontalSpacing( int theValue )
320+
{
321+
mHorizontalSpacing = theValue;
322+
}

‎src/gui/qgsdetaileditemdelegate.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323

2424
class QCheckBox;
2525
class QgsDetailedItemWidget;
26+
class QgsDetailedItemData;
2627
class QFontMetrics;
28+
class QFont;
2729

2830
class GUI_EXPORT QgsDetailedItemDelegate :
2931
public QAbstractItemDelegate
@@ -32,17 +34,47 @@ class GUI_EXPORT QgsDetailedItemDelegate :
3234
public:
3335
QgsDetailedItemDelegate(QObject * parent = 0);
3436
~QgsDetailedItemDelegate();
37+
/** reimplement for parent class */
3538
void paint(QPainter * thePainter,
3639
const QStyleOptionViewItem & theOption,
3740
const QModelIndex & theIndex) const;
41+
/** reimplement for parent class */
3842
QSize sizeHint( const QStyleOptionViewItem & theOption,
3943
const QModelIndex & theIndex ) const;
44+
45+
void setVerticalSpacing( int theValue );
46+
47+
int verticalSpacing() const;
48+
49+
void setHorizontalSpacing( int theValue );
50+
51+
int horizontalSpacing() const;
52+
53+
54+
55+
4056
private:
57+
QFont detailFont(const QStyleOptionViewItem &theOption) const;
58+
QFont titleFont(const QStyleOptionViewItem &theOption) const;
59+
void drawHighlight(const QStyleOptionViewItem &theOption,
60+
QPainter * thepPainter,
61+
int theHeight) const;
62+
4163
QStringList wordWrap(QString theString,
4264
QFontMetrics theMetrics,
4365
int theWidth) const;
66+
void paintManually(QPainter * thePainter,
67+
const QStyleOptionViewItem & theOption,
68+
const QgsDetailedItemData theData) const;
69+
void paintAsWidget(QPainter * thePainter,
70+
const QStyleOptionViewItem & theOption,
71+
const QgsDetailedItemData theData) const;
72+
int height(const QStyleOptionViewItem & theOption,
73+
const QgsDetailedItemData theData) const;
4474
QgsDetailedItemWidget * mpWidget;
4575
QCheckBox * mpCheckBox;
76+
int mVerticalSpacing;
77+
int mHorizontalSpacing;
4678
};
4779

4880
#endif //QGSDETAILEDITEMDELEGATE_H

0 commit comments

Comments
 (0)
Please sign in to comment.