Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
xdebugtreewidget.cpp
Go to the documentation of this file.
1 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
2 // FGx FlightGear Launcher // xdebugtreewidget.cpp
3 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
4 // (c) 2010-2012
5 // Yves Sablonier, Pete Morgan
6 // Geoff McLane
7 // GNU GPLv2, see main.cpp and shipped licence.txt for further information
8 
9 
10 #include <QVBoxLayout>
11 #include <QTreeView>
12 #include <QModelIndex>
13 #include <QIcon>
14 
15 #include <QTreeView>
16 #include <QHeaderView>
17 #include <QToolBar>
18 
21 
23  QWidget(parent)
24  {
25 
26  mainObject = mob;
27 
28  QVBoxLayout *mainLayout = new QVBoxLayout();
29  mainLayout->setSpacing(0);
30  setLayout(mainLayout);
31 
32  QToolBar *toolbar = new QToolBar();
33  mainLayout->addWidget(toolbar);
34 
35  groupFilter = new QButtonGroup(this);
36  groupFilter->setExclusive(true);
37  QStringList filters;
38  filters << "All" << "Enabled" << "Disabled" << "Filter";
39  connect(groupFilter, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(on_filter_button(QAbstractButton*)) );
40 
41  for(int fidx = 0; fidx < filters.size(); fidx++ )
42  {
43  QToolButton *butt = new QToolButton();
44  butt->setText(filters.at(fidx));
45  butt->setCheckable(true);
46  butt->setChecked(filters.at(fidx) == "All");
47  butt->setProperty("filter", filters.at(fidx));
48  toolbar->addWidget(butt) ;
49  groupFilter->addButton( butt, fidx);
50 
51  }
52  QLineEdit *txtFilter = new QLineEdit();
53  toolbar->addWidget(txtFilter);
54  connect(txtFilter, SIGNAL(textChanged(QString)), this, SLOT(on_filter_text_changed(QString)));
55  // ======================
56  // == Models
58  proxyModel->setSourceModel(mainObject->X);
59  proxyModel->setFilterKeyColumn(XSettingsModel::C_ENABLED);
60 
61 
62 
63  //=============================================================
64  // TEMP DEBUG TREE
65  tree = new QTreeView();
66  tree->setRootIsDecorated(false);
67  mainLayout->addWidget(tree);
68 
69  tree->setModel(proxyModel);
70 
71  tree->setSelectionBehavior(QAbstractItemView::SelectRows);
72  tree->setSortingEnabled(true);
73  tree->sortByColumn(XSettingsModel::C_OPTION, Qt::AscendingOrder);
74  tree->setUniformRowHeights(true);
75  tree->header()->setStretchLastSection(true);
76 
77  tree->setColumnHidden(XSettingsModel::C_LEVEL, true);
78  tree->setColumnHidden(XSettingsModel::C_AREA, true);
79 
80  tree->setColumnWidth(XSettingsModel::C_ENABLED, 40);
81  tree->setColumnWidth(XSettingsModel::C_OPTION, 200);
82  tree->setColumnWidth(XSettingsModel::C_VALUE, 200);
83 
84  connect(mainObject->X, SIGNAL(upx(QString,bool,QString)), this, SLOT(on_select_a_node(QString,bool,QString)));
85 
86  }
87 
88 
89 void XDebugTreeWidget::on_filter_button(QAbstractButton *butt)
90 {
91  QString f = butt->property("filter").toString();
92 
93  proxyModel->setFilterKeyColumn(f == "Filter" ? XSettingsModel::C_OPTION : XSettingsModel::C_ENABLED );
94 
95  if(f == "All"){
96  proxyModel->setFilterRegExp("");
97 
98  }else if(f == "Enabled"){
99  proxyModel->setFilterRegExp("1");
100 
101  }else if(f == "Disabled"){
102  proxyModel->setFilterRegExp("0");
103 
104  }else{
105  proxyModel->setFilterRegExp(txtFilter->text());
106  }
107 }
108 
110 {
111  proxyModel->setFilterRegExp(txt);
112  proxyModel->setFilterKeyColumn(XSettingsModel::C_OPTION );
113  groupFilter->button(3)->setChecked(true); // filter button is third index
114 }
115 
116 void XDebugTreeWidget::on_select_a_node(QString option, bool enabled, QString value)
117 {
118  return; // TODO
119  Q_UNUSED(enabled);
120  Q_UNUSED(value);
121  tree->selectionModel()->setCurrentIndex( proxyModel->mapFromSource(mainObject->X->get_index(option)), QItemSelectionModel::Rows );
122  tree->selectionModel()->select( proxyModel->mapFromSource(mainObject->X->get_index(option)), QItemSelectionModel::Rows );
123  //qDebug() << "select" << option << " " << mainObject->X->get_index(option).row();
124 }
void on_select_a_node(QString option, bool enabled, QString value)
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
void on_filter_button(QAbstractButton *button)
XDebugTreeWidget(MainObject *mob, QWidget *parent=0)
MainObject * mainObject
QSortFilterProxyModel * proxyModel
QLineEdit * txtFilter
XSettingsModel * X
Definition: mainobject.h:86
QButtonGroup * groupFilter
void on_filter_text_changed(QString)
QModelIndex get_index(QString option)