SampleEditor

From FarsightWiki
Revision as of 21:38, 10 July 2009 by Vargun (Talk | contribs)
Jump to: navigation, search

The SampleEditor program (checkout from the FARSIGHT repository) is implemented by using the QT's model/view architecture. This web page is prepared to help one to implement their code by using this model. (Please visit hese pages for additional information:

 * ALISA shows how we implement  QT's Model/View Architecture in FARSIGHT, specifically in the NucleusEditor module. 
 * EVS presents Edit-based Validation and Model-View Programming)

Contents

Why do we need to use this architecture?

In general, there are many applications that follow some of the steps listed below:

  • 1. Read Some Input - Read the data from a file, from the command line, or from the program itself
  • 2. Present the Data Using Different Views - Show it with a table, draw a scatter plott, or display some columns buy using a histogram
  • 3. Edit the Data in the Views - reflect the changes to all the other views, update them properly
  • 4. Compute some features
  • 5. Write/Store the Results - into a file, or to the screen

In Farsight, our modules follow the similar patterns to process the data. In order to implement these steps, many different solutions might be provided. The major problem with this approach is that for every unique solution, the programmer needs to implement their specialized viewers. An alternative and a better solution is to base your application onto the model/view architecture that we have already implemented. The advantage is that your module will be able to view the data with a small amount of extra programming by using the different viewers that are implemented in our libraries.

We show, in the SampleEditor program, how this idea works. For simplicity, we view the data by using only three views. Here are the screen shots of these views from the SampleEditor program:

  • 1. Table View
SETableView.JPG
  • 2. Scatter Plot View
SEPlotView.JPG
  • 3. Histogram View
SEHistoView.JPG

In this architecture, any changes in one of the views will be reflected to the other viewers immidiately.

Steps

Declaration

Here is the main class that we defined for the SampleEditor:

 class SampleEditor : public QMainWindow
 {
   Q_OBJECT;
 public:
   SampleEditor(QWidget * parent = 0, Qt::WindowFlags flags = 0);
 
 //Use this declaration to load your data 
 private slots:
   void loadFile(void);
 signals:    
 private:
   // Setup the GUI 
   void createMenus();
   void createStatusBar();
   QMenu *fileMenu;
   QAction *loadAction;
   // Define the QT model - two models are necessary, one for the data, and the other one for the selections 
   QStandardItemModel *model;
   QItemSelectionModel *selModel;
   // Define the views - We have three views in this case 
   QTableView *table;
   PlotWindow *plot;
   HistoWindow *histo;
  };

Definitions

Personal tools