1
git-svn-id: svn://db.shs.com.ru/libs@1 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
357
piqt_tools/mainwindow.cpp
Normal file
357
piqt_tools/mainwindow.cpp
Normal file
@@ -0,0 +1,357 @@
|
||||
#include "mainwindow.h"
|
||||
#include "pifile.h"
|
||||
#include "pitime.h"
|
||||
#include "pidir.h"
|
||||
#include "ccm.h"
|
||||
#include <QClipboard>
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget * parent): QMainWindow(parent) {
|
||||
SLOT(f(1,2,3));
|
||||
SIGNAL((1,2,3));
|
||||
setupUi(this);
|
||||
treeProperties->header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
treeChannels->header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
treeDump->header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
PICodeInfo::EnumInfo * ei = PICodeInfo::enumsInfo->value("PIIODevice::DeviceMode");
|
||||
if (ei) {
|
||||
labelDevice->setText(PI2QString(ei->name) + ":");
|
||||
piForeachC (PICodeInfo::EnumeratorInfo & e, ei->members)
|
||||
comboDevice->addItem(PI2QString(e.name + " (" + PIString::fromNumber(e.value) + ")"), QVariant::fromValue<int>(e.value));
|
||||
}
|
||||
ei = PICodeInfo::enumsInfo->value("PIPacketExtractor::SplitMode");
|
||||
if (ei) {
|
||||
labelSplit->setText(PI2QString(ei->name) + ":");
|
||||
piForeachC (PICodeInfo::EnumeratorInfo & e, ei->members)
|
||||
comboSplit->addItem(PI2QString(e.name + " (" + PIString::fromNumber(e.value) + ")"), QVariant::fromValue<int>(e.value));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void MainWindow::changeEvent(QEvent * e) {
|
||||
QMainWindow::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::updateTree() {
|
||||
QList<QTreeWidgetItem*> sel(treeConnections->findItems("", Qt::MatchContains | Qt::MatchRecursive));
|
||||
QStringList sell;
|
||||
foreach (QTreeWidgetItem * i, sel)
|
||||
if (i->isSelected()) sell << i->text(0);
|
||||
treeConnections->clear();
|
||||
PIVector<PIConnection * > conns = PIConnection::allConnections();
|
||||
piForeachC (PIConnection * c, conns) {
|
||||
QTreeWidgetItem * ti = new QTreeWidgetItem();
|
||||
ti->setText(0, PI2QString(c->name()));
|
||||
ti->setData(0, Qt::UserRole, 1);
|
||||
ti->setData(0, Qt::UserRole + 1, quintptr(c));
|
||||
PIVector<PIIODevice * > bdl(c->boundedDevices());
|
||||
piForeachC (PIIODevice * d, bdl) {
|
||||
QTreeWidgetItem * pi = new QTreeWidgetItem(ti);
|
||||
pi->setData(0, Qt::UserRole, 2);
|
||||
pi->setData(0, Qt::UserRole + 1, quintptr(d));
|
||||
pi->setText(0, "[Device] " + PI2QString(d->property("__fullPath__").toString()));
|
||||
}
|
||||
PIStringList pel(c->filterNames());
|
||||
piForeachC (PIString & pe, pel) {
|
||||
QTreeWidgetItem * pi = new QTreeWidgetItem(ti);
|
||||
pi->setData(0, Qt::UserRole, 3);
|
||||
pi->setData(0, Qt::UserRole + 1, PI2QString(pe));
|
||||
pi->setText(0, "[Filter] " + PI2QString(pe + " (" +
|
||||
PICodeInfo::enumsInfo->value("PIPacketExtractor::SplitMode")->memberName(c->filter(pe)->splitMode()) + ")"));
|
||||
PIVector<PIIODevice * > pebdl(c->filterBoundedDevices(pe));
|
||||
piForeachC (PIIODevice * d, pebdl) {
|
||||
QTreeWidgetItem * pdi = new QTreeWidgetItem(pi);
|
||||
pdi->setData(0, Qt::UserRole, 4);
|
||||
pdi->setData(0, Qt::UserRole + 1, quintptr(d));
|
||||
if (PIString(d->className()) == "PIPacketExtractor")
|
||||
pdi->setText(0, "[Filter] " + PI2QString(d->name()));
|
||||
else
|
||||
pdi->setText(0, "[Device] " + PI2QString(d->property("__fullPath__").toString()));
|
||||
}
|
||||
}
|
||||
treeConnections->addTopLevelItem(ti);
|
||||
}
|
||||
sel = treeConnections->findItems("", Qt::MatchContains | Qt::MatchRecursive);
|
||||
foreach (QTreeWidgetItem * i, sel)
|
||||
if (sell.contains(i->text(0))) {
|
||||
i->setSelected(sell.contains(i->text(0)));
|
||||
treeConnections->setCurrentItem(i);
|
||||
}
|
||||
treeConnections->expandAll();
|
||||
|
||||
treeDevices->clear();
|
||||
PIVector<PIIODevice * > devs(PIConnection::allDevices());
|
||||
piForeachC (PIIODevice * i, devs) {
|
||||
PIString ms;
|
||||
switch (i->mode()) {
|
||||
case PIIODevice::ReadOnly: ms = "Ro"; break;
|
||||
case PIIODevice::WriteOnly: ms = "Wo"; break;
|
||||
case PIIODevice::ReadWrite: ms = "RW"; break;
|
||||
}
|
||||
treeDevices->addTopLevelItem(new QTreeWidgetItem(QStringList(PI2QString(PIString(i->className()) + " (" + ms + "): " + i->path()))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::updateProperties(PIObject * o) {
|
||||
labelObject->clear();
|
||||
if (o == 0) return;
|
||||
labelObject->setText(PI2QString(PIString(o->className()) + " \"" + o->name() + "\""));
|
||||
PIMap<PIString, PIVariant> props(o->properties());
|
||||
typedef PIMap<PIString, PIVariant>::value_type PPair;
|
||||
piForeachC (PPair p, props)
|
||||
treeProperties->addTopLevelItem(new QTreeWidgetItem(QStringList()
|
||||
<< PI2QString(p.first)
|
||||
<< PI2QString(PIVariant::typeName(p.second.type()))
|
||||
<< PI2QString(p.second.toString()) ));
|
||||
}
|
||||
|
||||
|
||||
PIConnection * MainWindow::currentConnection() {
|
||||
QTreeWidgetItem * ci = treeConnections->currentItem();
|
||||
if (ci == 0) return 0;
|
||||
while (ci->parent() != 0)
|
||||
ci = ci->parent();
|
||||
return (PIConnection * )(ci->data(0, Qt::UserRole + 1).toULongLong());
|
||||
}
|
||||
|
||||
|
||||
PIPacketExtractor * MainWindow::currentPacketExt() {
|
||||
QTreeWidgetItem * ci = treeConnections->currentItem();
|
||||
if (ci == 0) return 0;
|
||||
if (ci->data(0, Qt::UserRole).toInt() < 3) return 0;
|
||||
if (ci->data(0, Qt::UserRole).toInt() == 4) ci = ci->parent();
|
||||
return currentConnection()->filter(Q2PIString(ci->data(0, Qt::UserRole + 1).toString()));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_buttonNewConnection_clicked() {
|
||||
(new PIConnection())->setName(Q2PIString(lineNew->text()));
|
||||
updateTree();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_buttonAddDevice_clicked() {
|
||||
PIConnection * c = currentConnection();
|
||||
if (!c) return;
|
||||
PIPacketExtractor * pe = currentPacketExt();
|
||||
PIString dn(Q2PIString(lineDevice->text()));
|
||||
if (pe) {
|
||||
c->addFilter(pe->name(), dn);
|
||||
} else
|
||||
c->addDevice(dn, (PIIODevice::DeviceMode)(comboDevice->itemData(comboDevice->currentIndex()).toInt()));
|
||||
updateTree();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_buttonAddPacketExt_clicked() {
|
||||
PIConnection * c = currentConnection();
|
||||
if (!c) return;
|
||||
c->addFilter(Q2PIString(linePacketExt->text()), Q2PIString(lineDevice->text()),
|
||||
(PIPacketExtractor::SplitMode)(comboSplit->itemData(comboSplit->currentIndex()).toInt()));
|
||||
updateTree();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_buttonRemove_clicked() {
|
||||
QTreeWidgetItem * ci = treeConnections->currentItem();
|
||||
if (ci == 0) return;
|
||||
PIIODevice * d(0);
|
||||
switch (ci->data(0, Qt::UserRole).toInt()) {
|
||||
case 1:
|
||||
delete currentConnection();
|
||||
break;
|
||||
case 2:
|
||||
d = (PIIODevice*)(ci->data(0, Qt::UserRole + 1).toULongLong());
|
||||
currentConnection()->removeDevice(d->property("__fullPath__").toString());
|
||||
break;
|
||||
case 3:
|
||||
currentConnection()->removeFilter(Q2PIString(ci->data(0, Qt::UserRole + 1).toString()));
|
||||
break;
|
||||
case 4:
|
||||
d = (PIIODevice*)(ci->data(0, Qt::UserRole + 1).toULongLong());
|
||||
currentConnection()->removeFilter(Q2PIString(ci->parent()->data(0, Qt::UserRole + 1).toString()),
|
||||
d->property("__fullPath__").toString());
|
||||
break;
|
||||
}
|
||||
updateTree();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_buttonAddFromConfig_clicked() {
|
||||
QFile f("c.conf");
|
||||
f.open(QIODevice::ReadWrite);
|
||||
f.resize(0);
|
||||
f.write((textEdit->toPlainText() + "\n").toUtf8());
|
||||
f.close();
|
||||
new PIConnection("c.conf", Q2PIString(lineNew_2->text()));
|
||||
updateTree();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_buttonToConfig_clicked() {
|
||||
PIConnection * c = currentConnection();
|
||||
if (!c) return;
|
||||
textEdit_2->setPlainText(PI2QString(c->makeConfig()));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_buttonAddChannel_clicked() {
|
||||
PIConnection * c = currentConnection();
|
||||
if (!c) return;
|
||||
c->addChannel(Q2PIString(lineChannel0->text()), (Q2PIString(lineChannel1->text())));
|
||||
updateTree();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_treeConnections_currentItemChanged(QTreeWidgetItem * ci, QTreeWidgetItem *) {
|
||||
treeProperties->clear();
|
||||
treeChannels->clear();
|
||||
if (ci == 0) return;
|
||||
switch (ci->data(0, Qt::UserRole).toInt()) {
|
||||
case 1:
|
||||
updateProperties(currentConnection());
|
||||
break;
|
||||
case 3:
|
||||
updateProperties(currentConnection()->filter(Q2PIString(ci->data(0, Qt::UserRole + 1).toString())));
|
||||
break;
|
||||
case 2:
|
||||
case 4:
|
||||
updateProperties((PIIODevice*)(ci->data(0, Qt::UserRole + 1).toULongLong()));
|
||||
break;
|
||||
}
|
||||
PIConnection * c = currentConnection();
|
||||
if (c == 0) return;
|
||||
typedef PIPair<PIString, PIString> SSPair;
|
||||
PIVector<SSPair> chns(c->channels());
|
||||
piForeachC (SSPair & i, chns)
|
||||
treeChannels->addTopLevelItem(new QTreeWidgetItem(QStringList() << PI2QString(i.first) << " -> " << PI2QString(i.second)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MainWindow::buildDump() {
|
||||
treeDump->clear();
|
||||
if (!dump.contains('{')) return;
|
||||
PIString app = dump.takeWord();
|
||||
if (app != "application") return;
|
||||
dump.takeLine();
|
||||
QTreeWidgetItem * ti;
|
||||
while (!dump.isEmpty()) {
|
||||
PIString line = dump.takeLine();
|
||||
if (line.contains('{')) {
|
||||
ti = new QTreeWidgetItem();
|
||||
dump.prepend(line + "\n");
|
||||
buildDumpSection(ti, dump);
|
||||
treeDump->addTopLevelItem(ti);
|
||||
continue;
|
||||
}
|
||||
int colon = line.find(":");
|
||||
if (colon < 0) continue;
|
||||
PIString name = line.takeLeft(colon).trim();
|
||||
PIString value = line.cutLeft(1).trim();
|
||||
if (value.startsWith("\"")) value.cutLeft(1);
|
||||
if (value.endsWith("\"")) value.cutRight(1);
|
||||
ti = new QTreeWidgetItem(QStringList() << PI2QString(name) << PI2QString(value));
|
||||
treeDump->addTopLevelItem(ti);
|
||||
}
|
||||
on_checkDumpHideService_toggled(checkDumpHideService->isChecked());
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::buildDumpSection(QTreeWidgetItem * pi, PIString & str) {
|
||||
PIString section = str.takeLeft(str.find("{")).trim();
|
||||
PIString value;
|
||||
if (section.contains('(')) {
|
||||
value = section;
|
||||
section = value.takeLeft(value.find('('));
|
||||
value = value.takeRange("(", ")");
|
||||
}
|
||||
pi->setText(0, piqt(section));
|
||||
pi->setText(1, piqt(value));
|
||||
//if (section == "PIObjects")
|
||||
PIString range = str.takeRange("{", "}");
|
||||
QTreeWidgetItem * ti;
|
||||
PIString fs;
|
||||
if (section == "PIObjects" || section == "properties") fs = ":";
|
||||
if (section == "methodsEH") fs = " ";
|
||||
if (section == "connections") fs = "->";
|
||||
while (!range.isEmpty()) {
|
||||
PIString line = range.takeLine().trim();
|
||||
if (line.contains('{')) {
|
||||
ti = new QTreeWidgetItem(pi);
|
||||
range.prepend(line + "\n");
|
||||
buildDumpSection(ti, range);
|
||||
//treeDump->addTopLevelItem(ti);
|
||||
continue;
|
||||
}
|
||||
if (line.left(line.find(":")).trim() == "count") {
|
||||
pi->setText(1, "[" + PI2QString(line.right(line.length() - line.find(":") - 1).trim()) + "]");
|
||||
continue;
|
||||
}
|
||||
int colon = line.find(fs);
|
||||
if (colon < 0) continue;
|
||||
PIString name = line.takeLeft(colon).trim();
|
||||
PIString value = line.cutLeft(fs.size_s()).trim();
|
||||
if (value.startsWith("\"")) value.cutLeft(1);
|
||||
if (value.endsWith("\"")) value.cutRight(1);
|
||||
if (name.endsWith(":")) name.cutRight(1);
|
||||
if (name.isEmpty() && value.isEmpty()) continue;
|
||||
ti = new QTreeWidgetItem(pi, QStringList() << PI2QString(name) << PI2QString(value));
|
||||
//treeDump->addTopLevelItem(ti);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_buttonDumpMake_clicked() {
|
||||
if (radioDumpCurrent->isChecked()) {
|
||||
PICout::setBufferActive(true, true);
|
||||
dumpApplication();
|
||||
dump = PICout::buffer();
|
||||
PICout::setBufferActive(false);
|
||||
} else {
|
||||
int pid = lineDumpCustom->text().toInt();
|
||||
if (pid == 0) return;
|
||||
if (system(QString("kill -USR1 %1").arg(pid).toLatin1().constData()) < 0) return;
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
PIString dp = PIDir::home().path() + "/_PIP_DUMP_" + PIString::fromNumber(pid);
|
||||
PITimeMeasurer tm;
|
||||
while (tm.elapsed_s() < 5. && !PIFile::isExists(dp)) {
|
||||
piMSleep(10);
|
||||
}
|
||||
//piSleep(2.);
|
||||
PIFile f(dp, PIIODevice::ReadOnly);
|
||||
QApplication::restoreOverrideCursor();
|
||||
if (!f.isOpened()) return;
|
||||
dump = PIString(f.readAll());
|
||||
f.remove();
|
||||
}
|
||||
buildDump();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_buttonDumpClipboard_clicked() {
|
||||
dump = Q2PIString(QApplication::clipboard()->text());
|
||||
buildDump();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_checkDumpHideService_toggled(bool on) {
|
||||
QList<QTreeWidgetItem * > il = treeDump->findItems("", Qt::MatchContains | Qt::MatchRecursive);
|
||||
foreach (QTreeWidgetItem * i, il) {
|
||||
if (on) {
|
||||
if (i->text(0).startsWith("class"))
|
||||
i->setHidden(i->text(1).contains("__S__"));
|
||||
} else
|
||||
i->setHidden(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user