QString QgsCustomizationDialog::widgetPath( QWidget * theWidget, const QString& thePath ) { // go up until QDialog is reached QString name = theWidget->objectName(); QString path = thePath; if ( !QgsCustomization::mInternalWidgets.contains( name ) ) { if ( !path.isEmpty() ) { path = name + '/' + path; } else { path = name; } } QWidget * parent = theWidget->parentWidget(); if ( !parent || theWidget->inherits( "QDialog" ) ) { return '/' + path; } return widgetPath( parent, path ); }
void CWidget::remove(CWorkerTools::WorkerProgressFunc progressCallback, const std::string & widgetName) { YADOMS_LOG(information) << "Removing widget " << widgetName; shared::CDataContainer callbackData; callbackData.set("widgetName", widgetName); progressCallback(true, 0.0f, i18n::CClientStrings::UpdateWidgetRemove, shared::CStringExtension::EmptyString, callbackData); try { ///////////////////////////////////////////// //1. remove plugin folder ///////////////////////////////////////////// Poco::Path widgetPath(CWorkerTools::getWidgetBasePath()); widgetPath.append(widgetName); Poco::File toDelete(widgetPath); if (toDelete.exists()) toDelete.remove(true); progressCallback(true, 100.0f, i18n::CClientStrings::UpdateWidgetSuccess, shared::CStringExtension::EmptyString, callbackData); } catch (std::exception & ex) { //fail to remove package YADOMS_LOG(error) << "Fail to delete widget : " << widgetName << " : " << ex.what(); progressCallback(false, 100.0f, i18n::CClientStrings::UpdateWidgetRemoveFailed, ex.what(), callbackData); } }
bool QgsCustomizationDialog::switchWidget( QWidget *widget, QMouseEvent *e ) { Q_UNUSED( e ); QgsDebugMsg( "Entered" ); if ( !actionCatch->isChecked() ) return false; QString path = widgetPath( widget ); QgsDebugMsg( "path = " + path ); if ( path.startsWith( "/QgsCustomizationDialogBase" ) ) { // do not allow modification of this dialog return false; } else if ( path.startsWith( "/QgisApp" ) ) { // changes to main window // (work with toolbars, tool buttons) if ( widget->inherits( "QToolBar" ) ) { path = "/Toolbars/" + widget->objectName(); } else if ( widget->inherits( "QToolButton" ) ) { QToolButton* toolbutton = qobject_cast<QToolButton*>( widget ); QAction* action = toolbutton->defaultAction(); if ( !action ) return false; QString toolbarName = widget->parent()->objectName(); QString actionName = action->objectName(); path = "/Toolbars/" + toolbarName + '/' + actionName; } else { // unsupported widget in main window return false; } } else { // ordinary widget in a dialog path = "/Widgets" + path; } QgsDebugMsg( "path final = " + path ); bool on = !itemChecked( path ); QgsDebugMsg( QString( "on = %1" ).arg( on ) ); setItemChecked( path, on ); QTreeWidgetItem *myItem = item( path ); if ( myItem ) { treeWidget->scrollToItem( myItem, QAbstractItemView::PositionAtCenter ); treeWidget->clearSelection(); myItem->setSelected( true ); QString style; if ( !on ) { style = "background-color: #FFCCCC;"; } widget->setStyleSheet( style ); } return true; }