File: VisibleSectionsModel.cpp

package info (click to toggle)
tulip 3.7.0dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 39,428 kB
  • sloc: cpp: 231,403; php: 11,023; python: 1,128; sh: 671; yacc: 522; makefile: 315; xml: 63; lex: 55
file content (64 lines) | stat: -rwxr-xr-x 2,161 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "VisibleSectionsModel.h"
#include "GraphTableWidget.h"
#include <QtGui/QHeaderView>
#include "TulipTableWidgetColumnSelectionModel.h"
#include <tulip/TlpQtTools.h>

using namespace std;
VisibleSectionsModel::VisibleSectionsModel(QWidget* parent): QComboBox(parent),_columnModel(NULL) {

}

void VisibleSectionsModel::setColumnModel(TulipTableWidgetColumnSelectionModel* columModel) {
  _columnModel = columModel;
  connect(_columnModel,SIGNAL(dataChanged(QModelIndex,QModelIndex)),this,SLOT(propertiesDataChanged(QModelIndex,QModelIndex)));
  connect(_columnModel,SIGNAL(rowsInserted(QModelIndex,int,int)),this,SLOT(propertiesInserted(QModelIndex,int,int)));
  connect(_columnModel,SIGNAL(rowsRemoved(QModelIndex,int,int)),this,SLOT(propertiesRemoved(QModelIndex,int,int)));
  connect(_columnModel,SIGNAL(rowsMoved(QModelIndex , int , int , QModelIndex, int)),this,SLOT(propertiesMoved(QModelIndex,int,int,QModelIndex,int)));
  connect(_columnModel,SIGNAL(modelReset()),this,SLOT(propertiesReset()));
  initModel();

}

void VisibleSectionsModel::initModel(int selectedColumnIndex) {
  int index=0;
  clear();
  addItem(tr("All columns"),QVariant(-1));

  for(int i = 0 ; i < _columnModel->rowCount() ; ++i) {
    if(_columnModel->isColumnVisible(i)) {
      tlp::PropertyInterface* property = _columnModel->propertyForIndex(_columnModel->index(i));

      if(property != NULL) {
        addItem(tlp::tlpStringToQString(property->getName()),QVariant(i));

        //If the last added index match with the column to select
        if(i == selectedColumnIndex) {
          index = count()-1;
        }
      }
    }
  }

  setCurrentIndex(index);
}

void VisibleSectionsModel::propertiesInserted ( const QModelIndex &, int , int ) {
  initModel();
}

void VisibleSectionsModel::propertiesMoved ( const QModelIndex & , int , int , const QModelIndex & , int ) {
  initModel();
}

void VisibleSectionsModel::propertiesRemoved ( const QModelIndex & , int , int ) {
  initModel();
}

void VisibleSectionsModel::propertiesDataChanged(const QModelIndex &, const QModelIndex &) {
  initModel();
}

void VisibleSectionsModel::propertiesReset() {
  initModel();
}