Skip to content

Commit

Permalink
Refactored detaileditemdelegate to avoid code duplication and try to …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
timlinux committed Jul 15, 2008
1 parent e1342f5 commit 5e55aca
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 178 deletions.
39 changes: 26 additions & 13 deletions src/app/qgspluginmanager.cpp
Expand Up @@ -305,15 +305,13 @@ sharedLibExtension = "*.so*";
myData.setTitle(pName());
myData.setDetail(pDesc());
myData.setRenderAsWidget(false);
QVariant myVariant = qVariantFromValue(myData);
myData.setCheckable(true);
myData.setChecked(false); //start unchecked - we will check it later if needed

//round trip test - delete this...no need to uncomment
//QgsDetailedItemData myData2 = qVariantValue<QgsDetailedItemData>(myVariant);
//Q_ASSERT(myData.title() == myData2.title());
//round trip test ends
mypDetailItem->setData(myVariant,PLUGIN_DATA_ROLE);
// Let the first col have a checkbox
mypDetailItem->setCheckable(true);
mypDetailItem->setEditable(false);

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

Expand All @@ -332,9 +330,11 @@ sharedLibExtension = "*.so*";
if (libName == myLib->fileName())
{
// set the checkbox
mypDetailItem->setCheckState(Qt::Checked);
myData.setChecked(true);
}
}
QVariant myVariant = qVariantFromValue(myData);
mypDetailItem->setData(myVariant,PLUGIN_DATA_ROLE);
// Add items to model
mModelPlugins->appendRow(mypDetailItem);

Expand Down Expand Up @@ -437,8 +437,13 @@ void QgsPluginManager::selectAll()
// select all plugins
for (int row=0;row < mModelPlugins->rowCount();row++)
{
QStandardItem *myItem=mModelPlugins->item(row,0);
myItem->setCheckState(Qt::Checked);
QStandardItem *mypItem=mModelPlugins->item(row,0);
QgsDetailedItemData myData =
qVariantValue<QgsDetailedItemData>(mypItem->data(PLUGIN_DATA_ROLE));
myData.setChecked(true);
QVariant myVariant = qVariantFromValue(myData);
mypItem->setData(myVariant,PLUGIN_DATA_ROLE);

}
}

Expand All @@ -447,8 +452,12 @@ void QgsPluginManager::clearAll()
// clear all selection checkboxes
for (int row=0;row < mModelPlugins->rowCount();row++)
{
QStandardItem *myItem=mModelPlugins->item(row,0);
myItem->setCheckState(Qt::Unchecked);
QStandardItem *mypItem=mModelPlugins->item(row,0);
QgsDetailedItemData myData =
qVariantValue<QgsDetailedItemData>(mypItem->data(PLUGIN_DATA_ROLE));
myData.setChecked(false);
QVariant myVariant = qVariantFromValue(myData);
mypItem->setData(myVariant,PLUGIN_DATA_ROLE);
}
}

Expand All @@ -463,14 +472,18 @@ void QgsPluginManager::on_vwPlugins_clicked(const QModelIndex &theIndex )
//
QStandardItem * mypItem =
mModelPlugins->findItems(theIndex.data(Qt ::DisplayRole).toString()).first();
if ( mypItem->checkState() == Qt::Checked )
QgsDetailedItemData myData =
qVariantValue<QgsDetailedItemData>(mypItem->data(PLUGIN_DATA_ROLE));
if ( myData.isChecked() )
{
mypItem->setCheckState(Qt::Unchecked);
myData.setChecked(false);
}
else
{
mypItem->setCheckState(Qt::Checked);
myData.setChecked(true);
}
QVariant myVariant = qVariantFromValue(myData);
mypItem->setData(myVariant,PLUGIN_DATA_ROLE);
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/gui/qgsdetaileditemdata.cpp
Expand Up @@ -26,59 +26,59 @@ QgsDetailedItemData::~QgsDetailedItemData()
{
}

void QgsDetailedItemData::setTitle(QString theTitle)
void QgsDetailedItemData::setTitle(const QString theTitle)
{
mTitle=theTitle;
}

void QgsDetailedItemData::setDetail(QString theDetail)
void QgsDetailedItemData::setDetail(const QString theDetail)
{
mDetail=theDetail;
}

void QgsDetailedItemData::setIcon(QPixmap theIcon)
void QgsDetailedItemData::setIcon(const QPixmap theIcon)
{
mPixmap = theIcon;
}
void QgsDetailedItemData::setCheckable(bool theFlag)
void QgsDetailedItemData::setCheckable(const bool theFlag)
{
mCheckableFlag = theFlag;
}
void QgsDetailedItemData::setChecked(bool theFlag)
void QgsDetailedItemData::setChecked(const bool theFlag)
{
mCheckedFlag = theFlag;
}
void QgsDetailedItemData::setRenderAsWidget(bool theFlag)
void QgsDetailedItemData::setRenderAsWidget(const bool theFlag)
{
mRenderAsWidgetFlag = theFlag;
}

QString QgsDetailedItemData::title()
QString QgsDetailedItemData::title() const
{
return mTitle;
}

QString QgsDetailedItemData::detail()
QString QgsDetailedItemData::detail() const
{
return mDetail;
}

QPixmap QgsDetailedItemData::icon()
QPixmap QgsDetailedItemData::icon() const
{
return mPixmap;
}

bool QgsDetailedItemData::isCheckable()
bool QgsDetailedItemData::isCheckable() const
{
return mCheckableFlag;
}

bool QgsDetailedItemData::isChecked()
bool QgsDetailedItemData::isChecked() const
{
return mCheckedFlag;
}

bool QgsDetailedItemData::isRenderedAsWidget()
bool QgsDetailedItemData::isRenderedAsWidget() const
{
return mRenderAsWidgetFlag;
}
Expand Down
22 changes: 11 additions & 11 deletions src/gui/qgsdetaileditemdata.h
Expand Up @@ -31,11 +31,11 @@ class GUI_EXPORT QgsDetailedItemData
public:
QgsDetailedItemData();
~QgsDetailedItemData();
void setTitle(QString theTitle);
void setDetail(QString theDetail);
void setIcon(QPixmap theIcon);
void setCheckable(bool theFlag);
void setChecked(bool theFlag);
void setTitle(const QString theTitle);
void setDetail(const QString theDetail);
void setIcon(const QPixmap theIcon);
void setCheckable(const bool theFlag);
void setChecked(const bool theFlag);
/** This is a hint to the delegate to render using
* a widget rather than manually painting every
* part of the list item.
Expand All @@ -44,12 +44,12 @@ class GUI_EXPORT QgsDetailedItemData
*/
void setRenderAsWidget(bool theFlag);

QString title();
QString detail();
QPixmap icon();
bool isCheckable();
bool isChecked();
bool isRenderedAsWidget();
QString title() const;
QString detail() const;
QPixmap icon() const;
bool isCheckable() const;
bool isChecked() const;
bool isRenderedAsWidget() const;

private:
QString mTitle;
Expand Down

0 comments on commit 5e55aca

Please sign in to comment.