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

This commit is contained in:
2017-01-22 21:14:32 +00:00
parent 30fd5d2a07
commit 9f9b624124
65 changed files with 547 additions and 144 deletions

52
qcd_utils/CMakeLists.txt Normal file
View File

@@ -0,0 +1,52 @@
project(qcd_utils)
cmake_minimum_required(VERSION 2.6)
if (NOT LIBPROJECT)
find_package(PIP REQUIRED)
endif ()
if (MINGW)
find_package(MinGW REQUIRED)
endif()
find_package(Qt4 REQUIRED)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PIP_INCLUDES} ${QT_INCLUDES})
set(PULT_NAME "cd_pult")
option(PULT "Build ${PULT_NAME}" 1)
option(LIB "System install" 1)
option(DEBUG "Build with -g3" 0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
if (DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
endif ()
file(GLOB CPPS "*.cpp")
file(GLOB MOCS "*.h")
file(GLOB UIS "*.ui")
file(GLOB RES "*.qrc")
qt4_wrap_cpp(CMOCS ${MOCS} OPTIONS -nw)
qt4_wrap_ui(CUIS ${UIS})
qt4_add_resources(RESS ${RES})
add_library(${PROJECT_NAME} SHARED ${CPPS} ${CMOCS} ${CUIS} ${RESS} ${MOCS})
set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${PIP_LIBRARY} qad_widgets cd_utils piqt)
target_link_libraries(${PROJECT_NAME} ${LIBS})
if (NOT DEFINED ENV{QNX_HOST})
if (PULT)
add_subdirectory(pult)
endif ()
endif ()
if (LIB)
if (WIN32)
set(CMAKE_INSTALL_PREFIX ${MINGW_DIR})
install(FILES ${MOCS} DESTINATION ${MINGW_INCLUDE})
install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_LIB})
install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_BIN})
get_filename_component(QTDIR ${QT_QMAKE_EXECUTABLE} PATH)
install(TARGETS ${PROJECT_NAME} DESTINATION ${QTDIR})
else ()
set(CMAKE_INSTALL_PREFIX /usr)
install(FILES ${MOCS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endif ()
message(STATUS "Install to system \"${CMAKE_INSTALL_PREFIX}\"")
else ()
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
message(STATUS "Install to local \"bin\"")
endif ()

4
qcd_utils/clean.bat Normal file
View File

@@ -0,0 +1,4 @@
#make clean
del /q /f /s CMakeFiles
rmdir /q /s CMakeFiles
del /q /f CMakeCache.txt Makefile cmake_install.cmake install_manifest.txt *.user* *~ *cxx moc_* ui_* qrc_* *.o *.exe *.a *.dll *.lib core *.qrc.depends

1
qcd_utils/make_lib.bat Normal file
View File

@@ -0,0 +1 @@
cmake -G "MinGW Makefiles" -DLIB=1 && make install . %*

View File

@@ -0,0 +1,21 @@
project(cd_pult)
cmake_minimum_required(VERSION 2.6)
if (NOT LIBPROJECT)
find_package(PIP REQUIRED)
endif ()
if (MINGW)
find_package(MinGW REQUIRED)
endif()
find_package(Qt4 REQUIRED)
find_package(OpenGL REQUIRED)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PIP_INCLUDES} ${QT_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}/../)
file(GLOB PULT_CPPS "*.cpp")
file(GLOB PULT_MOCS "*.h")
file(GLOB PULT_UIS "*.ui")
file(GLOB PULT_RES "*.qrc")
qt4_wrap_cpp(PULT_CMOCS ${PULT_MOCS} OPTIONS -nw)
qt4_wrap_ui(PULT_CUIS ${PULT_UIS})
qt4_add_resources(PULT_RESS ${PULT_RES})
add_executable(${PROJECT_NAME} ${PULT_CPPS} ${PULT_CMOCS} ${PULT_CUIS} ${PULT_RESS} ${PULT_MOCS})
set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${OPENGL_LIBRARIES} ${PIP_LIBRARY} qad_graphic qad_utils qad_widgets qcd_utils)
target_link_libraries(${PROJECT_NAME} ${LIBS} cd_utils)

View File

549
qcd_utils/pult/cd_pult.cpp Normal file
View File

