c# generate data matrix code 5: Doing More with Qt in Visual C#

Encoding Data Matrix in Visual C# 5: Doing More with Qt

CHAPTER 5: Doing More with Qt
Painting ECC200 In C#.NET
Using Barcode maker for Visual Studio .NET Control to generate, create Data Matrix 2d barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Scan Data Matrix ECC200 In Visual C#.NET
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Listing 5 16. Map widget initialization when the widget is resized void MapItemWidget::resizeEvent(QResizeEvent *event) { if (size() != mMapSize) { initMap(); initMarkers(); } } void MapItemWidget::initMap() { // Load the map bitmap QPixmap map(":/images/map.jpg"); QSize newSize(map.size()); newSize.scale(size(), Qt::KeepAspectRatio); if (newSize!=map.size()) { mMap = map.scaled(newSize, Qt::KeepAspectRatio); } // Record the widget size so we only rescale when we need to mMapSize = size(); } void MapItemWidget::initMarkers() { // Always start from scratch mMarkers.clear(); if (!mModel) { return; } for(int i = 0; i < mModel->rowCount(); i++) { QModelIndex index = mModel->index(i, 0); qreal lat = mModel->data(index, QuakeListModel::Latitude).value<qreal>(); qreal lon = mModel->data(index, QuakeListModel::Longitude).value<qreal>(); qreal mag = mModel->data(index, QuakeListModel::Magnitude).value<qreal>(); QPoint point = geoToWidgetCoords(lat, lon); mMarkers.append(QPair<QPoint, int>(point, mag)); } }
Generating 2D Barcode In C#
Using Barcode generation for VS .NET Control to generate, create 2D Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Creating EAN / UCC - 13 In Visual C#
Using Barcode creator for .NET Control to generate, create GTIN - 13 image in .NET applications.
www.OnBarcode.com
Handling the resizing event is easy just reinitialize the map s base layer and cache of item positions if the new size isn t the same as the current size. Resizing the base map itself is also easy, thanks to Qt s handling of image formats; we simply reload the base map (which is an image larger than we expect any device screen to be, but not so unwieldy for today s devices) and scale it to fit within the new widget s bounds, preserving the map s aspect ratio. This isn t perfect as you saw in Figure 5 2, the map ends up with black bands on the borders of the image but it prevents additional stretching and tearing that would distort the map projection further.
UPC A Generation In C#
Using Barcode printer for .NET framework Control to generate, create UPC Code image in .NET applications.
www.OnBarcode.com
QR Generation In C#.NET
Using Barcode creation for .NET framework Control to generate, create QR Code image in .NET framework applications.
www.OnBarcode.com
CHAPTER 5: Doing More with Qt
1D Barcode Encoder In Visual C#
Using Barcode maker for .NET Control to generate, create Linear image in .NET framework applications.
www.OnBarcode.com
Generate Uniform Symbology Specification ITF In C#.NET
Using Barcode maker for .NET Control to generate, create 2 of 5 Interleaved image in Visual Studio .NET applications.
www.OnBarcode.com
Initializing the map marker position cache is a little trickier. Because there are a small number of items, we do this any time the map rescales or when the model changes (which you see later in Listing 5 18). In either case, we simply clear the cache of markers and then walk the model, projecting each point from its coordinates on Earth to its coordinate on the map using the private function geoToWidgetCoords (not shown here, but available in the sample code that accompanies this book). As you ve seen elsewhere, we simply use the model itself to generate an index for each row in the model, and then extract the latitude, longitude, and quake magnitude from the model using its own data method. With the cache always up-to-date, the map widget s paint function need only draw the base map and then loop over the cache of projected markers, plotting a rectangle for each marker, as you see in Listing 5 17.
Data Matrix 2d Barcode Recognizer In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Recognize Data Matrix 2d Barcode In VB.NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Listing 5 17. Drawing the map and its markers void MapItemWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); QPoint pt; pt.setX(size().width() /2 - mMap.size().width() /2); pt.setY(size().height()/2 - mMap.size().height()/2); painter.drawPixmap(pt, mMap); painter.setBrush(Qt::SolidPattern); for( int i = mMarkers.length(); i>0; i--) { QPair<QPoint, int> marker = mMarkers.at(i-1); pt = marker.first; int r = marker.second; painter.fillRect(pt.x()-r, pt.y()-r, 2*r, 2*r, QColor(255, 0, 0)); } }
Code 3/9 Generator In Visual Studio .NET
Using Barcode generation for Reporting Service Control to generate, create Code 39 image in Reporting Service applications.
www.OnBarcode.com
QR Code JIS X 0510 Decoder In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
The code begins by calculating the upper-left-hand corner where to draw the map so it s centered horizontally and vertically. It then loops through the collection of map markers, painting a red-filled rectangle at each marker position. The rectangle s size is twice the magnitude of the earthquake on each axis, providing a slight idea as to the earthquake s relative magnitude without causing too much overlapping between adjacent earthquakes unless they re very close. The remaining methods of the map widget are largely bookkeeping to manage the map model itself, as you can see from Listing 5 18.
UCC - 12 Scanner In None
Using Barcode decoder for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Code 128B Generator In Visual Basic .NET
Using Barcode drawer for VS .NET Control to generate, create USS Code 128 image in VS .NET applications.
www.OnBarcode.com
CHAPTER 5: Doing More with Qt
Code39 Creation In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create Code39 image in ASP.NET applications.
www.OnBarcode.com
Making Matrix Barcode In VB.NET
Using Barcode creation for .NET framework Control to generate, create Matrix image in Visual Studio .NET applications.
www.OnBarcode.com
Listing 5 18. Managing the view s model and its signals void MapItemWidget::setModel(QAbstractItemModel* model) { if (mModel) { disconnect(mModel, 0, this, 0); } mModel = model; if (mModel) { connect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(itemsChanged(QModelIndex,QModelIndex))); connect(mModel, SIGNAL(modelReset()), this, SLOT(itemsReset())); } initMarkers(); update(); } void MapItemWidget::itemsChanged(const QModelIndex&, const QModelIndex &) { initMarkers(); update(); } void MapItemWidget::itemsReset() { initMarkers(); update(); }
EAN 128 Scanner In VB.NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Barcode Encoder In .NET Framework
Using Barcode creator for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
You first saw the map widget s setModel method invoked back in Listing 5 8; it needs to do four things: 1. 2. 3. 4. Disconnect from all signals emitted by the old model, if there is one. Cache a reference to the model so it can later get data from the model when it initializes or updates the list of map markers. Connect slots to the model s dataChanged and modelReset methods, so that the widget can redraw any time the model data changes. Re-initialize the cache of markers, so that the view updates with the new data.
Encoding EAN128 In .NET
Using Barcode encoder for Reporting Service Control to generate, create EAN 128 image in Reporting Service applications.
www.OnBarcode.com
Make Data Matrix 2d Barcode In Java
Using Barcode creation for Java Control to generate, create Data Matrix 2d barcode image in Java applications.
www.OnBarcode.com
The two slots that handle the model changes, itemsChanged and itemsReset, simply invalidate the entire cache and re-create the cache of markers. A more sophisticated view might keep a cache indexed by model index, so that the dataChanged signal s indices could be used to determine which items should be updated, and then update only the changed items. A good place to start in doing this would be to use a QHash keyed by QModelIndexes, with each entry in the cache being the projected point and its magnitude. However, given the number of items likely for the application (certainly less than one hundred), the infrequency of model updates (never, once the application has received its data), and the relatively low cost of handling a single item (a handful of floating-point operations) this complexity doesn t seem necessary.
Copyright © OnBarcode.com . All rights reserved.