Exercise

Add a new method to the ShipTableModel, sortByTEU(). Use any sorting technique you like; we have used DSU. Then use this method in MainForm.sort-Table(). In total this should take just half a dozen lines.

Extend the ShipTableModel.data() method to provide tooltips. The tip should simply be the text of the data item, except for TEUs, where the text should be the (localized) number followed by "twenty foot equivalents". Notice that HTML is correctly formatted in the tooltip. This is easy and takes only a dozen lines.

Modify ShipTableDelegate.setModelData() so that it will change the name, owner, or country, only if the new text is at least three characters long. Extend the tooltips for these columns with the text "(minimum of 3 characters)". This can be done in about half a dozen lines.

Add an Export button that, when pressed, prompts the user for a filename with the suffix .txt, and saves the data using the UTF-8 encoding, one ship per line, in the form:

name|owner|country|teu|description with a bar "I" (pipe) as a separator. The data should be accessed through the model's data() method and output in country/owner order, with no HTML tags in the description and with TEUs output with digits only (no commas, periods, or spaces). Pop up a message box at the end, either to report an error or to report success. Use Python or PyQt for writing the file; we have used PyQt. If you write using a version of PyQt prior to 4.1, you will need to convert the TEU to a QString before writing it to the text stream. The export() method can be written in less than 50 lines.

A solution is provided in chap14/ships_ans.py and chap14/ships-delegate-_ans.py.

This page intentionally left blank

• Connecting to the Database

• Executing SQL Queries

• Using Database Form Views

• Using Database Table Views

Was this article helpful?

0 0
YouTube Saturation

YouTube Saturation

Uncover The Instant Traffic System That Will TRIPLE Your Income Overnight While Putting You In Direct Contact With THOUSANDS Of Hungry Buyers. How to generate instant traffic to your website, easily! Siphon high quality, ultra-targeted traffic to your offers. The easiest way to dominate your market with lase targeted video based campaigns. These video ads will suck in customers by the minute, driving your message out to a global audience of buyers.

Get My Free Ebook


Post a comment