@@ -0,0 +1,549 @@
#include <QScrollBar>
#include <QMessageBox>
#include <math.h>
#include "cd_pult.h"
#include "ui_cd_pult.h"
#include "piqt.h"
#include "pifile.h"
#include "qpiconfig.h"
using namespace CDUtils;
CD_Pult::CD_Pult(): QMainWindow(), config_("cd_pult.conf"),
config(piqt(config_), QIODevice::ReadWrite) {
//cout << sizeof(coeffsK.k_protocol->to_k) << endl;
ui = new Ui::CD_Pult();
ui->setupUi(this);
ui->configWidget->setQPIConfig(&config);
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);
show_x = config.getValue("show_x", true);
if (!show_x)
ui->tabWidget->removeTab(1);
session.setFile("session_cd_pult.conf");
session.addEntry(this);
session.addEntry(ui->tabWidget);
session.addEntry(ui->checkKHideNormal);
session.addEntry(ui->checkKHideExpressions);
session.addEntry(ui->checkKAutoCalculate);
session.addEntry(ui->spinHistory);
session.addEntry(ui->spinBuffer);
needWrite = isPause = false;
timer = 0;
//x.resize(KX_X_PACKET_NUM);
//k.resize(K_NUM);
QPalette pal = palette();
QColor col;
ui->graphic->setGraphicsCount(0);
//renew();
ui->treeK->setColumnWidth(0, 60);
ui->treeK->setColumnWidth(1, 250);
ui->treeK->setColumnWidth(3, 100);
ui->treeK->setColumnWidth(4, 100);
//ui->table->setK(coeffsK.k()->data(), coeffsK.count());
//addToList(trUtf8("Read K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(coeffs.fileName())).arg(K.size_s()).arg(coeffs.k_content.size_s()), Qt::darkMagenta);
/*CONNECT(void, &coeffs, sendFailed, this, pip_sendFailed);
CONNECT(void, &coeffs, sendSucceed, this, pip_sendSucceed);
CONNECT(void, &coeffs, receiveFailed, this, pip_receiveFailed);
CONNECT(void, &coeffs, receiveSucceed, this, pip_receiveSucceed);*/
kmodel = new CDKItemModel();
ui->treeCDK->setModel(kmodel);
delegate = new CDKDelegate();
ui->treeCDK->setItemDelegateForColumn(4, delegate);
CONNECTU(&K, sended, this, pip_sendSucceed);
CONNECTU(&K, sendFailed, this, pip_sendFailed);
CONNECTU(&K, received, this, pip_receiveSucceed);
CONNECTU(&K, receiveFailed, this, pip_receiveFailed);
connect(this, SIGNAL(q_k_sendFailed()), this, SLOT(k_sendFailed()), Qt::QueuedConnection);
connect(this, SIGNAL(q_k_sendSucceed()), this, SLOT(k_sendSucceed()), Qt::QueuedConnection);
connect(this, SIGNAL(q_k_receiveFailed()), this, SLOT(k_receiveFailed()), Qt::QueuedConnection);
connect(this, SIGNAL(q_k_receiveSucceed()), this, SLOT(k_receiveSucceed()), Qt::QueuedConnection);
connect(&timer_diag, SIGNAL(timeout()), this, SLOT(updateDiag()));
connect(&session, SIGNAL(loading(QPIConfig&)), this, SLOT(loading(QPIConfig&)));
connect(&session, SIGNAL(saving(QPIConfig&)), this, SLOT(saving(QPIConfig&)));
connect(ui->checkKHideNormal, SIGNAL(toggled(bool)), this, SLOT(filterTree()));
connect(ui->checkKHideExpressions, SIGNAL(toggled(bool)), this, SLOT(filterTree()));
connect(ui->lineKSearch, SIGNAL(textChanged(QString)), this, SLOT(filterTree()));
session.load();
on_spinBuffer_editingFinished();
K.reinitConnection(K.pultConfig());
K.configure(config_);
K.readFile();
updateKDesc();
updateCDesc();
timer_diag.start(40);
}
CD_Pult::~CD_Pult() {
session.save();
}
void CD_Pult::loading(QPIConfig & conf) {
kdesc_file = Q2PIString(conf.getValue("kdesc_file").stringValue());
cdesc_file = Q2PIString(conf.getValue("cdesc_file").stringValue());
}
void CD_Pult::saving(QPIConfig & conf) {
conf.setValue("kdesc_file", PI2QString(kdesc_file));
conf.setValue("cdesc_file", PI2QString(cdesc_file));
}
bool CD_Pult::eventFilter(QObject * o, QEvent * e) {
if (o == ui->list->viewport()) {
if (e->type() == QEvent::ContextMenu) {
clear_target = 0;
log_menu.popup(((QContextMenuEvent*)e)->globalPos());
}
return QMainWindow::eventFilter(o, e);
}
if (o == ui->treeK->viewport()) {
if (e->type() == QEvent::ContextMenu) {
clear_target = 1;
log_menu.popup(((QContextMenuEvent*)e)->globalPos());
}
return QMainWindow::eventFilter(o, e);
}
//int ind = o->property("index").toInt();
//qDebug() << "event" << i << e->type();
switch (e->type()) {
case QEvent::Enter:
ui->graphic->setAutoUpdate(false);
//for (int i = 0; i < KX_X_PACKET_NUM; ++i)
// ui->graphic->setGraphicLineWidth(ind == i ? 3. : 1., i);
ui->graphic->setAutoUpdate(true);
ui->graphic->update();
break;
case QEvent::Leave:
ui->graphic->setAutoUpdate(false);
//for (int i = 0; i < KX_X_PACKET_NUM; ++i)
// ui->graphic->setGraphicLineWidth(1., i);
ui->graphic->setAutoUpdate(true);
ui->graphic->update();
break;
default: break;
}
return QMainWindow::eventFilter(o, e);
}
void CD_Pult::timerEvent(QTimerEvent * e) {
/*if (e->timerId() == timer_update) {
if (need_update) {
need_update = false;
ui->graphic->updateGraphics();
}
}*/
if (e->timerId() == timer) {
static QString sPI = QString::number(atan(1) * 4., 'f', 14).leftJustified(14);
static int cnt = 0;
int si = qMax<int>(cnt - 6, 0);
++cnt;
cnt %= 23;
ui->labelWait->setText(QString(si, QChar(' ')) + sPI.mid(cnt - 6, 6).trimmed());
//if (!coeffs.isReady()) return;
//ui->table->setK(coeffsK.k()->data(), coeffsK.count());
//ui->table->showK();
}
}
void CD_Pult::addToList(const QString & s, const QColor & c) {
ui->list->addItem(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:ss - ") + s);
ui->list->item(ui->list->count() - 1)->setTextColor(c);
ui->list->scrollToBottom();
}
void CD_Pult::on_actionClear_triggered() {
switch (clear_target) {
case 0:
ui->list->clear();
break;
case 1:
clearSelected();
break;
default: break;
}
}
void CD_Pult::clearSelected() {
QList<QTreeWidgetItem * > si = ui->treeK->selectedItems();
ui->treeK->setUpdatesEnabled(false);
ui->treeK->blockSignals(true);
foreach (QTreeWidgetItem * i, si) {
// int ki = i->text(0).toInt();
i->setText(2, "");
//coeffs.setFormula(ki, "");
}
ui->treeK->blockSignals(false);
ui->treeK->setUpdatesEnabled(true);
if (ui->checkKAutoCalculate->isChecked()) {
QApplication::processEvents();
//calculate();
}
}
QString CD_Pult::typeName(const QString & n) const {
if (n.isEmpty()) return "";
switch (n[0].toLatin1()) {
case 'l': return trUtf8("list"); break;
case 'b': return trUtf8("bool"); break;
case 'n': return trUtf8("int"); break;
case 'f': return trUtf8("double"); break;
case 'c': return trUtf8("color"); break;
case 'r': return trUtf8("rect"); break;
case 'a': return trUtf8("rect"); break;
case 'p': return trUtf8("point"); break;
case 'v': return trUtf8("vector"); break;
case 'i': return trUtf8("IP"); break;
case 'e': return trUtf8("enum"); break;
case 'F': return trUtf8("file"); break;
case 'D': return trUtf8("dir"); break;
}
return trUtf8("double");
}
void CD_Pult::makeTreeSection(CDSection & ks, QTreeWidgetItem * pi) {
PIMap<int, CDType>::iterator ki;
for (ki = ks.k.begin(); ki != ks.k.end(); ++ki) {
QTreeWidgetItem * ti = new QTreeWidgetItem(pi);
const CDType & ck(ki.value());
ti->setText(0, QString::number(ck.index()));
ti->setText(1, PI2QString(ck.name()));
ti->setText(2, typeName(PI2QString(ck.type())));
ti->setText(3, PI2QString(ck.formula()));
ti->setText(5, PI2QString(ck.comment()));
}
PIMap<int, CDSection>::iterator si;
for (si = ks.s.begin(); si != ks.s.end(); ++si) {
QTreeWidgetItem * ti = new QTreeWidgetItem(pi);
CDSection & cs(si.value());
ti->setText(0, QString("[%1]").arg(si.key()));
ti->setText(1, PI2QString(cs.alias));
ti->setText(2, PI2QString(cs.name));
makeTreeSection(cs, ti);
}
}
void CD_Pult::on_treeK_itemClicked(QTreeWidgetItem * item, int column) {
Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if (column == 2) f |= Qt::ItemIsEditable;
item->setFlags(f);
}
void CD_Pult::on_treeK_itemChanged(QTreeWidgetItem * item, int column) {
if (column != 2) return;
// int ki = item->text(0).toInt();
//coeffs.setFormula(ki, piqt(item->text(column)));
if (ui->checkKAutoCalculate->isChecked())
;//calculate();
}
void CD_Pult::on_buttonSendK_clicked() {
// on_buttonWrite_clicked();
K.send();
//coeffs.sendCoeffs();
if (timer != 0) killTimer(timer);
timer = startTimer(100);
}
void CD_Pult::on_buttonReceiveK_clicked() {
K.request();
// K.se
//coeffs.receiveCoeffs();
if (timer != 0) killTimer(timer);
timer = startTimer(100);
}
void CD_Pult::on_buttonShowAll_clicked() {
/*for (int i = 0; i < KX_X_PACKET_NUM; ++i) {
checks[i]->check.setChecked(true);
//ui->graphic->setGraphicVisible(true, i);
}*/
}
void CD_Pult::on_buttonHideAll_clicked() {
/*for (int i = 0; i < KX_X_PACKET_NUM; ++i) {
checks[i]->check.setChecked(false);
//ui->graphic->setGraphicVisible(false, i);
}*/
}
void CD_Pult::on_buttonRead_clicked() {
K.readFile();
addToList(trUtf8("Read K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(K.file())).arg(K.count()).arg(K.fileSize()), Qt::darkMagenta);
updateTree();
}
void CD_Pult::on_buttonWrite_clicked() {
K.writeFile();
addToList(trUtf8("Write K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(K.file())).arg(K.count()).arg(K.fileSize()), Qt::darkMagenta);
}
void CD_Pult::on_buttonSetKDesc_clicked() {
QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with K description"), PI2QString(kdesc_file), "C/C++ header files(*.h *.hpp);;All files(*)");
if (ret.isEmpty()) return;
kdesc_file = Q2PIString(QDir::current().relativeFilePath(ret));
PIFile f(kdesc_file, PIIODevice::ReadOnly);
piCout << "open description:" << Q2PIString(ret);
//K.update(&f);
updateKDesc(true);
}
void CD_Pult::on_buttonSetCDesc_clicked() {
QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with C description"), PI2QString(cdesc_file), "C/C++ header files(*.h *.hpp);;All files(*)");
if (ret.isEmpty()) return;
cdesc_file = Q2PIString(QDir::current().relativeFilePath(ret));
updateCDesc();
}
void CD_Pult::k_sendFailed() {
addToList(trUtf8("K not sended"), Qt::darkRed);
if (timer != 0) killTimer(timer);
}
void CD_Pult::k_sendSucceed() {
addToList(trUtf8("K sended"), Qt::darkGreen);;
if (timer != 0) killTimer(timer);
}
void CD_Pult::k_receiveFailed() {
addToList(trUtf8("K not received"), Qt::darkRed);
if (timer != 0) killTimer(timer);
}
void CD_Pult::k_receiveSucceed() {
addToList(trUtf8("K received"), Qt::darkGreen);
if (timer != 0) killTimer(timer);
updateTree();
}
void CD_Pult::on_spinBuffer_editingFinished() {
ui->graphic->setHistorySize(ui->spinBuffer->value());
}
void CD_Pult::updateGraph() {
ui->graphic->updateGraphics();
}
void CD_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());
ui->spinKReceived->setValue(coeffs.k_protocol->receiveCount());
ui->spinKWrong->setValue(coeffs.k_protocol->wrongCount());
ui->spinKMissed->setValue(coeffs.k_protocol->missedCount());
ui->labelKType->setText("0x" + QString::number(coeffs.k_protocol->from_k.type, 16).toUpper().rightJustified(2, '0'));
ui->labelKAddrPult->setText("0x" + QString::number(coeffs.k_protocol->from_k.addr_to, 16).toUpper().rightJustified(2, '0'));
ui->labelKAddr->setText("0x" + QString::number(coeffs.k_protocol->to_k.addr_to, 16).toUpper().rightJustified(2, '0'));
ui->labelXReceiver->setText(piqt(prot_x->receiverDeviceName() + " - " + prot_x->receiverDeviceState()));
ui->labelXSender->setText(piqt(prot_x->senderDeviceName()));
ui->spinXSended->setValue(prot_x->sendCount());
ui->spinXReceived->setValue(prot_x->receiveCount());
ui->spinXWrong->setValue(prot_x->wrongCount());
ui->spinXMissed->setValue(prot_x->missedCount());
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 CD_Pult::updateKDesc(bool ask_move) {
addToList(trUtf8("Update K description file \"%1\"").arg(PI2QString(kdesc_file)), Qt::darkMagenta);
PIFile f(kdesc_file, PIIODevice::ReadOnly);
//piCout << "call K.update():";
K.root() = CDSection();
K.update(&f);
updateTree(ask_move);
}
void CD_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();
return s1 > s2;
}
void CD_Pult::updateTree(bool move) {
int sp = ui->treeK->verticalScrollBar()->value();
QApplication::setOverrideCursor(Qt::WaitCursor);
//qDebug() << "fill tree ...";
ui->treeK->clear();
ui->treeK->setUpdatesEnabled(false);
eval.clearCustomVariables();
CDSection r = K.root();
makeTreeSection(r, ui->treeK->invisibleRootItem());
/*for (int i = 0; i < K.size_s(); ++i) {
QTreeWidgetItem * ti = new QTreeWidgetItem();
KDesc kd = kdesc[i];
QString kn = QString("k%1").arg(i);
knames[kn] = i;
knames_sort << kn;
if (eval.content.findVariable(kn) < 0)
eval.content.addVariable(kn, 0., false);
if (!kd.name.isEmpty()) {
knames[kd.name] = i;
knames_sort << kd.name;
eval.content.addVariable(kd.name, 0., false);
}
if (move && !kd.name.isEmpty()) {
if (prev_val.contains(kd.name))
coeffs.setFormula(i, Q2PIString(prev_val[kd.name]));
}
ti->setText(0, QString::number(i));
ti->setText(1, kd.name);
ti->setText(2, PI2QString(coeffs.formula(i)));
ti->setText(3, QString::number(K[i]));
ti->setText(4, typeName(kd.type));
ti->setText(5, kd.comment);
ui->treeK->addTopLevelItem(ti);
}*/
eval.content.sortVariables();
//qDebug() << "fill tree ok";
//qDebug() << "sort ...";
qSort(knames_sort.begin(), knames_sort.end(), stringComp);
//qDebug() << "names" << knames_sort;
//qDebug() << "sort ok";
QApplication::restoreOverrideCursor();
ui->treeK->setUpdatesEnabled(true);
ui->treeK->verticalScrollBar()->setValue(sp);
//calculate();
filterTree();
kmodel->rebuildModel();
ui->treeCDK->expandAll();
for (int i=0; i<6; i++) ui->treeCDK->resizeColumnToContents(i);
}
void CD_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 CD_Pult::filterTree() {
bool hn = ui->checkKHideNormal->isChecked();
bool hs = ui->checkKHideExpressions->isChecked();
bool ok = false;
QString fl = ui->lineKSearch->text();
int lc = ui->treeK->topLevelItemCount();
for (int i = 0; i < lc; ++i) {
QTreeWidgetItem * ti = ui->treeK->topLevelItem(i);
if (fl.isEmpty())
ti->setHidden(false);
else
ti->setHidden(!ti->text(0).contains(fl, Qt::CaseInsensitive) &&
!ti->text(1).contains(fl, Qt::CaseInsensitive) &&
!ti->text(2).contains(fl, Qt::CaseInsensitive) &&
!ti->text(3).contains(fl, Qt::CaseInsensitive) &&
!ti->text(4).contains(fl, Qt::CaseInsensitive));
if (hn)
if (ti->data(0, Qt::UserRole).toBool())
ti->setHidden(true);
if (hs) {
ti->data(2, Qt::DisplayRole).toDouble(&ok);
if (!ok)
ti->setHidden(true);
}
}
}
void CD_Pult::markError(QTreeWidgetItem * item, const QString & tool_tip) {
int cc = item->columnCount();
for (int i = 0; i < cc; ++i)
item->setBackgroundColor(i, QColor(255, 200, 200));
if (item->toolTip(2).isEmpty())
item->setToolTip(2, tool_tip);
if (item->toolTip(3).isEmpty())
item->setToolTip(3, tool_tip);
item->setData(0, Qt::UserRole, false);
item->setText(3, "Error");
}
void CD_Pult::markNormal(QTreeWidgetItem * item) {
int cc = item->columnCount();
for (int i = 0; i < cc; ++i)
item->setBackground(i, Qt::NoBrush);
item->setToolTip(2, QString());
item->setToolTip(3, QString());
item->setData(0, Qt::UserRole, true);
}
void CD_Pult::progress(int val, int max) {
if (ctm.elapsed() < 50) return;
ctm.restart();
ui->progress->setValue(qRound(val * 100. / max));
QApplication::processEvents();
}
void CD_Pult::commandClicked() {
QPushButton * b = qobject_cast<QPushButton*>(sender());
if (!b) return;
//prot_c->sendCommand(b->property("_command").toInt());
}

123
qcd_utils/pult/cd_pult.h Normal file
View File

@@ -0,0 +1,123 @@
#ifndef CD_PULT_H
#define CD_PULT_H
#include <QDialog>
#include <QSpinBox>
#include <QFont>
#include <QRect>
#include <QFile>
#include <QVector>
#include <QDir>
#include <QTextStream>
#include <QDebug>
#include <QBoxLayout>
#include <QCheckBox>
#include <QMainWindow>
#include <QTimer>
#include <QTime>
#include <QMenu>
#include <QMetaObject>
#include <QTreeWidgetItem>
#include <QLabel>
#include "piqt.h"
#include "session_manager.h"
#include "qpievaluator.h"
#include "cdutils_core.h"
#include "cdutils_k.h"
#include "qcd_kmodel.h"
namespace Ui {
class CD_Pult;
}
class CD_Pult: public QMainWindow, public PIObject
{
Q_OBJECT
PIOBJECT(CD_Pult)
public:
CD_Pult();
~CD_Pult();
private:
bool eventFilter(QObject * o, QEvent * e);
void timerEvent(QTimerEvent * );
void addToList(const QString & s, const QColor & c);
QColor invertColor(QColor col) {return QColor(255 - col.red(), 255 - col.green(), 255 - col.blue());}
void stopWait();
bool calculateExpression(int i, QVector<int> trace);
void markError(QTreeWidgetItem * item, const QString & tool_tip = QString());
void markNormal(QTreeWidgetItem * item);
void progress(int val, int max);
void clearSelected();
QString typeName(const QString & n) const;
void makeTreeSection(CDUtils::CDSection & ks, QTreeWidgetItem * pi);
EVENT_HANDLER(void, pip_sendFailed) {emit q_k_sendFailed();}
EVENT_HANDLER(void, pip_sendSucceed) {emit q_k_sendSucceed();}
EVENT_HANDLER(void, pip_receiveFailed) {emit q_k_receiveFailed();}
EVENT_HANDLER(void, pip_receiveSucceed) {emit q_k_receiveSucceed();}
Ui::CD_Pult * ui;
PIString config_, name_x, name_c;
PIString kdesc_file, cdesc_file, xdesc_file;
QMenu log_menu;
QTime tm, ctm;
QTimer timer_diag;
QMap<QString, int> knames;
QSet<int> calculated;
QStringList knames_sort;
QPIEvaluator eval;
SessionManager session;
QPIConfig config;
CDKItemModel * kmodel;
CDKDelegate * delegate;
//QVector<float> k, x;
int clear_target, timer;
bool needWrite, isPause, need_update, show_x;
private slots:
void loading(QPIConfig & conf);
void saving(QPIConfig & conf);
void updateGraph();
void updateDiag();
void updateKDesc(bool ask_move = false);
void updateCDesc();
void updateTree(bool move = false);
void updateCommands();
void filterTree();
//void calculate();
//void renew(bool write = true);
void commandClicked();
void k_sendFailed();
void k_sendSucceed();
void k_receiveFailed();
void k_receiveSucceed();
void on_spinBuffer_editingFinished();
void on_buttonSendK_clicked();
void on_buttonReceiveK_clicked();
void on_buttonShowAll_clicked();
void on_buttonHideAll_clicked();
void on_buttonRead_clicked();
void on_buttonWrite_clicked();
void on_buttonSetKDesc_clicked();
void on_buttonReparseKDesc_clicked() {updateKDesc(true);}
void on_buttonSetCDesc_clicked();
void on_buttonReparseCDesc_clicked() {updateCDesc();}
//void on_buttonCalculate_clicked() {calculate();}
//void on_buttonApply_clicked() {renew();}
void on_buttonPause_toggled(bool on) {isPause = on;}
void on_treeK_itemClicked(QTreeWidgetItem * item, int column);
void on_treeK_itemChanged(QTreeWidgetItem * item, int column);
void on_actionClear_triggered();
signals:
void q_k_sendFailed();
void q_k_sendSucceed();
void q_k_receiveFailed();
void q_k_receiveSucceed();
};
#endif // CD_PULT_H

View File

@@ -0,0 +1,40 @@
<RCC>
<qresource prefix="/">
<file>icons/dialog-close.png</file>
<file>icons/edit-clear-.png</file>
<file>icons/edit-guides.png</file>
<file>icons/view-grid.png</file>
<file>icons/zoom-fit-best.png</file>
<file>icons/configure.png</file>
<file>icons/alpha.png</file>
<file>icons/document-save.png</file>
<file>icons/edit-clear-locationbar-rtl.png</file>
<file>icons/edit-find.png</file>
<file>icons/list-add.png</file>
<file>icons/edit-delete.png</file>
<file>icons/item-add.png</file>
<file>icons/item.png</file>
<file>icons/node-add.png</file>
<file>icons/node.png</file>
<file>icons/edit-copy.png</file>
<file>icons/edit-paste.png</file>
<file>icons/expand_s_x.png</file>
<file>icons/expand_s_y.png</file>
<file>icons/expand_x.png</file>
<file>icons/expand_y.png</file>
<file>icons/media-playback-pause.png</file>
<file>icons/media-playback-stop.png</file>
<file>icons/media-record.png</file>
<file>icons/application-exit.png</file>
<file>icons/document-save-.png</file>
<file>icons/view-refresh.png</file>
<file>icons/document-open.png</file>
<file>icons/archive-extract.png</file>
<file>icons/document-export.png</file>
<file>icons/document-import.png</file>
<file>icons/zoom-fit-height.png</file>
<file>icons/layer-visible-off.png</file>
<file>icons/layer-visible-on.png</file>
<file>icons/accessories-calculator.png</file>
</qresource>
</RCC>

1284
qcd_utils/pult/cd_pult.ui Normal file
View File

@@ -0,0 +1,1284 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CD_Pult</class>
<widget class="QMainWindow" name="CD_Pult">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1035</width>
<height>728</height>
</rect>
</property>
<property name="windowTitle">
<string>CD Pult</string>
</property>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Coefficients (K)</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<widget class="QPushButton" name="buttonReparseKDesc">
<property name="text">
<string>Update</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/view-refresh.png</normaloff>:/icons/view-refresh.png</iconset>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="buttonRead">
<property name="text">
<string>Read</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/archive-extract.png</normaloff>:/icons/archive-extract.png</iconset>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="buttonSendK">
<property name="text">
<string>Send</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/document-export.png</normaloff>:/icons/document-export.png</iconset>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="5">
<widget class="QListWidget" name="list">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="buttonReceiveK">
<property name="text">
<string>Receive</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/document-import.png</normaloff>:/icons/document-import.png</iconset>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="labelWait">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="buttonWrite">
<property name="text">
<string>Write</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/document-save-.png</normaloff>:/icons/document-save-.png</iconset>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="buttonSetKDesc">
<property name="text">
<string>Make ...</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QCheckBox" name="checkKHideExpressions">
<property name="text">
<string>Hide expressions</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkKHideNormal">
<property name="text">
<string>Show only errors</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_17">
<property name="pixmap">
<pixmap resource="cd_pult.qrc">:/icons/edit-find.png</pixmap>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_16">
<property name="text">
<string> Search:</string>
</property>
</widget>
</item>
<item>
<widget class="CLineEdit" name="lineKSearch">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkKAutoCalculate">
<property name="text">
<string>Auto calculate</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonCalculate">
<property name="toolTip">
<string>Calculate</string>
</property>
<property name="statusTip">
<string>Calculate</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/accessories-calculator.png</normaloff>:/icons/accessories-calculator.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progress">
<property name="value">
<number>100</number>
</property>
<property name="format">
<string>Calculate %p%</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeWidget" name="treeK">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="columnCount">
<number>6</number>
</property>
<attribute name="headerDefaultSectionSize">
<number>200</number>
</attribute>
<attribute name="headerMinimumSectionSize">
<number>20</number>
</attribute>
<column>
<property name="text">
<string>Index</string>
</property>
</column>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
<column>
<property name="text">
<string>Expression</string>
</property>
</column>
<column>
<property name="text">
<string>Calculated</string>
</property>
</column>
<column>
<property name="text">
<string>Comment</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QTreeView" name="treeCDK">
<property name="editTriggers">
<set>QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<attribute name="headerMinimumSectionSize">
<number>20</number>
</attribute>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="title">
<string>Commands (C)</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QPushButton" name="buttonSetCDesc">
<property name="text">
<string>Set C desc file ...</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonReparseCDesc">
<property name="text">
<string>Reparse C desc</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/view-refresh.png</normaloff>:/icons/view-refresh.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QGroupBox" name="groupCommands">
<property name="title">
<string>Commands</string>
</property>
<layout class="QVBoxLayout" name="layout_">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="layoutCommands"/>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>66</width>
<height>441</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Graphics (X)</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QWidget" name="widgetChecks" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<property name="horizontalSpacing">
<number>10</number>
</property>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="buttonShowAll">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show all</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/layer-visible-on.png</normaloff>:/icons/layer-visible-on.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonHideAll">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Hide all</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/layer-visible-off.png</normaloff>:/icons/layer-visible-off.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonRecord">
<property name="text">
<string>Start record</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/media-record.png</normaloff>:/icons/media-record.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="buttonPause">
<property name="text">
<string>Pause</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/media-playback-pause.png</normaloff>:/icons/media-playback-pause.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Show</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinHistory">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="suffix">
<string> с</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>0.100000000000000</double>
</property>
<property name="maximum">
<double>9999.000000000000000</double>
</property>
<property name="value">
<double>10.000000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinBuffer">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="suffix">
<string> с</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>0.100000000000000</double>
</property>
<property name="maximum">
<double>9999.000000000000000</double>
</property>
<property name="value">
<double>60.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Graphic" name="graphic">
<property name="buttons">
<set>Graphic::Autofit|Graphic::BorderInputs|Graphic::Clear|Graphic::Configure|Graphic::CursorAxis|Graphic::Grid|Graphic::OnlyExpandX|Graphic::OnlyExpandY|Graphic::Save</set>
</property>
<property name="borderInputsVisible">
<bool>false</bool>
</property>
<property name="legendVisible">
<bool>false</bool>
</property>
<property name="historySize">
<double>60.000000000000000</double>
</property>
<property name="maxVisibleTime">
<double>10.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Configuration</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>K</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="formAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>receiver:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="labelKReceiver">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>sender:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="labelKSender">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>sended count:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="spinKSended">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1999999999</number>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>received count:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="spinKReceived">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1999999999</number>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>wrong received count:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QSpinBox" name="spinKWrong">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1999999999</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>type:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="labelKType">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelKType_2">
<property name="text">
<string>address K:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="labelKAddr">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="labelKAddrPult">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>missed received count:</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QSpinBox" name="spinKMissed">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1999999999</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelKType_3">
<property name="text">
<string>address pult:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>X</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="formAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>receiver:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="labelXReceiver">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>sender:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="labelXSender">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelKType_4">
<property name="text">
<string>type:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="labelXType">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelKType_5">
<property name="text">
<string>address X:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelKType_6">
<property name="text">
<string>address pult:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="labelXAddrPult">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>sended count:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="spinXSended">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1999999999</number>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>received count:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="spinXReceived">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1999999999</number>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>wrong received count:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QSpinBox" name="spinXWrong">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1999999999</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="labelXAddr">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>missed received count:</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QSpinBox" name="spinXMissed">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1999999999</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>C</string>
</property>
<layout class="QFormLayout" name="formLayout_3">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="formAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_18">
<property name="text">
<string>receiver:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="labelCReceiver">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>sender:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="labelCSender">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelKType_7">
<property name="text">
<string>type:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="labelCType">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelKType_8">
<property name="text">
<string>address C:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelKType_9">
<property name="text">
<string>address pult:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="labelCAddrPult">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_20">
<property name="text">
<string>sended count:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="spinCSended">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1999999999</number>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
<string>received count:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="spinCReceived">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1999999999</number>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_22">
<property name="text">
<string>wrong received count:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QSpinBox" name="spinCWrong">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1999999999</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="labelCAddr">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_23">
<property name="text">
<string>missed received count:</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QSpinBox" name="spinCMissed">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1999999999</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QPIConfigWidget" name="configWidget">
<property name="readOnlyName">
<bool>true</bool>
</property>
<property name="readOnlyType">
<bool>true</bool>
</property>
<property name="readOnlyComment">
<bool>true</bool>
</property>
<property name="columnTypeVisible">
<bool>false</bool>
</property>
<attribute name="headerMinimumSectionSize">
<number>20</number>
</attribute>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonApply">
<property name="text">
<string>Apply</string>
</property>
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/document-save-.png</normaloff>:/icons/document-save-.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<action name="actionClear">
<property name="icon">
<iconset resource="cd_pult.qrc">
<normaloff>:/icons/edit-clear-.png</normaloff>:/icons/edit-clear-.png</iconset>
</property>
<property name="text">
<string>Clear</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>Graphic</class>
<extends>QFrame</extends>
<header>graphic.h</header>
</customwidget>
<customwidget>
<class>QPIConfigWidget</class>
<extends>QTreeWidget</extends>
<header>qpiconfigwidget.h</header>
</customwidget>
<customwidget>
<class>CLineEdit</class>
<extends>QLineEdit</extends>
<header>clineedit.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="cd_pult.qrc"/>
<include location="cd_pult.qrc"/>
</resources>
<connections>
<connection>
<sender>spinHistory</sender>
<signal>valueChanged(double)</signal>
<receiver>graphic</receiver>
<slot>setMaxVisibleTime(double)</slot>
<hints>
<hint type="sourcelabel">
<x>919</x>
<y>107</y>
</hint>
<hint type="destinationlabel">
<x>932</x>
<y>132</y>
</hint>
</hints>
</connection>
</connections>
</ui>

52
qcd_utils/pult/form.cpp Normal file
View File

@@ -0,0 +1,52 @@
#include "form.h"
#include "ui_form.h"
#include <QFileDialog>
#include <QDebug>
#include "cdutils_k.h"
#include "cdutils_core.h"
#include "qcd_core.h"
using namespace CDUtils;
Form::Form(QWidget *parent) : QWidget(parent), ui(new Ui::Form) {
CDCore::instance()->initPult();
ui->setupUi(this);
ui->treeView->setKFile("");
ui->treeView->refresh();
}
Form::~Form() {
delete ui;
}
void Form::on_pushButton_3_clicked() {
ui->treeView->setKFile(QFileDialog::getSaveFileName(this, "Save"));
ui->treeView->saveK();
ui->treeView->setKFile("");
}
void Form::on_pushButton_4_clicked() {
ui->treeView->setKFile(QFileDialog::getOpenFileName(this, "Open"));
ui->treeView->loadK();
ui->treeView->setKFile("");
qDebug() << QCDCore::instance()->bindWindow(this);
}
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(*)"));
/*piCout << K.root()["Radar_WaveFreqTune"];
piCout << K.root()["11.NVA_PulseGenFineTune"];
piCout << K.root()[".NVA.NVA_PulseGenFineTune"];
piCout << K.root()["NVA_A.1.NVA_Clk"];*/
}
void Form::on_buttonCalc_clicked() {
ui->treeView->calculateK();
ui->treeView->refresh();
}

28
qcd_utils/pult/form.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef FORM_H
#define FORM_H
#include <QWidget>
namespace Ui {
class Form;
}
class Form : public QWidget
{
Q_OBJECT
public:
explicit Form(QWidget *parent = 0);
~Form();
private slots:
void on_pushButton_3_clicked();
void on_pushButton_4_clicked();
void on_pushButton_6_clicked();
void on_buttonCalc_clicked();
private:
Ui::Form *ui;
};
#endif // FORM_H

240
qcd_utils/pult/form.ui Normal file
View File

@@ -0,0 +1,240 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>731</width>
<height>508</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<widget class="QPushButton" name="buttonRefresh">
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Send</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="CDKView" name="treeView"/>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="buttonCalc">
<property name="text">
<string>Calculate</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButton_4">
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="pushButton_5">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="pushButton_6">
<property name="text">
<string>update from KDescription</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Receive</string>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="5">
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>GroupBox</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="checkRadar_ADA_On">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item>
<widget class="SpinSlider" name="spinSliderRadar_Antenna_Distance"/>
</item>
<item>
<widget class="QSpinBox" name="spinRadar_Antenna_SwitchRate"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SpinSlider</class>
<extends>QWidget</extends>
<header>spinslider.h</header>
</customwidget>
<customwidget>
<class>CDKView</class>
<extends>QTreeView</extends>
<header location="global">qcd_kview.h</header>
<slots>
<signal>busyStatusChanged(bool)</signal>
<slot>sendK()</slot>
<slot>receiveK()</slot>
<slot>saveK()</slot>
<slot>loadK()</slot>
<slot>clear()</slot>
<slot>clearK()</slot>
<slot>refresh()</slot>
</slots>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>pushButton_2</sender>
<signal>clicked()</signal>
<receiver>treeView</receiver>
<slot>receiveK()</slot>
<hints>
<hint type="sourcelabel">
<x>264</x>
<y>60</y>
</hint>
<hint type="destinationlabel">
<x>264</x>
<y>152</y>
</hint>
</hints>
</connection>
<connection>
<sender>treeView</sender>
<signal>busyStatusChanged(bool)</signal>
<receiver>pushButton_2</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>264</x>
<y>174</y>
</hint>
<hint type="destinationlabel">
<x>264</x>
<y>60</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButton_5</sender>
<signal>clicked()</signal>
<receiver>treeView</receiver>
<slot>clearK()</slot>
<hints>
<hint type="sourcelabel">
<x>264</x>
<y>89</y>
</hint>
<hint type="destinationlabel">
<x>264</x>
<y>188</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>treeView</receiver>
<slot>sendK()</slot>
<hints>
<hint type="sourcelabel">
<x>137</x>
<y>60</y>
</hint>
<hint type="destinationlabel">
<x>198</x>
<y>152</y>
</hint>
</hints>
</connection>
<connection>
<sender>treeView</sender>
<signal>busyStatusChanged(bool)</signal>
<receiver>pushButton</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>177</x>
<y>246</y>
</hint>
<hint type="destinationlabel">
<x>98</x>
<y>46</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonRefresh</sender>
<signal>clicked()</signal>
<receiver>treeView</receiver>
<slot>refresh()</slot>
<hints>
<hint type="sourcelabel">
<x>223</x>
<y>114</y>
</hint>
<hint type="destinationlabel">
<x>217</x>
<y>134</y>
</hint>
</hints>
</connection>
</connections>
</ui>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1005 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1017 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 563 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 644 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 485 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 694 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 658 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 691 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 929 B

10
qcd_utils/pult/main.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include <QtGui/QApplication>
#include "form.h"
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
Form w;
w.show();
return a.exec();
}

196
qcd_utils/qcd_core.cpp Normal file
View File

@@ -0,0 +1,196 @@
#include "qcd_core.h"
#include "cdutils_core.h"
#include "piqt.h"
#include <QWidget>
#include <QCheckBox>
#include <QGroupBox>
#include <QSpinBox>
#include <QSlider>
#include <QScrollBar>
#include <QDoubleSpinBox>
#include <QLineEdit>
#include <spinslider.h>
#include <clineedit.h>
using namespace CDUtils;
int __QCore_Initializer__::count_(0);
QCDCore * __QCore_Initializer__::__instance__(0);
__QCore_Initializer__::__QCore_Initializer__() {
count_++;
if (count_ > 1) return;
__instance__ = new QCDCore();
}
__QCore_Initializer__::~__QCore_Initializer__() {
count_--;
if (count_ > 0) return;
if (__instance__ != 0) {
delete __instance__;
__instance__ = 0;
}
}
QCDCore::QCDCore() {
setObjectName("QCDCore");
setName("QCDCore");
CONNECTU(CDCore::instance(), K_ChangedGlobal, this, K_ChangedGlobal);
updating = false;
}
QCDCore::~QCDCore() {
}
void QCDCore::K_ChangedGlobal() {
QMetaObject::invokeMethod(this, "updateBindedWidgets", Qt::QueuedConnection);
}
void QCDCore::slotBool(bool v) {
QWidget * w = (QWidget*)sender();
if (!w || updating) return;
PIDeque<int> path = binded_widgets.value(w);
CDCore::instance()->k()[path].setValue(PIString::fromBool(v));
}
void QCDCore::slotInt(int v) {
QWidget * w = (QWidget*)sender();
if (!w || updating) return;
PIDeque<int> path = binded_widgets.value(w);
CDCore::instance()->k()[path].setValue(PIString::fromNumber(v));
}
void QCDCore::slotDouble(double v) {
QWidget * w = (QWidget*)sender();
if (!w || updating) return;
PIDeque<int> path = binded_widgets.value(w);
CDCore::instance()->k()[path].setValue(PIString::fromNumber(v));
}
void QCDCore::slotText(QString v) {
QWidget * w = (QWidget*)sender();
if (!w || updating) return;
PIDeque<int> path = binded_widgets.value(w);
CDCore::instance()->k()[path].setValue(Q2PIString(v));
}
int QCDCore::bindWindow(QWidget * wnd) {
if (!wnd) return 0;
CDCore::instance()->k().makePath();
return bindWidgets(wnd->findChildren<QWidget * >());
}
int QCDCore::bindWidgets(QList<QWidget * > wl) {
int ret = 0;
foreach (QWidget * w, wl)
if (bindWidget(w)) ++ret;
return ret;
}
bool QCDCore::bindWidget(QWidget * w) {
if (!w) return false;
QString on = w->objectName();
PIVector<CDType * > ak = CDCore::instance()->k().children();
piForeachC (CDType * k, ak) {
if (!on.endsWith(PI2QString(k->name()))) continue;
QString cn = w->metaObject()->className();
bool ok = false;
if (cn == "QCheckBox" || cn == "QGroupBox") {
connect(w, SIGNAL(toggled(bool)), this, SLOT(slotBool(bool)), Qt::UniqueConnection);
ok = true;
}
if (cn == "QSpinBox" || cn == "QSlider" || cn == "QScrollBar") {
connect(w, SIGNAL(valueChanged(int)), this, SLOT(slotInt(int)), Qt::UniqueConnection);
ok = true;
}
if (cn == "QDoubleSpinBox" || cn == "SpinSlider") {
connect(w, SIGNAL(valueChanged(double)), this, SLOT(slotDouble(double)), Qt::UniqueConnection);
ok = true;
}
if (cn == "QLineEdit" || cn == "CLineEdit") {
connect(w, SIGNAL(textChanged(QString)), this, SLOT(slotText(QString)), Qt::UniqueConnection);
ok = true;
}
if (!ok) continue;
binded_widgets[w] = k->path();
return true;
}
return false;
}
void QCDCore::updateBindedWidgets() {
QMapIterator<QWidget * , PIDeque<int> > it(binded_widgets);
updating = true;
while (it.hasNext()) {
QWidget * w = it.next().key();
QString cn = w->metaObject()->className();
const CDType k(CDCore::instance()->k()[it.value()]);
if (cn == "QCheckBox") qobject_cast<QCheckBox*>(w)->setChecked(k.toBool());
if (cn == "QGroupBox") qobject_cast<QGroupBox*>(w)->setChecked(k.toBool());
if (cn == "QSpinBox") qobject_cast<QSpinBox*>(w)->setValue(k.toInt());
if (cn == "QSlider") qobject_cast<QSlider*>(w)->setValue(k.toInt());
if (cn == "QScrollBar") qobject_cast<QScrollBar*>(w)->setValue(k.toInt());
if (cn == "QDoubleSpinBox") qobject_cast<QDoubleSpinBox*>(w)->setValue(k.toDouble());
if (cn == "SpinSlider") qobject_cast<SpinSlider*>(w)->setValue(k.toDouble());
if (cn == "QLineEdit") qobject_cast<QLineEdit*>(w)->setText(PI2QString(k.value()));
if (cn == "CLineEdit") qobject_cast<CLineEdit*>(w)->setText(PI2QString(k.value()));
}
updating = false;
}
int QCDCore::unbindWindow(QWidget * wnd) {
if (!wnd) return 0;
return unbindWidgets(wnd->findChildren<QWidget * >());
}
int QCDCore::unbindWidgets(QList<QWidget * > wl) {
int ret = 0;
foreach (QWidget * w, wl)
if (unbindWidget(w)) ++ret;
return ret;
}
bool QCDCore::unbindWidget(QWidget * w) {
if (!w) return false;
if (!binded_widgets.contains(w)) return false;
QString cn = w->metaObject()->className();
if (cn == "QCheckBox" || cn == "QGroupBox")
disconnect(w, SIGNAL(toggled(bool)), this, SLOT(slotBool(bool)));
if (cn == "QSpinBox" || cn == "QSlider" || cn == "QScrollBar")
disconnect(w, SIGNAL(valueChanged(int)), this, SLOT(slotInt(int)));
if (cn == "QDoubleSpinBox" || cn == "SpinSlider")
disconnect(w, SIGNAL(valueChanged(double)), this, SLOT(slotDouble(double)));
if (cn == "QLineEdit" || cn == "CLineEdit")
disconnect(w, SIGNAL(textChanged(QString)), this, SLOT(slotText(QString)));
binded_widgets.remove(w);
return true;
}
void QCDCore::unbindAllWidgets() {
QMapIterator<QWidget * , PIDeque<int> > it(binded_widgets);
while (it.hasNext()) {
QWidget * w = it.next().key();
unbindWidget(w);
}
binded_widgets.clear();
}

65
qcd_utils/qcd_core.h Normal file
View File

@@ -0,0 +1,65 @@
#ifndef QCD_CORE_H
#define QCD_CORE_H
#include <QObject>
#include <QMap>
#include "piobject.h"
class QCDCore;
class __QCore_Initializer__ {
public:
__QCore_Initializer__();
~__QCore_Initializer__();
static int count_;
static QCDCore * __instance__;
};
class QCDCore: public QObject, public PIObject
{
Q_OBJECT
PIOBJECT(QCDCore)
friend class __QCore_Initializer__;
public:
static QCDCore * instance() {return __QCore_Initializer__::__instance__;}
int bindWindow(QWidget * wnd);
int bindWidgets(QList<QWidget * > wl);
bool bindWidget(QWidget * w);
void updateBindedWidgets();
int unbindWindow(QWidget * wnd);
int unbindWidgets(QList<QWidget * > wl);
bool unbindWidget(QWidget * w);
void unbindAllWidgets();
private:
QCDCore();
~QCDCore();
EVENT_HANDLER(void, K_ChangedGlobal);
QMap<QWidget * , PIDeque<int> > binded_widgets;
bool updating;
private slots:
void slotBool(bool v);
void slotInt(int v);
void slotDouble(double v);
void slotText(QString v);
public slots:
signals:
};
static __QCore_Initializer__ __QCore_initializer__;
#endif // QCD_CORE_H

309
qcd_utils/qcd_kmodel.cpp Normal file
View File

@@ -0,0 +1,309 @@
#include "qcd_kmodel.h"
#include "cdutils_k.h"
#include "piqt.h"
#include <QDebug>
#include <QBrush>
#include <QColor>
#include "qvariantedit.h"
using namespace CDUtils;
CDKItemModel::CDKItemModel(QObject *parent) : QAbstractItemModel(parent) {
root = 0;
internalRebuild();
}
CDKItemModel::~CDKItemModel() {
delete root;
}
QVariant CDKItemModel::data(const QModelIndex &index, int role) const {
if (!index.isValid()) return QVariant();
CDKItem *item = getItem(index);
return item->data(index.column(), role);
}
QVariant CDKItemModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) {
case 0: return trUtf8("Index");
case 1: return trUtf8("Name");
case 2: return trUtf8("Type");
case 3: return trUtf8("Expression");
case 4: return trUtf8("Value");
case 5: return trUtf8("Comment");
}
}
return QVariant();
}
QModelIndex CDKItemModel::index(int row, int column, const QModelIndex &parent) const {
if (parent.isValid() && parent.column() != 0) return QModelIndex();
CDKItem * p = getItem(parent);
CDKItem * c = p->childs.value(row, 0);
if (c) return createIndex(row, column, c);
else return QModelIndex();
}
QModelIndex CDKItemModel::parent(const QModelIndex &index) const {
if (!index.isValid()) return QModelIndex();
CDKItem * c = getItem(index);
CDKItem * p = c->parent_;
if (p == root) return QModelIndex();
return createIndex(p->parent_->childs.indexOf(p), 0, p);
}
int CDKItemModel::rowCount(const QModelIndex &parent) const {
CDKItem *p = getItem(parent);
return p->childs.count();
}
int CDKItemModel::columnCount(const QModelIndex &parent) const {
return 6;
}
Qt::ItemFlags CDKItemModel::flags(const QModelIndex &index) const {
if (!index.isValid()) return 0;
Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
CDKItem * item = getItem(index);
if ((index.column() == 3 || index.column() == 4) && item->type_ == CDKItem::ItemCDType) f |= Qt::ItemIsEditable;
if (item->type_ == CDKItem::ItemCDType && index.column() == 4) {
CDType t = K.section(item->buildPath())[item->index_];
if (t.type() == "b") {
f |= Qt::ItemIsUserCheckable;
// piCout << "ItemIsUserCheckable";
}
}
return f;
}
bool CDKItemModel::setData(const QModelIndex &index, const QVariant &value, int role) {
if (role == Qt::CheckStateRole && index.column() == 4) {
CDKItem * item = getItem(index);
if (item->type_ == CDKItem::ItemCDType) {
CDType t = K.section(item->buildPath())[item->index_];
if (t.type() == "b") {
bool result = item->setData(index.column(), PI2QString(PIString::fromBool(value.toBool())));
return result;
}
}
}
if (role != Qt::EditRole) return false;
CDKItem * item = getItem(index);
bool result = item->setData(index.column(), value);
if (result) emit dataChanged(index, index);
return result;
}
void CDKItemModel::rebuildModel() {
beginResetModel();
internalRebuild();
endResetModel();
}
void CDKItemModel::buildItem(CDKItem *it, CDSection & r) {
//piCout << "build item" << r.name << r.alias;
PIMap<int, CDType>::iterator i;
for (i = r.k.begin(); i != r.k.end(); ++i) {
it->childs << new CDKItem(i.key(), CDKItem::ItemCDType, it);
}
PIMap<int, CDSection>::iterator j;
for (j = r.s.begin(); j != r.s.end(); ++j) {
it->childs << new CDKItem(j.key(), CDKItem::ItemCDSection, it);
buildItem(it->childs.back(), j.value());
}
}
void CDKItemModel::internalRebuild() {
//qDebug() << "[CDKItemModel]" << "internalRebuild()";
if (root) delete root;
root = new CDKItem(0, CDKItem::ItemCDSection, 0);
CDSection & r = K.root();
buildItem(root, r);
}
CDKItem * CDKItemModel::getItem(const QModelIndex &index) const {
if (index.isValid()) {
CDKItem * item = static_cast<CDKItem*>(index.internalPointer());
if (item) return item;
}
return root;
}
// CDKItem
CDKItem::CDKItem(int index, CDKItem::CDKItemType type, CDKItem *parent) {
index_ = index;
parent_ = parent;
type_ = type;
}
CDKItem::~CDKItem() {
qDeleteAll(childs);
}
QVariant CDKItem::data(int column, int role) const {
if (role == Qt::BackgroundRole) {
switch (type_) {
case ItemCDType: {
CDType & t = K.section(buildPath())[index_];
if (t.errorString().isEmpty()) return QBrush(QColor(255, 250, 230));
else return QBrush(QColor(255, 128, 128));
}
case ItemCDSection: return QBrush(QColor(230, 250, 230));
}
}
if (role == Qt::CheckStateRole && type_ == ItemCDType && column == 4) {
CDType & t = K.section(buildPath())[index_];
if (t.type() == "b") return t.toBool() ? Qt::Checked : Qt::Unchecked;
else QVariant();
}
if (role == Qt::ToolTipRole && type_ == ItemCDType) {
CDType & t = K.section(buildPath())[index_];
return PI2QString(t.errorString());
}
if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant();
PIDeque<int> path = buildPath();
CDSection & rs = K.section(path);
CDSection s;
switch (type_) {
case ItemCDType:
switch (column) {
case 0: return QString::number(index_);
case 1: return PI2QString(rs[index_].name());
case 2: return stringType(rs[index_].type());
case 3: return PI2QString(rs[index_].formula());
case 4: return value(rs[index_], role);
case 5: return PI2QString(rs[index_].comment());
default:
break;
}
break;
case ItemCDSection:
s = rs.section(index_);
// piCout << rs.name << rs.alias << s.name << s.alias;
switch (column) {
case 0: return QString("[") + QString::number(index_) + QString("]");
case 1: return PI2QString(s.alias);
case 2: return PI2QString(s.name);
default:
break;
}
break;
}
return QVariant();
}
QVariant CDKItem::value(CDType t, int role) const {
if (t.type() == "f") return t.toDouble();
if (t.type() == "n") return t.toInt();
if (t.type() == "b") return t.toBool();
if (t.type() == "e") {
QVariantEdit::EnumType et;
et.enum_list = PI2QStringList(t.enumValues());
et.value = et.enum_list.at(t.toInt());//et.enum_list.indexOf("");
if (role == Qt::EditRole)return QVariant::fromValue<QVariantEdit::EnumType>(et);
else return et.value;
}
return PI2QString(t.value());
}
bool CDKItem::setData(int column, const QVariant &value) {
if ((column == 3 || column == 4) && type_ == ItemCDType) {
K.section(buildPath())[index_].setValue(Q2PIString(value.toString()));
return true;
}
return false;
}
PIDeque<int> CDKItem::buildPath() const {
PIDeque<int> path;
CDKItem * p = parent_;
while (p) {
path.push_front(p->index_);
p = p->parent_;
}
path.take_front();
return path;
}
QString CDKItem::stringType(const PIString & t) const {
QString n = PI2QString(t);
if (n.isEmpty()) return QString("");
switch (n[0].toLatin1()) {
case 'l': return QString("list"); break;
case 'b': return QString("bool"); break;
case 'n': return QString("int"); break;
case 'f': return QString("double"); break;
case 'c': return QString("color"); break;
case 'r': return QString("rect"); break;
case 'a': return QString("rect"); break;
case 'p': return QString("point"); break;
case 'v': return QString("vector"); break;
case 'i': return QString("IP"); break;
case 'e': return QString("enum"); break;
case 'F': return QString("file"); break;
case 'D': return QString("dir"); break;
}
return QString("double");
}
// CDKDelegate
CDKDelegate::CDKDelegate(QObject *parent) : QStyledItemDelegate(parent) {
}
QWidget *CDKDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
return new QVariantEdit(parent);
}
void CDKDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
QVariantEdit *edit = static_cast<QVariantEdit*>(editor);
edit->setValue(index.model()->data(index, Qt::EditRole));
}
void CDKDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
QVariantEdit *edit = static_cast<QVariantEdit*>(editor);
QVariant v = edit->value();
if (v.canConvert<QVariantEdit::EnumType>()) {
QVariantEdit::EnumType et = v.value<QVariantEdit::EnumType>();
model->setData(index, et.enum_list.indexOf(et.value), Qt::EditRole);
} else model->setData(index, v, Qt::EditRole);
}
void CDKDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const {
editor->setGeometry(option.rect);
}
QSize CDKDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const {
QSize s = QStyledItemDelegate::sizeHint(option, index);
s.setWidth(s.width() + 20);
return s;
}

