#include "qgsdesignerwidgets.h" #include #include #include #include "qgslegend.h" #include "qgsmapcanvas.h" static const char *legend_pixmap[] = { "22 22 8 1", " c Gray100", ". c Gray97", "X c #4f504f", "o c #00007f", "O c Gray0", "+ c none", "@ c Gray0", "# c Gray0", "++++++++++++++++++++++", "++++++++++++++++++++++", "++++++++++++++++++++++", "++++++++++++++++++++++", "+OOOOOOOOOOOOOOOOOOOO+", "OOXXXXXXXXXXXXXXXXXXOO", "OXX. O", "OX. ooooooooo O", "OX. o o .O", "OX o o O", "OX o o O", "O o o O", "OX o o o O", "OX o o o O", "OX o o O", "OX ooooooooo o O", "OO..................OO", "+OOOOOOOOOOOOOOOOOOOO+", "++++++++++++++++++++++", "++++++++++++++++++++++", "++++++++++++++++++++++", "++++++++++++++++++++++" }; //shamelessly snarfed from qwt stuff - a very nice simple neat way to //accommodate building multiple widgets...Tim namespace { struct Entry { Entry() {} Entry( QString theClassname, QString theHeader, QString thePixmap, QString theTooltip, QString theWhatsThisString): classname(theClassname), header(theHeader), pixmap(thePixmap), tooltip(theTooltip), whatshis(theWhatsThisString) {} QString classname; QString header; QString pixmap; QString tooltip; QString whatshis; }; QValueList mEntriesVector; const Entry *entry(const QString& theString) { for ( uint i = 0; i < mEntriesVector.count(); i++ ) { if (theString == mEntriesVector[i].classname) return &mEntriesVector[i]; } return NULL; } } QgsDesignerWidgets::QgsDesignerWidgets() { mEntriesVector.append(Entry("QgsLegend", "qgslegend.h", "qwtplot.png", "A legend widget that shows layers associated with a mapcanvas.", "A legend widget that shows layers associated with a mapcanvas")); mEntriesVector.append(Entry("QgsMapCanvas", "qgsmapcanvas.h", "somepng.png", "A map canvas widget", "A map canvas is an interactive map that can be panned and zoomed.")); } QWidget* QgsDesignerWidgets::create(const QString &key, QWidget* parent, const char* name) { if ( key == "QgsLegend" ) return new QgsLegend( parent, name ); else if ( key == "QgsMapCanvas" ) return new QgsMapCanvas ( parent, name ); return 0; } QStringList QgsDesignerWidgets::keys() const { QStringList list; for (unsigned i = 0; i < mEntriesVector.count(); i++) list += mEntriesVector[i].classname; return list; } QString QgsDesignerWidgets::group( const QString& feature ) const { if (entry(feature) != NULL ) return QString("QGIS"); return QString::null; } QIconSet QgsDesignerWidgets::iconSet( const QString& thePixmap) const { QString pixmapKey("qwtwidget.png"); if (entry(thePixmap) != NULL ) pixmapKey = entry(thePixmap)->pixmap; const QMimeSource *ms = QMimeSourceFactory::defaultFactory()->data(pixmapKey); QPixmap pixmap; QImageDrag::decode(ms, pixmap); return QIconSet(pixmap); } QString QgsDesignerWidgets::includeFile( const QString& feature ) const { if (entry(feature) != NULL) return entry(feature)->header; return QString::null; } QString QgsDesignerWidgets::toolTip( const QString& feature ) const { if (entry(feature) != NULL ) return entry(feature)->tooltip; return QString::null; } QString QgsDesignerWidgets::whatsThis( const QString& feature ) const { if (entry(feature) != NULL) return entry(feature)->whatshis; return QString::null; } bool QgsDesignerWidgets::isContainer( const QString& ) const { return FALSE; } /* The Q_EXPORT_PLUGIN macro. Q_EXPORT_PLUGIN( CustomWidgetPlugin ) This macro identifies the module as a plugin -- all the other code simply implements the relevant interface, i.e. wraps the classes you wish to make available. This macro must appear once in your plugin. It should be copied with the class name changed to the name of your plugin's class. (See the Qt Plugin documentation for more information on the plugin entry point.) Each widget you wrap in a widget plugin implementation becomes a class that the plugin implementation offers. There is no limit to the number of classes that you may include in an plugin implementation. */ Q_EXPORT_PLUGIN( QgsDesignerWidgets )