From b874ffb2533dd4f75b9a9a56dc69914394dda2d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Fri, 16 Jun 2017 12:29:33 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@238 a8b55f48-bf90-11e4-a774-851b48703e85 --- cd_utils/cdutils_core.cpp | 8 ++-- cd_utils/cdutils_core.h | 3 +- cd_utils/cdutils_k.cpp | 5 +-- cd_utils/cdutils_k.h | 2 +- cd_utils/cdutils_types.cpp | 84 ++++++++++++++++++++++++++++------- cd_utils/cdutils_types.h | 10 ++++- qcd_utils/pult/form.cpp | 5 ++- qcd_utils/pult/form.h | 5 ++- qcd_utils/qcd_kview.cpp | 4 +- qcd_utils/qcd_kview.h | 2 +- qcd_utils/qcd_modedialog.cpp | 46 +++++++++++++++++++ qcd_utils/qcd_modedialog.h | 31 +++++++++++++ qcd_utils/qcd_modedialog.ui | 85 ++++++++++++++++++++++++++++++++++++ 13 files changed, 259 insertions(+), 31 deletions(-) create mode 100644 qcd_utils/qcd_modedialog.cpp create mode 100644 qcd_utils/qcd_modedialog.h create mode 100644 qcd_utils/qcd_modedialog.ui diff --git a/cd_utils/cdutils_core.cpp b/cd_utils/cdutils_core.cpp index c16cabd..e2e21e6 100644 --- a/cd_utils/cdutils_core.cpp +++ b/cd_utils/cdutils_core.cpp @@ -118,16 +118,16 @@ void CDCore::k_parse(PIIODevice * d) { } -void CDCore::k_update(PIIODevice * d) { +void CDCore::k_update(PIIODevice * d, UpdateModeFlags mode) { CDSection uk = k_; k_parse(d); - bool kn = true; + /*bool kn = true; if (!uk.isEmpty()) if (!uk.isSameStructure(k_)) { piCout << "ask for save names"; K_KeepNamesRequest(&kn); - } - uk.update(k_, kn); + }*/ + uk.update(k_, mode); //piCout << k_.count() << uk.count(); k_ = uk; k_.makePath(); diff --git a/cd_utils/cdutils_core.h b/cd_utils/cdutils_core.h index d407618..87756b4 100644 --- a/cd_utils/cdutils_core.h +++ b/cd_utils/cdutils_core.h @@ -35,14 +35,13 @@ public: EVENT(K_Received) EVENT(K_ReceiveFail) EVENT(K_ChangedGlobal) - EVENT1(K_KeepNamesRequest, bool*, kn) EVENT_HANDLER(void, K_Send); EVENT_HANDLER(void, K_Request); void k_write(PIIODevice * d); void k_read(PIIODevice * d); void k_parse(PIIODevice * d); - void k_update(PIIODevice * d); + void k_update(PIIODevice * d, UpdateModeFlags mode); void k_calculate(); void initApp(); void initPult(); diff --git a/cd_utils/cdutils_k.cpp b/cd_utils/cdutils_k.cpp index 7c2241c..e240877 100644 --- a/cd_utils/cdutils_k.cpp +++ b/cd_utils/cdutils_k.cpp @@ -17,7 +17,6 @@ KInterface::KInterface() { CONNECTU(core, K_SendFail, this, sendFailed); CONNECTU(core, K_Received, this, received); CONNECTU(core, K_ReceiveFail, this, receiveFailed); - CONNECTU(core, K_KeepNamesRequest, this, keepNamesRequest); } @@ -127,8 +126,8 @@ void KInterface::parse(PIIODevice * d) { } -void KInterface::update(PIIODevice * d) { - core->k_update(d); +void KInterface::update(PIIODevice * d, UpdateModeFlags mode) { + core->k_update(d, mode); } diff --git a/cd_utils/cdutils_k.h b/cd_utils/cdutils_k.h index aed19a2..2d7a2a5 100644 --- a/cd_utils/cdutils_k.h +++ b/cd_utils/cdutils_k.h @@ -47,7 +47,7 @@ public: void write(PIIODevice * d); void read(PIIODevice * d); void parse(PIIODevice * d); - void update(PIIODevice * d); + void update(PIIODevice * d, UpdateModeFlags mode = SaveByName); void calculate(); PIString appConfig(); diff --git a/cd_utils/cdutils_types.cpp b/cd_utils/cdutils_types.cpp index 072558a..69bd7fa 100644 --- a/cd_utils/cdutils_types.cpp +++ b/cd_utils/cdutils_types.cpp @@ -375,16 +375,70 @@ void CDSection::read(const void * ep) { } -void CDSection::update(CDSection & v, bool keep_names) { -// piCout << "[CDSection] update start"; - PIMap prev_k_f; - PISet used; - PIMap::iterator i; - //piCout << "before" << k.size() << v.k.size(); - if (keep_names) { - for (i = k.begin(); i != k.end(); ++i) - prev_k_f[i.value().name_] = i.value().formula(); +void CDSection::update(CDSection & v, UpdateModeFlags mode) { + if (mode[SaveByIndex] && mode[SaveByName]) { + piCout << "[CDSection] update error: SaveByIndex | SaveByName mode is denied!"; + return; } + //piCout << "[CDSection] update start"; + //piCout << "before" << k.size() << v.k.size(); + + PIMap prev_k_f_bi; + PIMap prev_k_f_bn; + PIMap::iterator i; + if (mode[SaveByIndex]) { + for (i = k.begin(); i != k.end(); ++i) + prev_k_f_bi[i.key()] = i.value().formula(); + } + if (mode[SaveByName]) { + for (i = k.begin(); i != k.end(); ++i) + prev_k_f_bn[i.value().name_] = i.value().formula(); + } + if (!mode[Merge]) + k.clear(); + for (i = v.k.begin(); i != v.k.end(); ++i) { + int id = i.key(); + PIString n = i.value().name(); + k[id] = i.value(); + if (mode[SaveByIndex]) { + if (prev_k_f_bi.contains(id)) + k[id].setFormula(prev_k_f_bi[id]); + } + if (mode[SaveByName]) { + if (prev_k_f_bn.contains(n)) + k[id].setFormula(prev_k_f_bn[n]); + } + } + + PIMap prev_s_bi; + PIMap prev_s_bn; + PIMap::iterator j; + if (mode[SaveByIndex]) { + for (j = s.begin(); j != s.end(); ++j) + prev_s_bi[j.key()] = j.value(); + } + if (mode[SaveByName]) { + for (j = s.begin(); j != s.end(); ++j) + prev_s_bn[j.value().alias] = j.value(); + } + if (!mode[Merge]) + s.clear(); + for (j = v.s.begin(); j != v.s.end(); ++j) { + int id = j.key(); + PIString n = j.value().alias; + s[id] = j.value(); + if (mode[SaveByIndex]) { + if (prev_s_bi.contains(id)) + s[id] = prev_s_bi[id]; + } + if (mode[SaveByName]) { + if (prev_s_bn.contains(n)) + s[id] = prev_s_bn[n]; + } + s[id].update(j.value(), mode); + } + + /*PISet used; for (i = k.begin(); i != k.end(); ++i) { if (v.k.contains(i.key())) { PIString f = k[i.key()].formula_; @@ -393,10 +447,10 @@ void CDSection::update(CDSection & v, bool keep_names) { k[i.key()] = cdt; used << i.key(); } - if (keep_names) { + if (mode) { CDType & ck(k[i.key()]); - if (prev_k_f.contains(ck.name_)) - ck.setFormula(prev_k_f[ck.name_]); + if (prev_k_f_bn.contains(ck.name_)) + ck.setFormula(prev_k_f_bn[ck.name_]); } } //piCout << " after" << k.size(); @@ -404,19 +458,19 @@ void CDSection::update(CDSection & v, bool keep_names) { if (!used.contains(i.key())) k[i.key()] = i.value(); CDType & ck(k[i.key()]); - ck.setFormula(prev_k_f.value(ck.name_)); + ck.setFormula(prev_k_f_bn.value(ck.name_)); } used.clear(); PIMap::iterator j; for (j = s.begin(); j != s.end(); ++j) { if (v.s.contains(j.key())) - j.value().update(v.s[j.key()], keep_names); + j.value().update(v.s[j.key()], mode); used << j.key(); } for (j = v.s.begin(); j != v.s.end(); ++j) { if (!used.contains(j.key())) s[j.key()] = j.value(); - } + }*/ // piCout << "[CDSection] update end"; } diff --git a/cd_utils/cdutils_types.h b/cd_utils/cdutils_types.h index be664e7..6eecd28 100644 --- a/cd_utils/cdutils_types.h +++ b/cd_utils/cdutils_types.h @@ -15,6 +15,14 @@ namespace CDUtils { class CDSection; +enum UpdateMode { + SaveByIndex = 0x01, + SaveByName = 0x02, + Merge = 0x04 +}; + +typedef PIFlags UpdateModeFlags; + class CDType { friend class CDSection; public: @@ -97,7 +105,7 @@ protected: } void write(PIIODevice * d, const PIString & prefix = PIString()); void read(const void * ep); - void update(CDSection & v, bool keep_names); + void update(CDSection & v, UpdateModeFlags mode = SaveByName); bool isSameStructure(CDSection & v); void prepareCalculate(); void calculateRecursive(PIEvaluator * e); diff --git a/qcd_utils/pult/form.cpp b/qcd_utils/pult/form.cpp index d36b4fe..18daa2b 100644 --- a/qcd_utils/pult/form.cpp +++ b/qcd_utils/pult/form.cpp @@ -165,7 +165,10 @@ void Form::on_pushButton_4_clicked() { void Form::on_pushButton_6_clicked() { - ui->treeView->buildFromHeader(QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with K description"), "k_description.h", "C/C++ header files(*.h *.hpp);;All files(*)")); + QString fn = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with K description"), "k_description.h", "C/C++ header files(*.h *.hpp);;All files(*)"); + if (fn.isEmpty()) return; + if (mode_dlg.exec() == QDialog::Rejected) return; + ui->treeView->buildFromHeader(fn, mode_dlg.mode()); /*piCout << K.root()["Radar_WaveFreqTune"]; piCout << K.root()["11.NVA_PulseGenFineTune"]; piCout << K.root()[".NVA.NVA_PulseGenFineTune"]; diff --git a/qcd_utils/pult/form.h b/qcd_utils/pult/form.h index ae334c5..700ecdc 100644 --- a/qcd_utils/pult/form.h +++ b/qcd_utils/pult/form.h @@ -2,6 +2,7 @@ #define FORM_H #include +#include namespace Ui { class Form; @@ -22,7 +23,9 @@ private slots: void on_buttonCalc_clicked(); private: - Ui::Form *ui; + Ui::Form * ui; + QCDModeDialog mode_dlg; + }; #endif // FORM_H diff --git a/qcd_utils/qcd_kview.cpp b/qcd_utils/qcd_kview.cpp index 03bb984..df9ad9a 100644 --- a/qcd_utils/qcd_kview.cpp +++ b/qcd_utils/qcd_kview.cpp @@ -80,11 +80,11 @@ void CDKView::clearK() { } -void CDKView::buildFromHeader(const QString &kdescription) { +void CDKView::buildFromHeader(const QString &kdescription, int mode) { if (kdescription.isEmpty()) return; PIString kdesc_file = Q2PIString(QDir::current().relativeFilePath(kdescription)); PIFile f(kdesc_file, PIIODevice::ReadOnly); - K.update(&f); + K.update(&f, mode); refresh(); } diff --git a/qcd_utils/qcd_kview.h b/qcd_utils/qcd_kview.h index 4f545c5..2c3025c 100644 --- a/qcd_utils/qcd_kview.h +++ b/qcd_utils/qcd_kview.h @@ -26,7 +26,7 @@ public slots: void saveK(); void loadK(); void clearK(); - void buildFromHeader(const QString & kdescription); + void buildFromHeader(const QString & kdescription, int mode = 2); void calculateK(); private slots: diff --git a/qcd_utils/qcd_modedialog.cpp b/qcd_utils/qcd_modedialog.cpp new file mode 100644 index 0000000..9612588 --- /dev/null +++ b/qcd_utils/qcd_modedialog.cpp @@ -0,0 +1,46 @@ +#include "qcd_modedialog.h" +#include "ui_qcd_modedialog.h" + + +QCDModeDialog::QCDModeDialog(QWidget * parent): QDialog(parent) { + ui = new Ui::QCDModeDialog(); + ui->setupUi(this); +} + + +QCDModeDialog::~QCDModeDialog() { + delete ui; +} + + +CDUtils::UpdateModeFlags QCDModeDialog::mode() const { + CDUtils::UpdateModeFlags ret = 0; + if (ui->checkSaveIndex->isChecked()) ret |= CDUtils::SaveByIndex; + if (ui->checkSaveName->isChecked()) ret |= CDUtils::SaveByName; + if (ui->checkMerge->isChecked()) ret |= CDUtils::Merge; + return ret; +} + + +void QCDModeDialog::changeEvent(QEvent *e) { + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + + +void QCDModeDialog::on_checkSaveIndex_clicked(bool checked) { + if (!checked) return; + ui->checkSaveName->setChecked(false); +} + + +void QCDModeDialog::on_checkSaveName_clicked(bool checked) { + if (!checked) return; + ui->checkSaveIndex->setChecked(false); +} diff --git a/qcd_utils/qcd_modedialog.h b/qcd_utils/qcd_modedialog.h new file mode 100644 index 0000000..702cd20 --- /dev/null +++ b/qcd_utils/qcd_modedialog.h @@ -0,0 +1,31 @@ +#ifndef QCD_MODEDIALOG_H +#define QCD_MODEDIALOG_H + +#include +#include + +namespace Ui { + class QCDModeDialog; +} + +class QCDModeDialog: public QDialog +{ + Q_OBJECT +public: + explicit QCDModeDialog(QWidget * parent = 0); + ~QCDModeDialog(); + + CDUtils::UpdateModeFlags mode() const; + +protected: + void changeEvent(QEvent *e); + + Ui::QCDModeDialog * ui; + +private slots: + void on_checkSaveIndex_clicked(bool checked); + void on_checkSaveName_clicked(bool checked); + +}; + +#endif // QCD_MODEDIALOG_H diff --git a/qcd_utils/qcd_modedialog.ui b/qcd_utils/qcd_modedialog.ui new file mode 100644 index 0000000..19918dd --- /dev/null +++ b/qcd_utils/qcd_modedialog.ui @@ -0,0 +1,85 @@ + + + QCDModeDialog + + + + 0 + 0 + 251 + 152 + + + + Update description mode + + + + + + Save by index + + + + + + + Save by name + + + + + + + Merge + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + QCDModeDialog + accept() + + + 106 + 131 + + + 101 + 146 + + + + + buttonBox + rejected() + QCDModeDialog + reject() + + + 182 + 127 + + + 169 + 146 + + + + +