80
qcd_utils/qcd_kmodel.h Normal file
View File

@@ -0,0 +1,80 @@
#ifndef QCD_KMODEL_H
#define QCD_KMODEL_H
#include <QAbstractItemModel>
#include <QItemDelegate>
#include <QStyledItemDelegate>
#include "pistring.h"
namespace CDUtils {
class CDSection;
class CDType;
}
class CDKItemModel;
class CDKItem {
friend class CDKItemModel;
public:
enum CDKItemType{ItemCDType, ItemCDSection};
CDKItem(int index, CDKItemType type, CDKItem * parent);
~CDKItem();
QVariant data(int column, int role) const;
QVariant value(CDUtils::CDType t, int role) const;
bool setData(int column, const QVariant & value);
private:
PIDeque<int> buildPath() const;
QString stringType(const PIString & t) const;
CDKItem * parent_;
int index_;
CDKItemType type_;
QList<CDKItem *> childs;
};
class CDKDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
CDKDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
class CDKItemModel : public QAbstractItemModel {
Q_OBJECT
public:
explicit CDKItemModel(QObject *parent = 0);
~CDKItemModel();
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
void rebuildModel();
void buildItem(CDKItem * it, CDUtils::CDSection &r);
public slots:
private:
void internalRebuild();
CDKItem * getItem(const QModelIndex & index) const;
CDKItem * root;
signals:
};
#endif // QCD_KMODEL_H

