3. The View class

If you need to create a new view, you have to create a new class that implements the View interface

View interface (in library/tulip-qt/include/tulip/View.h) can be split into 3 parts

An example of view plugin

This is an example of a simple view. This view displays the number of nodes/edges on the graph

This example provides just a view without interactors

.h file

class TutoView : public tlp::View {
  Q_OBJECT

public:

  QWidget *construct(QWidget *parent) {
    //Construct Qt part of the view
    widget= new QWidget(parent);
    widget->resize(230, 60);
    QGridLayout *gridLayout = new QGridLayout(widget);
    gridLayout->setSpacing(0);
    gridLayout->setMargin(0);

    nodeNumber = new QLineEdit(widget);
    nodeNumber->setReadOnly(true);
    gridLayout->addWidget(nodeNumber, 0, 0, 1, 1);

    edgeNumber = new QLineEdit(widget);
    edgeNumber->setReadOnly(true);
    gridLayout->addWidget(edgeNumber, 1, 0, 1, 1);

    return widget;
  }

  //In this example we don't read DataSet parameters because this view doesn't need to be saved
  void setData(tlp::Graph *graph,tlp::DataSet dataSet) {
    this->graph=graph;
    draw();
  }
  void getData(tlp::Graph **graph,tlp::DataSet *dataSet) {
    *graph=this->graph;
  }
  tlp::Graph *getGraph() {return graph;}

  //In this example we have no interactor so we return empty list
  std::list<QAction *> *getInteractorsActionList() {
    return new std::list<QAction*>;
  }
  void installInteractor(QAction*) {}

protected :

  tlp::Graph *graph;
  QWidget *widget;
  QLineEdit *nodeNumber;
  QLineEdit *edgeNumber;

public slots :
  
  //Display function, we get back nodes/edges number
  void draw() {
    nodeNumber->setText(QString("Number of nodes : ")+QString::number(graph->numberOfNodes()));
    edgeNumber->setText(QString("Number of edges : ")+QString::number(graph->numberOfEdges()));
  }
  //refresh and init is automatically done by Qt
  void refresh() {}
  void init() {}
  void setGraph(tlp::Graph *graph) {this->graph=graph;}

};
      

.cpp file

// This line is needed to register the plugin in Tulip
// Warning : last parameter(42) is the id of the plugin, it must be unique
VIEWPLUGIN(TutoView, "TutorielView", "Tulip Team", "21/11/2008", "Tutoriel view", "1.0", 42);