Skip to content
Permalink
Browse files
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
  • Loading branch information
timlinux committed Jul 15, 2008
1 parent db036f6 commit cd965f4
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 178 deletions.
@@ -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");

@@ -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);

@@ -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);

}
}

@@ -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);
}
}

@@ -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);
}
}

@@ -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;
}
@@ -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.
@@ -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;

0 comments on commit cd965f4

Please sign in to comment.