-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialogobjects.cpp
189 lines (162 loc) · 6.26 KB
/
dialogobjects.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "dialogobjects.h"
#include "ui_dialogobjects.h"
DialogObjects::DialogObjects(QWidget *parent, const std::string& name) :
QDialog(parent),
objectModel(0),
ui(new Ui::DialogObjects)
{
ui->setupUi(this);
QString qname(name.c_str());
QString title("Select ");
title += qname;
ui->labelPrompt->setText(tr(title.toStdString().c_str()));
this->setObjectName(QString(name.c_str()));
restoreSettings();
}
void DialogObjects::initModels(std::string unique, const QStringList &columnList)
{
objectModel = new ObjectListModel(this, unique, columnList);
objectDetailsModel = new ObjectDetailsModel(this);
initConnections();
}
void DialogObjects::setKey(const QString &altKey)
{
if (objectModel)
objectModel->setKey(altKey.toStdString());
}
void DialogObjects::initConnections()
{
proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(objectModel);
proxyModel->setFilterKeyColumn(0);
ui->objectListView->setModel(proxyModel);
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), proxyModel, SLOT(setFilterFixedString(QString)));
ui->objectTableView->setModel(objectDetailsModel);
connect(ui->objectListView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
this, SLOT(selected(QModelIndex)));
connect(objectModel, SIGNAL(objectSelected(qmf::Data)),
objectDetailsModel, SLOT(showObjectDetail(qmf::Data)));
connect(objectDetailsModel, SIGNAL(detailReady()), this, SLOT(resizeDetail()));
}
DialogObjects::~DialogObjects()
{
saveSettings();
delete ui;
if (objectModel)
delete objectModel;
if (objectDetailsModel)
delete objectDetailsModel;
if (proxyModel)
delete proxyModel;
}
// SLOT triggered after the object details have been added
// This will cause the columns in the object details table
// to resize to the longest column contents
void DialogObjects::resizeDetail()
{
// workaround for a QT bug https://bugreports.qt.nokia.com//browse/QTBUG-9352
//ui->objectTableView->setVisible(false);
//ui->objectTableView->resizeColumnsToContents();
//ui->objectTableView->setVisible(true);
}
void DialogObjects::connectionChanged(bool isConnected)
{
objectModel->connectionChanged(isConnected);
objectDetailsModel->connectionChanged(isConnected);
}
// SLOT triggered when user highlights an item in the list
// Translate to a filtered index and show the details
void DialogObjects::selected(const QModelIndex &index)
{
if (index.isValid()) {
QModelIndex filteredIndex = proxyModel->mapToSource(index);
objectModel->selected(filteredIndex);
}
}
// The async request to get the data has completed
// Add the objects to the model
void DialogObjects::gotDataEvent(const qmf::ConsoleEvent& event, bool all)
{
quint32 pcount = event.getDataCount();
for (quint32 idx = 0; idx < pcount; idx++) {
objectModel->addObject(event.getData(idx), event.getCorrelator());
}
// this was the last batch of objects for this timer/event
if (event.isFinal()) {
// if we just updated all objects, remove the old ones
if (all) {
objectModel->refresh(event.getCorrelator());
}
// select 1st item if none are selected
if (!(ui->objectListView->selectionModel()->hasSelection())) {
ui->objectListView->setCurrentIndex(ui->objectListView->model()->index(0, 0));
}
dataRefreshed();
emit finalAdded();
}
}
void DialogObjects::setCurrentRow(const QModelIndex& row)
{
// row is the index for the object-model
// translate this into the row for the listview
QModelIndex prow = proxyModel->mapFromSource(row);
ui->objectListView->setCurrentIndex(prow);
}
void DialogObjects::dataRefreshed()
{
QModelIndex current = ui->objectListView->selectionModel()->currentIndex();
if (current.isValid()) {
QModelIndex filteredIndex = proxyModel->mapToSource(current);
// if the dialogbox is open, we want to show the updated object details
objectModel->selected(filteredIndex);
emit objectRefreshed();
}
// remove any samples that are older than our charting window
objectModel->expireSamples();
}
void DialogObjects::accept()
{
// get the currently selected object in the list
QModelIndex index = ui->objectListView->selectionModel()->currentIndex();
if (index.isValid()) {
QModelIndex filteredIndex = proxyModel->mapToSource(index);
emit setCurrentObject(objectModel->getSelected(filteredIndex), objectName());
}
close();
}
void DialogObjects::saveSettings() {
QSettings settings;
settings.beginGroup(objectName());
settings.setValue("Geometry", saveGeometry());
settings.setValue("splitterSizes", ui->splitter->saveState());
settings.setValue("tableState", ui->objectTableView->horizontalHeader()->saveState());
settings.setValue("tableGeometry", ui->objectTableView->horizontalHeader()->saveGeometry());
settings.endGroup();
}
void DialogObjects::restoreSettings() {
QSettings settings;
settings.beginGroup(this->objectName());
restoreGeometry(settings.value("Geometry").toByteArray());
ui->splitter->restoreState(settings.value("splitterSizes").toByteArray());
ui->objectTableView->horizontalHeader()->restoreState(settings.value("tableState").toByteArray());
ui->objectTableView->horizontalHeader()->restoreGeometry(settings.value("tableGeometry").toByteArray());
settings.endGroup();
}