Skip to content

Commit 5e55aca

Browse files
author
timlinux
committed
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/qgis@8787 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e1342f5 commit 5e55aca

5 files changed

+271
-178
lines changed

src/app/qgspluginmanager.cpp

+26-13
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

+12-12
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

+11-11
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;

0 commit comments

Comments
 (0)