2 * Copyright (c) 2007, Aconex. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 #include "searchdialog.h"
15 #include <QMessageBox>
18 SearchDialog::SearchDialog(QWidget
* parent
) : QDialog(parent
)
24 void SearchDialog::languageChange()
29 void SearchDialog::reset(QTreeWidget
*pmns
)
32 buttonOk
->setEnabled(false);
33 if (matchList
->count() > 0)
34 buttonAll
->setEnabled(true);
36 buttonAll
->setEnabled(false);
41 void SearchDialog::clear()
43 this->hostPattern
->clear();
44 this->metricPattern
->clear();
45 this->instancePattern
->clear();
46 this->resultStatus
->setText("");
49 buttonSearch
->setEnabled(false);
50 buttonOk
->setEnabled(false);
51 buttonAll
->setEnabled(false);
54 void SearchDialog::changed()
56 bool hostEnabled
= (hostPattern
->text() != QString::null
);
57 bool metricEnabled
= (metricPattern
->text() != QString::null
);
58 bool instanceEnabled
= (instancePattern
->text() != QString::null
);
59 buttonSearch
->setEnabled(hostEnabled
|| metricEnabled
|| instanceEnabled
);
62 void SearchDialog::selectall()
64 matchList
->selectAll();
67 void SearchDialog::listchanged()
69 QList
<QListWidgetItem
*> check
= matchList
->selectedItems();
70 if (check
.size() == 0) {
71 buttonOk
->setEnabled(false);
74 buttonOk
->setEnabled(true);
78 void SearchDialog::search()
81 QTreeWidgetItemIterator
iterator(my
.pmns
, QTreeWidgetItemIterator::All
);
90 console
->post(PmChart::DebugUi
,
91 "SearchDialog::search host=\"%s\" metric=\"%s\" instance=\"%s\"",
92 (const char *)hostPattern
->text().toLatin1(),
93 (const char *)metricPattern
->text().toLatin1(),
94 (const char *)instancePattern
->text().toLatin1());
96 if (hostPattern
->text() == QString::null
&&
97 metricPattern
->text() == QString::null
&&
98 instancePattern
->text() == QString::null
) {
99 // got here via pressing Enter from one of the pattern input fields,
100 // and all the fields are empty ... do nothing
104 if (hostPattern
->text() != QString::null
)
105 h_rx
.setPattern(hostPattern
->text());
107 if (metricPattern
->text() != QString::null
)
108 m_rx
.setPattern(metricPattern
->text());
110 if (instancePattern
->text() != QString::null
)
111 i_rx
.setPattern(instancePattern
->text());
116 for (; (*iterator
); ++iterator
) {
117 NameSpace
*item
= (NameSpace
*)(*iterator
);
118 if (item
->isRoot()) {
120 if (hostPattern
->text() != QString::null
)
121 h_match
= h_rx
.indexIn(item
->sourceName());
125 console
->post(PmChart::DebugUi
, "SearchDialog::search "
126 "host=\"%s\" h_match=%d",
127 (const char *)item
->sourceName().toLatin1(), h_match
);
129 item
->setExpanded(true, false);
132 else if (h_match
>= 0 && item
->isMetric()) {
135 if (metricPattern
->text() != QString::null
)
136 m_match
= m_rx
.indexIn(item
->metricName());
140 if (item
->isLeaf() &&
141 instancePattern
->text() == QString::null
) {
142 QString fqn
= item
->sourceName().append(":");
143 fqn
.append(item
->metricName());
144 matchList
->addItem(fqn
);
145 my
.pmnsList
.append(item
);
148 console
->post(PmChart::DebugUi
, "SearchDialog::search "
149 "host=%s h_match=%d metric=%s m_match=%d",
150 (const char *)item
->sourceName().toLatin1(), h_match
,
151 (const char *)item
->metricName().toLatin1(), m_match
);
153 if (item
->isLeaf() == false) {
154 // has instance domain
155 item
->setExpanded(true, false);
160 else if (h_match
>= 0 && m_match
>= 0 && item
->isInst()) {
161 // matched last metric, now related instance name ...
163 if (instancePattern
->text() != QString::null
)
164 i_match
= i_rx
.indexIn(item
->metricInstance());
168 QString fqn
= item
->sourceName().append(":");
169 fqn
.append(item
->metricName());
170 fqn
.append("[").append(item
->metricInstance()).append("]");
171 matchList
->addItem(fqn
);
172 my
.pmnsList
.append(item
);
174 console
->post(PmChart::DebugUi
, "SearchDialog::search "
175 "host=%s h_match=%d metric=%s m_match=%d inst=%s i_match=%d",
176 (const char *)item
->sourceName().toLatin1(), h_match
,
177 (const char *)item
->metricName().toLatin1(), m_match
,
178 (const char *)item
->metricInstance().toLatin1(), i_match
);
181 else if (item
->isNonLeaf()) {
182 item
->setExpanded(true, false);
189 if (matchList
->count() > 0) {
190 buttonAll
->setEnabled(true);
193 QTextStream(&res
) << "Matched " << matchList
->count() << " of " << count
<< " possibilities";
194 this->resultStatus
->setText(res
);
197 void SearchDialog::ok()
199 QList
<QListWidgetItem
*> selected
= matchList
->selectedItems();
204 for (i
= 0; i
< selected
.size(); i
++) {
205 row
= matchList
->row(selected
[i
]);
207 fprintf(stderr
, "[%d] %s:%s[%s]\n",
208 row
, (const char *)my
.pmnsList
[row
]->sourceName().toLatin1(),
209 (const char *)my
.pmnsList
[row
]->metricName().toLatin1(),
210 (const char *)my
.pmnsList
[row
]->metricInstance().toLatin1());
212 my
.pmnsList
[row
]->setSelected(true);
213 parent
= (NameSpace
*)my
.pmnsList
[row
]->parent();
214 while (parent
->isRoot() == false) {
216 fprintf(stderr
, "SearchDialog::ok expand: %s\n",
217 (const char *)parent
->metricName().toLatin1());
219 parent
->QTreeWidgetItem::setExpanded(true);
220 parent
= (NameSpace
*)parent
->parent();