|
| 1 | +#include "qgsdesignerwidgets.h" |
| 2 | +#include <qstringlist.h> |
| 3 | +#include <qimage.h> |
| 4 | +#include <q3dragobject.h> |
| 5 | +#include "qgslegend.h" |
| 6 | +#include "qgsmapcanvas.h" |
| 7 | +#include "qgslinestylewidget.h" |
| 8 | +#include "qgsfillstylewidget.h" |
| 9 | +#include "qgspointstylewidget.h" |
| 10 | +#include "qgsvectorsymbologywidget.h" |
| 11 | +//Added by qt3to4: |
| 12 | +#include <QPixmap> |
| 13 | +#include <Q3ValueList> |
| 14 | +static const char *legend_pixmap[] = { |
| 15 | + "22 22 8 1", |
| 16 | + " c Gray100", |
| 17 | + ". c Gray97", |
| 18 | + "X c #4f504f", |
| 19 | + "o c #00007f", |
| 20 | + "O c Gray0", |
| 21 | + "+ c none", |
| 22 | + "@ c Gray0", |
| 23 | + "# c Gray0", |
| 24 | + "++++++++++++++++++++++", |
| 25 | + "++++++++++++++++++++++", |
| 26 | + "++++++++++++++++++++++", |
| 27 | + "++++++++++++++++++++++", |
| 28 | + "+OOOOOOOOOOOOOOOOOOOO+", |
| 29 | + "OOXXXXXXXXXXXXXXXXXXOO", |
| 30 | + "OXX. O", |
| 31 | + "OX. ooooooooo O", |
| 32 | + "OX. o o .O", |
| 33 | + "OX o o O", |
| 34 | + "OX o o O", |
| 35 | + "O o o O", |
| 36 | + "OX o o o O", |
| 37 | + "OX o o o O", |
| 38 | + "OX o o O", |
| 39 | + "OX ooooooooo o O", |
| 40 | + "OO..................OO", |
| 41 | + "+OOOOOOOOOOOOOOOOOOOO+", |
| 42 | + "++++++++++++++++++++++", |
| 43 | + "++++++++++++++++++++++", |
| 44 | + "++++++++++++++++++++++", |
| 45 | + "++++++++++++++++++++++" |
| 46 | +}; |
| 47 | + |
| 48 | +//shamelessly snarfed from qwt stuff - a very nice simple neat way to |
| 49 | +//accommodate building multiple widgets...Tim |
| 50 | +namespace |
| 51 | +{ |
| 52 | + struct Entry |
| 53 | + { |
| 54 | + Entry() {} |
| 55 | + Entry( QString theClassname, QString theHeader, QString thePixmap, |
| 56 | + QString theTooltip, QString theWhatsThisString): |
| 57 | + classname(theClassname), |
| 58 | + header(theHeader), |
| 59 | + pixmap(thePixmap), |
| 60 | + tooltip(theTooltip), |
| 61 | + whatshis(theWhatsThisString) |
| 62 | + {} |
| 63 | + |
| 64 | + QString classname; |
| 65 | + QString header; |
| 66 | + QString pixmap; |
| 67 | + QString tooltip; |
| 68 | + QString whatshis; |
| 69 | + }; |
| 70 | + |
| 71 | + Q3ValueList<Entry> mEntriesVector; |
| 72 | + |
| 73 | + const Entry *entry(const QString& theString) |
| 74 | + { |
| 75 | + for ( uint i = 0; i < mEntriesVector.count(); i++ ) |
| 76 | + { |
| 77 | + if (theString == mEntriesVector[i].classname) |
| 78 | + return &mEntriesVector[i]; |
| 79 | + } |
| 80 | + return NULL; |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | + QgsDesignerWidgets::QgsDesignerWidgets(QObject *parent) |
| 85 | +: QObject(parent) |
| 86 | + |
| 87 | +{ |
| 88 | + mInitialized = false; |
| 89 | + |
| 90 | + mEntriesVector.append(Entry("QgsLegend", "qgslegend.h", |
| 91 | + "", "A legend widget that shows layers associated with a mapcanvas.", "A legend widget that shows layers associated with a mapcanvas")); |
| 92 | + mEntriesVector.append(Entry("QgsMapCanvas", "qgsmapcanvas.h", |
| 93 | + "", "A map canvas widget", "A map canvas is an interactive map that can be panned and zoomed.")); |
| 94 | + mEntriesVector.append(Entry("QgsLineStyleWidget", "qgslinestylewidget.h", |
| 95 | + "", "A widget that lets you select a line style.", "A widget that lets you select a line style")); |
| 96 | + mEntriesVector.append(Entry("QgsFillStyleWidget", "qgsfillstylewidget.h", |
| 97 | + "", "A widget that lets you select a fill style.", "A widget that lets you select a fill style")); |
| 98 | + mEntriesVector.append(Entry("QgsPointStyleWidget", "qgspointstylewidget.h", |
| 99 | + "", "A widget that lets you select a point style.", "A widget that lets you select a point style")); |
| 100 | + mEntriesVector.append(Entry("QgsVectorSymbologyWidget", "QgsVectorSymbologyWidget", |
| 101 | + "", "A widget that lets you select vector symbology.", "A widget that lets you select vector symbology")); |
| 102 | +} |
| 103 | + |
| 104 | + |
| 105 | +void QgsDesignerWidgets::initialize(QDesignerFormEditorInterface * core ) |
| 106 | +{ |
| 107 | + if (mInitialized) |
| 108 | + return; |
| 109 | + |
| 110 | + mInitialized = true; |
| 111 | +} |
| 112 | + |
| 113 | +bool QgsDesignerWidgets::isInitialized() const |
| 114 | +{ |
| 115 | + return mInitialized; |
| 116 | +} |
| 117 | + |
| 118 | +QWidget* QgsDesignerWidgets::create(const QString &key, |
| 119 | + QWidget* parent, const char* name) |
| 120 | +{ |
| 121 | + if ( key == "QgsLegend" ) |
| 122 | + return new QgsLegend( parent, name ); |
| 123 | + else if ( key == "QgsMapCanvas" ) |
| 124 | + return new QgsMapCanvas ( parent, name ); |
| 125 | + else if ( key == "QgsLineStyleWidget" ) |
| 126 | + return new QgsLineStyleWidget ( parent, name ); |
| 127 | + else if ( key == "QgsFillStyleWidget" ) |
| 128 | + return new QgsFillStyleWidget ( parent, name ); |
| 129 | + else if ( key == "QgsPointStyleWidget" ) |
| 130 | + return new QgsPointStyleWidget ( parent, name ); |
| 131 | + else if ( key == "QgsVectorSymbologyWidget" ) |
| 132 | + return new QgsVectorSymbologyWidget( parent, name ); |
| 133 | + return 0; |
| 134 | +} |
| 135 | + |
| 136 | + |
| 137 | +QStringList QgsDesignerWidgets::keys() const |
| 138 | +{ |
| 139 | + QStringList list; |
| 140 | + |
| 141 | + for (unsigned i = 0; i < mEntriesVector.count(); i++) |
| 142 | + list += mEntriesVector[i].classname; |
| 143 | + |
| 144 | + return list; |
| 145 | +} |
| 146 | + |
| 147 | +QString QgsDesignerWidgets::group( const QString& feature ) const |
| 148 | +{ |
| 149 | + if (entry(feature) != NULL ) |
| 150 | + return QString("QGIS"); |
| 151 | + return QString::null; |
| 152 | +} |
| 153 | + |
| 154 | +QIcon QgsDesignerWidgets::iconSet( const QString& thePixmap) const |
| 155 | +{ |
| 156 | + QString pixmapKey("qwtwidget.png"); |
| 157 | + if (entry(thePixmap) != NULL ) |
| 158 | + pixmapKey = entry(thePixmap)->pixmap; |
| 159 | + |
| 160 | + const QMimeSource *ms = |
| 161 | + Q3MimeSourceFactory::defaultFactory()->data(pixmapKey); |
| 162 | + |
| 163 | + QPixmap pixmap; |
| 164 | + Q3ImageDrag::decode(ms, pixmap); |
| 165 | + |
| 166 | + return QIcon(pixmap); |
| 167 | +} |
| 168 | + |
| 169 | +QString QgsDesignerWidgets::includeFile( const QString& feature ) const |
| 170 | +{ |
| 171 | + if (entry(feature) != NULL) |
| 172 | + return entry(feature)->header; |
| 173 | + return QString::null; |
| 174 | +} |
| 175 | + |
| 176 | +QString QgsDesignerWidgets::toolTip( const QString& feature ) const |
| 177 | +{ |
| 178 | + if (entry(feature) != NULL ) |
| 179 | + return entry(feature)->tooltip; |
| 180 | + return QString::null; |
| 181 | +} |
| 182 | + |
| 183 | +QString QgsDesignerWidgets::whatsThis( const QString& feature ) const |
| 184 | +{ |
| 185 | + if (entry(feature) != NULL) |
| 186 | + return entry(feature)->whatshis; |
| 187 | + return QString::null; |
| 188 | +} |
| 189 | + |
| 190 | +bool QgsDesignerWidgets::isContainer( const QString& ) const |
| 191 | +{ |
| 192 | + return FALSE; |
| 193 | +} |
| 194 | + |
| 195 | +/* |
| 196 | + The Q_EXPORT_PLUGIN macro. |
| 197 | + Q_EXPORT_PLUGIN( CustomWidgetPlugin ) |
| 198 | + This macro identifies the module as a plugin -- all the other code simply |
| 199 | + implements the relevant interface, i.e. wraps the classes you wish to make available. |
| 200 | + This macro must appear once in your plugin. It should be copied with the class name |
| 201 | + changed to the name of your plugin's class. (See the Qt Plugin documentation for more |
| 202 | + information on the plugin entry point.) |
| 203 | + Each widget you wrap in a widget plugin implementation becomes a class that the |
| 204 | + plugin implementation offers. There is no limit to the number of classes that you |
| 205 | + may include in an plugin implementation. |
| 206 | + */ |
| 207 | +Q_EXPORT_PLUGIN( QgsDesignerWidgets ) |
0 commit comments