git-svn-id: svn://db.shs.com.ru/libs@94 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2016-06-07 11:11:14 +00:00
parent e338dd991d
commit 51ebffa2af
7 changed files with 513 additions and 26 deletions

View File

@@ -45,7 +45,8 @@ bool XCheck::eventFilter(QObject * o, QEvent * e) {
KX_Pult::KX_Pult(): QMainWindow(), config_("kx_pult.conf"), name_("x"), config(piqt(config_), QIODevice::ReadWrite), coeffs(config_, "k", true) {
KX_Pult::KX_Pult(): QMainWindow(), config_("kx_pult.conf"), name_x("x"), name_c("c"),
config(piqt(config_), QIODevice::ReadWrite), coeffs(config_, "k", true) {
//cout << sizeof(coeffsK.k_protocol->to_k) << endl;
ui = new Ui::KX_Pult();
ui->setupUi(this);
@@ -53,8 +54,12 @@ KX_Pult::KX_Pult(): QMainWindow(), config_("kx_pult.conf"), name_("x"), config(p
ui->configWidget->expandAll();
ui->list->viewport()->installEventFilter(this);
ui->treeK->viewport()->installEventFilter(this);
ui->scrollArea->setAutoFillBackground(false);
ui->scrollAreaWidgetContents->setAutoFillBackground(false);
ui->widget->setAutoFillBackground(false);
log_menu.addAction(ui->actionClear);
prot_x = 0;
prot_c = 0;
show_x = config.getValue("show_x", true);
if (!show_x)
ui->tabWidget->removeTab(1);
@@ -121,6 +126,7 @@ KX_Pult::KX_Pult(): QMainWindow(), config_("kx_pult.conf"), name_("x"), config(p
connect(ui->lineKSearch, SIGNAL(textChanged(QString)), this, SLOT(filterTree()));
session.load();
updateKDesc();
updateCDesc();
timer_diag.start(40);
timer_update = startTimer(25);
}
@@ -133,11 +139,13 @@ KX_Pult::~KX_Pult() {
void KX_Pult::loading(QPIConfig & conf) {
kdesc_file = conf.getValue("kdesc_file").stringValue();
cdesc_file = conf.getValue("cdesc_file").stringValue();
}
void KX_Pult::saving(QPIConfig & conf) {
conf.setValue("kdesc_file", kdesc_file);
conf.setValue("cdesc_file", cdesc_file);
}
@@ -403,7 +411,7 @@ void KX_Pult::on_buttonResize_clicked() {
}
void KX_Pult::on_buttonSetDesc_clicked() {
void KX_Pult::on_buttonSetKDesc_clicked() {
QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with K description"), kdesc_file, "C/C++ header files(*.h *.hpp);;All files(*)");
if (ret.isEmpty()) return;
kdesc_file = QDir::current().relativeFilePath(ret);
@@ -411,6 +419,14 @@ void KX_Pult::on_buttonSetDesc_clicked() {
}
void KX_Pult::on_buttonSetCDesc_clicked() {
QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with C description"), cdesc_file, "C/C++ header files(*.h *.hpp);;All files(*)");
if (ret.isEmpty()) return;
cdesc_file = QDir::current().relativeFilePath(ret);
updateCDesc();
}
void KX_Pult::on_spinSize_valueChanged(int) {
ui->spinSize->setStyleSheet("");
}
@@ -462,7 +478,6 @@ void KX_Pult::updateGraph() {
void KX_Pult::updateDiag() {
ui->labelKReceiver->setText(piqt(coeffs.k_protocol->receiverDeviceName() + " - " + coeffs.k_protocol->receiverDeviceState()));
ui->labelKSender->setText(piqt(coeffs.k_protocol->senderDeviceName()));
ui->spinKSended->setValue(coeffs.k_protocol->sendCount());
@@ -482,23 +497,32 @@ void KX_Pult::updateDiag() {
ui->labelXType->setText("0x" + QString::number(prot_x->from_x.type, 16).toUpper().rightJustified(2, '0'));
ui->labelXAddrPult->setText("0x" + QString::number(prot_x->from_x.addr_to, 16).toUpper().rightJustified(2, '0'));
ui->labelXAddr->setText("0x" + QString::number(prot_x->to_x.addr_to, 16).toUpper().rightJustified(2, '0'));
ui->labelCReceiver->setText(piqt(prot_c->receiverDeviceName() + " - " + prot_c->receiverDeviceState()));
ui->labelCSender->setText(piqt(prot_c->senderDeviceName()));
ui->spinCSended->setValue(prot_c->sendCount());
ui->spinCReceived->setValue(prot_c->receiveCount());
ui->spinCWrong->setValue(prot_c->wrongCount());
ui->spinCMissed->setValue(prot_c->missedCount());
ui->labelCType->setText("0x" + QString::number(prot_c->from_c.type, 16).toUpper().rightJustified(2, '0'));
ui->labelCAddrPult->setText("0x" + QString::number(prot_c->from_c.addr_to, 16).toUpper().rightJustified(2, '0'));
ui->labelCAddr->setText("0x" + QString::number(prot_c->to_c.addr_to, 16).toUpper().rightJustified(2, '0'));
}
void KX_Pult::updateKDesc(bool ask_move) {
kdesc.clear();
QFile f(kdesc_file);
int KX_Pult::parseHeader(const QString & file, QMap<int, KX_Pult::KDesc> & map) {
map.clear();
QFile f(file);
if (!f.open(QIODevice::ReadOnly)) {
updateTree();
addToList(trUtf8("Update descriptions from \"%1\": error").arg(kdesc_file), Qt::darkRed);
return;
addToList(trUtf8("Update descriptions from \"%1\": error").arg(file), Qt::darkRed);
return 0;
}
addToList(trUtf8("Update descriptions from \"%1\"").arg(kdesc_file), Qt::darkMagenta);
addToList(trUtf8("Update descriptions from \"%1\"").arg(file), Qt::darkMagenta);
QTextStream s(&f);
int cind = -1;
bool found = false;
//qDebug() << "\nparse" << kdesc_file;
//qDebug() << "\nparse" << file;
while (!s.atEnd()) {
QString line = s.readLine().trimmed(), num, name, type, comment;
int i = line.indexOf("//");
@@ -532,10 +556,16 @@ void KX_Pult::updateKDesc(bool ask_move) {
kd.name = name;
kd.type = type;
kd.comment = comment;
kdesc[kd.index] = kd;
map[kd.index] = kd;
//qDebug() << name << cind << type << comment;
}
cind++;
return cind;
}
void KX_Pult::updateKDesc(bool ask_move) {
int cind = parseHeader(kdesc_file, kdesc);
if (K.size_s() < cind) {
ui->spinSize->setValue(cind);
ui->spinSize->setStyleSheet("background-color: rgb(220, 220, 255);");
@@ -547,6 +577,12 @@ void KX_Pult::updateKDesc(bool ask_move) {
}
void KX_Pult::updateCDesc() {
parseHeader(cdesc_file, cdesc);
updateCommands();
}
bool stringComp(const QString & s1, const QString & s2) {
if (s1.size() != s2.size())
return s1.size() > s2.size();
@@ -608,6 +644,25 @@ void KX_Pult::updateTree(bool move) {
}
void KX_Pult::updateCommands() {
while (ui->layoutCommands->count() > 0)
delete ui->layoutCommands->itemAt(0)->widget();
QMapIterator<int, KDesc> it(cdesc);
while (it.hasNext()) {
it.next();
KDesc kd = it.value();
QPushButton * b = new QPushButton();
QString text = kd.name;
if (!kd.comment.isEmpty())
text += QString("\n(%1)").arg(kd.comment);
b->setText(text);
b->setProperty("_command", kd.index);
connect(b, SIGNAL(clicked()), this, SLOT(commandClicked()));
ui->layoutCommands->addWidget(b);
}
}
void KX_Pult::filterTree() {
bool he = ui->checkKHideEmpty->isChecked();
bool hn = ui->checkKHideNormal->isChecked();
@@ -763,7 +818,12 @@ void KX_Pult::renew(bool write) {
prot_x->stop();
delete prot_x;
}
prot_x = new __KX_Protocol_X(config_, name_);
if (prot_c != 0) {
prot_c->stop();
delete prot_c;
}
prot_x = new __KX_Protocol_X(config_, name_x);
prot_c = new __KX_Protocol_C(config_, name_c);
ui->graphic->setAutoXIncrement(prot_x->expectedFrequency() > 0. ? 1. / prot_x->expectedFrequency() : 1.);
coeffs.renew();
CONNECT1(void, bool, prot_x, received, this, received);
@@ -778,3 +838,10 @@ void KX_Pult::toggledX(int index, bool on) {
void KX_Pult::changedX(int index, int num) {
prot_x->to_x.x_num[index] = num;
}
void KX_Pult::commandClicked() {
QPushButton * b = qobject_cast<QPushButton*>(sender());
if (!b) return;
prot_c->sendCommand(b->property("_command").toInt());
}