124
qcd_utils/qcd_kview.cpp Normal file
View File

@@ -0,0 +1,124 @@
#include <QDir>
#include "cdutils_k.h"
#include "qcd_kview.h"
#include "qcd_kmodel.h"
#include "piqt.h"
#include "pifile.h"
using namespace CDUtils;
CDKView::CDKView(QWidget *parent) : QTreeView(parent) {
kmodel = 0;
CONNECTU(&K, sended, this, cdk_sendSucceed);
CONNECTU(&K, sendFailed, this, cdk_sendFailed);
CONNECTU(&K, received, this, cdk_receiveSucceed);
CONNECTU(&K, receiveFailed, this, cdk_receiveFailed);
connect(this, SIGNAL(_qcdk_sendFailed()), this, SLOT(k_sendFailed()), Qt::QueuedConnection);
connect(this, SIGNAL(_qcdk_sendSucceed()), this, SLOT(k_sendSucceed()), Qt::QueuedConnection);
connect(this, SIGNAL(_qcdk_receiveFailed()), this, SLOT(k_receiveFailed()), Qt::QueuedConnection);
connect(this, SIGNAL(_qcdk_receiveSucceed()), this, SLOT(k_receiveSucceed()), Qt::QueuedConnection);
}
CDKView::~CDKView() {
if (kmodel) delete kmodel;
kmodel = 0;
}
void CDKView::refresh() {
if (!kmodel) {
K.reinitConnection(K.pultConfig());
kmodel = new CDKItemModel();
setModel(kmodel);
setItemDelegateForColumn(4, new CDKDelegate());
}
kmodel->rebuildModel();
expandAll();
for (int i=0; i<6; i++) resizeColumnToContents(i);
}
void CDKView::setKFile(const QString &filename) {
K.setFileName(Q2PIString(filename));
}
void CDKView::startPing() {
K.startPing();
}
void CDKView::sendK() {
busyStatusChanged(true);
K.send();
}
void CDKView::receiveK() {
busyStatusChanged(true);
K.request();
}
void CDKView::saveK() {
K.writeFile();
}
void CDKView::loadK() {
K.readFile();
K.calculate();
refresh();
}
void CDKView::clearK() {
K.root() = CDSection();
refresh();
}
void CDKView::buildFromHeader(const QString &kdescription) {
if (kdescription.isEmpty()) return;
PIString kdesc_file = Q2PIString(QDir::current().relativeFilePath(kdescription));
PIFile f(kdesc_file, PIIODevice::ReadOnly);
K.update(&f);
refresh();
}
void CDKView::calculateK() {
K.calculate();
}
void CDKView::k_sendFailed() {
busyStatusChanged(false);
emit messageStatus("send failed");
emit KSendFailed();
}
void CDKView::k_sendSucceed() {
busyStatusChanged(false);
emit messageStatus("send success");
emit KSendSucceed();
}
void CDKView::k_receiveFailed() {
busyStatusChanged(false);
emit messageStatus("receive failed");
emit KReceiveFailed();
}
void CDKView::k_receiveSucceed() {
busyStatusChanged(false);
emit messageStatus("receive success");
refresh();
emit KReceiveSucceed();
}

