Math 157: Assignment 8

Assigned Friday, Feb. 20, 2009, due Friday, Feb. 27, 2009


Written Work

[1] Construct a high level class diagram (just showing classes and associations) associated with the application constructed in Part II of the computational work.

[2] Create a state diagram of the application constructed in Part II of the computational work.

Computational Work

[Discussion/Preliminaries] The goal of the computational problem is to create an application that plots a user specified function. The user interface will be created and managed using Qt designer. In order to make the following instructions precise, specific names have been given for the user interface components and files. You may change the names if you desire, but be aware that you'll typically need to modify the instructions in several places to reflect a name change.

Part I of the assignment consists of creating a skeleton application that contains the essential ingredients to build an application whose user interface is managed by Qt Designer. Part II consists of "fleshing out" the application and implementing the desired functionality.

PART I : Setting up the required file structure and project files for an application whose interface is managed by Qt Designer.

[+] Obtain the repository SampleQt from the class repository at 157support.

[+] Create a subdirectory named Assign8 of your course directory to hold the files for this assignment.

[1] Use Qt Designer to create a "skeleton" user interface based upon the Main Window template:

  1. Open up a Visual Studio command prompt window and cd to the Assign8 directory
  2. Invoke Qt Designer from the command line by typing designer at a command prompt.
  3. In Qt Designer, select new, and then select templates/forms/Main Window in the dialog. Click Create.
  4. Resize the main window that appears to something manageable.
  5. In the property editor
    1. Set the objectName property of the top level QObject to PlotFunctionWindow
    2. Set the windowTitle property of the QMainWindow to Plot Function. You'll have to scroll down the properties list to reveal this.
  6. Check that your user interface works by previewing it. (From the menu-bar select Form, then Preview).
  7. Save the user interface as PlotFunctionWindow.ui in your assignment directory.

[2] Create the project structure and file structure required to build an application that uses the interface defined by PlotFunctionWindow.ui.

  1. Create empty files PlotFunctionApp.cpp, PlotFunction.h and PlotFunction.cpp in the Assign8 directory. This can be done with Window's explorer -- open up a view of Assign8 and then right click, select New, select Text document, and specify the files.
  2. Create the project file PlotFunction.pro file by executing
    qmake -project -o PlotFunction.pro
  3. Edit the PlotFunction.pro file and change the TEMPLATE variable from app to vcapp and add PlotFunction.pro to the SOURCES list. This latter change will enable you to modify the project file using the IDE. (This step is for Visual Studio users only).
  4. run qmake from the command line to create the Visual Studio project file PlotFunction.vcproj.
  5. Open up Visual Studio and add the PlotFunction project to your solution

[3] Create implementations of the main(...) routine and the PlotFunction class. This is most easily done by copying and pasting from the SampleQt codes and changing names accordingly.

  1. Create the implementation of PlotFunctionApp.cpp by copying the code from SampleQtApp.cpp and changing names appropriately.
    1. Change the class for mainWindow instance to PlotFunction
    2. Change the included header file to #include "PlotFunction.h"

  2. Create the implementation of PlotFunction.h by copying the code from SampleQt.h and changing names appropriately.
    1. Change the class name to PlotFunction (don't forget to change the constructor).
    2. Change the include of the user interface header to #include "ui_PlotFunctionWindow.h"
    3. Change the class of the user interface to Ui::PlotFunctionWindow

  3. Create the implementation of PlotFunction.cpp by copying the code from SampleQt.cpp and changing names appropriately.
    1. Change the included header file to #include "PlotFunction.h"
    2. Change the class name to PlotFunction

[4] Re-run qmake by cd'ing to the Assign8 directory and running qmake from the command line. If you have added qmake as a tool to your Visual Studio environment, then just select the qmake tool. Re-running qmake induces Qt create a makefile that will generate the required supporting files for the application.

[5] Build the project and run the executable. If you are successful, then the application interface that appears should be similar to that observed when previewing the interface in Qt Designer.

Part II: Create an application that plots a user specified function.

[+] Obtain the repository QtGLgraphics from 157support. This repository contains the support files for the classes GLDisplayListWidget and GLDriverQt.

[1] By adding to the user interface and application files created in Part I create an application that plots a user specified function. Your plots will be displayed using a GLDisplayListWidget widget .

Your application should possess the following functionality

  1. The user specifies the function by entering in the function $f(x)$ symbolically.
  2. A "plot" button that causes a plot of the curve to be generated in a region [-2,2]x[-2,2] for $x$ in [-2,2] . Your plot should have a frame around the graphical output.
  3. A "clear" button that clears the graphical display..
  4. When the main window is resized, the plotting window fills out the resized window proportionally.

Notes:

The typical programming procedure consists of a repetition of the following steps

You will use a GLDisplayListWidget to display graphics. Since this is a "custom" widget, in order to work with it in Qt Designer, you should use the Graphics View widget (one of the Qt Designer display widgets) as a placeholder. In order for the correct code to be generated from the user interface file, you'll need to "promote" the Graphics View widget to a GLDisplayListWidget. When promoting the object you will have to specify the header file GLDisplayListWidget.h that is associated with this widget. Instructions on promoting a Graphics View widget to a GLDisplayListWidget.

After placement in the user interface, the use of a GLDisplayListWidget to display graphics consists of obtaining a GLDriverQt pointer from the widget and passing it to code that is written using UCdriver graphics calls (e.g. the PlotData class you used in Assignment 6). For detailed information about setting up and using GLDisplayListWidget, see "Setting Up and Using a GLDisplayListWidget".

To get a window that resizes appropriately, you should insert a Grid Layout object in the centralWidget of the main window, place your interface widgets in this layout. After you have done this, highlight the centralWidget object, go to the Forms menu item, and select "Layout in a Grid". This latter step will cause the Grid Layout object to expand when the surrounding window expands.

If your interface elements expand to the full size of the window when added to the layout, and you don't want this to occur, then you need to set their properties so they have a fixed size.


What You Should Turn In

Hardcopy to be turned in

In an Assign8 subdirectory of your submit directory, place