void QgsDetailedItemWidget::setData( QgsDetailedItemData theData ) { lblTitle->setText( theData.title() ); lblDetail->setText( theData.detail() ); lblCategory->setText( theData.category() ); cbx->setVisible( theData.isCheckable() ); cbx->setChecked( theData.isChecked() ); lblIcon->setPixmap( theData.icon() ); }
void QgsPluginManager::unload() { QSettings settings; QgsDebugMsg( "Checking for plugins to unload" ); for ( int row = 0; row < mModelPlugins->rowCount(); row++ ) { // FPV - I want to use index. You can do evrething with item. QModelIndex myIndex = mModelPlugins->index( row, 0 ); QgsDetailedItemData myData = qVariantValue<QgsDetailedItemData>( mModelPlugins->data( myIndex, PLUGIN_DATA_ROLE ) ); if ( !myData.isChecked() ) { // iThe plugin name without version string in its data PLUGIN_LIB [ts] myIndex = mModelPlugins->index( row, 0 ); // its off -- see if it is loaded and if so, unload it QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance(); // is loaded? QString baseName = mModelPlugins->data( myIndex, PLUGIN_BASE_NAME_ROLE ).toString(); if ( ! pRegistry->isLoaded( baseName ) ) continue; if ( pRegistry->isPythonPlugin( baseName ) ) { if ( mPythonUtils && mPythonUtils->isEnabled() ) { if ( mPythonUtils->canUninstallPlugin( baseName ) ) { mPythonUtils->unloadPlugin( baseName ); //disable it to the qsettings file settings.setValue( "/PythonPlugins/" + baseName, false ); } } } else // C++ plugin { QgisPlugin *plugin = pRegistry->plugin( baseName ); if ( plugin ) { plugin->unload(); } //disable it to the qsettings file [ts] settings.setValue( "/Plugins/" + baseName, false ); } // remove the plugin from the registry pRegistry->removePlugin( baseName ); } } QgsPluginRegistry::instance()->dump(); }
void QgsDetailedItemDelegate::paintAsWidget( QPainter *thepPainter, const QStyleOptionViewItem &theOption, const QgsDetailedItemData &theData ) const { mpWidget->setChecked( theData.isChecked() ); mpWidget->setData( theData ); mpWidget->resize( theOption.rect.width(), mpWidget->height() ); mpWidget->setAutoFillBackground( true ); //mpWidget->setAttribute(Qt::WA_OpaquePaintEvent); mpWidget->repaint(); if ( theOption.state & QStyle::State_Selected ) { drawHighlight( theOption, thepPainter, height( theOption, theData ) ); } QPixmap myPixmap = QPixmap::grabWidget( mpWidget ); thepPainter->drawPixmap( theOption.rect.x(), theOption.rect.y(), myPixmap ); }//render as widget
void QgsPluginManager::on_vwPlugins_clicked( const QModelIndex &theIndex ) { if ( theIndex.column() == 0 ) { // // If the model has been filtered, the index row in the proxy wont match // the index row in the underlying model so we need to jump through this // little hoop to get the correct item // QModelIndex realIndex = mModelProxy->mapToSource( theIndex ); QStandardItem* mypItem = mModelPlugins->itemFromIndex( realIndex ); QgsDetailedItemData myData = qVariantValue<QgsDetailedItemData>( mypItem->data( PLUGIN_DATA_ROLE ) ); if ( myData.isEnabled() ) { myData.setChecked( ! myData.isChecked() ); } QVariant myVariant = qVariantFromValue( myData ); mypItem->setData( myVariant, PLUGIN_DATA_ROLE ); } }
std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins() { std::vector < QgsPluginItem > pis; // FPV - I want to use item here. You can do everything with index if you want. for ( int row = 0; row < mModelPlugins->rowCount(); row++ ) { QgsDetailedItemData myData = qVariantValue<QgsDetailedItemData>( mModelPlugins->item( row, 0 )->data( PLUGIN_DATA_ROLE ) ); if ( myData.isChecked() ) { //QString baseName = mModelPlugins->item( row, 0 )->data( PLUGIN_BASE_NAME_ROLE ).toString(); QString pluginName = mModelPlugins->item( row, 0 )->data( Qt::DisplayRole ).toString(); bool pythonic = false; QString library = mModelPlugins->item( row, 0 )->data( PLUGIN_LIBRARY_ROLE ).toString(); if ( library.left( 7 ) == "python:" ) { library = library.mid( 7 ); pythonic = true; } else // C++ plugin { QString dir = mModelPlugins->item( row, 0 )->data( PLUGIN_DIRECTORY_ROLE ).toString(); //library = lblPluginDir->text() + QDir::separator() + library; library = dir + QDir::separator() + library; } // Ctor params for plugin item: //QgsPluginItem(QString name=0, // QString description=0, // QString fullPath=0, // QString type=0, // bool python=false); pis.push_back( QgsPluginItem( pluginName, library, 0, pythonic ) ); } } return pis; }
void QgsDetailedItemDelegate::paintManually( QPainter *thepPainter, const QStyleOptionViewItem &theOption, const QgsDetailedItemData &theData ) const { // // Get the strings and check box properties // //bool myCheckState = theIndex.model()->data(theIndex, Qt::CheckStateRole).toBool(); mpCheckBox->setChecked( theData.isChecked() ); mpCheckBox->setEnabled( theData.isEnabled() ); QPixmap myCbxPixmap( mpCheckBox->size() ); mpCheckBox->render( &myCbxPixmap ); //we will draw this onto the widget further down // // Calculate the widget height and other metrics // QFontMetrics myTitleMetrics( titleFont( theOption ) ); QFontMetrics myDetailMetrics( detailFont( theOption ) ); int myTextStartX = theOption.rect.x() + horizontalSpacing(); int myTextStartY = theOption.rect.y() + verticalSpacing(); int myHeight = myTitleMetrics.height() + verticalSpacing(); // // Draw the item background with a gradient if its highlighted // if ( theOption.state & QStyle::State_Selected ) { drawHighlight( theOption, thepPainter, height( theOption, theData ) ); thepPainter->setPen( theOption.palette.highlightedText().color() ); } else { thepPainter->setPen( theOption.palette.text().color() ); } // // Draw the checkbox // if ( theData.isCheckable() ) { thepPainter->drawPixmap( theOption.rect.x(), theOption.rect.y() + mpCheckBox->height(), myCbxPixmap ); myTextStartX = theOption.rect.x() + myCbxPixmap.width() + horizontalSpacing(); } // // Draw the decoration (pixmap) // bool myIconFlag = false; QPixmap myDecoPixmap = theData.icon(); if ( !myDecoPixmap.isNull() ) { myIconFlag = true; int iconWidth = 32, iconHeight = 32; if ( myDecoPixmap.width() <= iconWidth && myDecoPixmap.height() <= iconHeight ) { // the pixmap has reasonable size int offsetX = 0, offsetY = 0; if ( myDecoPixmap.width() < iconWidth ) offsetX = ( iconWidth - myDecoPixmap.width() ) / 2; if ( myDecoPixmap.height() < iconHeight ) offsetY = ( iconHeight - myDecoPixmap.height() ) / 2; thepPainter->drawPixmap( myTextStartX + offsetX, myTextStartY + offsetY, myDecoPixmap ); } else { // shrink the pixmap, it's too big thepPainter->drawPixmap( myTextStartX, myTextStartY, iconWidth, iconHeight, myDecoPixmap ); } myTextStartX += iconWidth + horizontalSpacing(); } // // Draw the title // myTextStartY += myHeight / 2; thepPainter->setFont( titleFont( theOption ) ); thepPainter->drawText( myTextStartX, myTextStartY, theData.title() ); // // Draw the description with word wrapping if needed // thepPainter->setFont( detailFont( theOption ) ); //return to original font set by client if ( myIconFlag ) { myTextStartY += verticalSpacing(); } else { myTextStartY += myDetailMetrics.height() + verticalSpacing(); } QStringList myList = wordWrap( theData.detail(), myDetailMetrics, theOption.rect.width() - myTextStartX ); QStringListIterator myLineWrapIterator( myList ); while ( myLineWrapIterator.hasNext() ) { QString myLine = myLineWrapIterator.next(); thepPainter->drawText( myTextStartX, myTextStartY, myLine ); myTextStartY += myDetailMetrics.height() - verticalSpacing(); } // // Draw the category. Not sure if we need word wrapping for it. // thepPainter->setFont( categoryFont( theOption ) ); //return to original font set by client thepPainter->drawText( myTextStartX, myTextStartY, theData.category() ); // // Draw the category with word wrapping if needed // /* myTextStartY += verticalSpacing(); if ( myIconFlag ) { myTextStartY += verticalSpacing(); } else { myTextStartY += myCategoryMetrics.height() + verticalSpacing(); } myList = wordWrap( theData.category(), myCategoryMetrics, theOption.rect.width() - myTextStartX ); QStringListIterator myLineWrapIter( myList ); while ( myLineWrapIter.hasNext() ) { QString myLine = myLineWrapIter.next(); thepPainter->drawText( myTextStartX, myTextStartY, myLine ); myTextStartY += myCategoryMetrics.height() - verticalSpacing(); } */ } //render by manual painting