61
qcd_utils/qcd_kview.h Normal file
View File

@@ -0,0 +1,61 @@
#ifndef QCD_KVIEW_H
#define QCD_KVIEW_H
#include "piobject.h"
#include <QTreeView>
class CDKItemModel;
class CDKView: public QTreeView, public PIObject
{
Q_OBJECT
PIOBJECT(CDKView)
public:
explicit CDKView(QWidget *parent = 0);
~CDKView();
void setKFile(const QString & filename);
void startPing();
CDKItemModel * CDKModel() {return kmodel;}
public slots:
void refresh();
void sendK();
void receiveK();
void saveK();
void loadK();
void clearK();
void buildFromHeader(const QString & kdescription);
void calculateK();
private slots:
void k_sendFailed();
void k_sendSucceed();
void k_receiveFailed();
void k_receiveSucceed();
private:
EVENT_HANDLER(void, cdk_sendFailed) {emit _qcdk_sendFailed();}
EVENT_HANDLER(void, cdk_sendSucceed) {emit _qcdk_sendSucceed();}
EVENT_HANDLER(void, cdk_receiveFailed) {emit _qcdk_receiveFailed();}
EVENT_HANDLER(void, cdk_receiveSucceed) {emit _qcdk_receiveSucceed();}
CDKItemModel * kmodel;
signals:
void KSendFailed();
void KSendSucceed();
void KReceiveFailed();
void KReceiveSucceed();
void messageStatus(QString msg);
void busyStatusChanged(bool bisy);
void _qcdk_sendFailed(); // PRIVATE
void _qcdk_sendSucceed(); // PRIVATE
void _qcdk_receiveFailed(); // PRIVATE
void _qcdk_receiveSucceed(); // PRIVATE
};
#endif // QCD_KVIEW_H