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

This commit is contained in:
2018-05-24 09:22:24 +00:00
parent 7c9a2d0db2
commit 31557d5e5c
7 changed files with 111 additions and 33 deletions

View File

@@ -181,8 +181,13 @@ void CDCore::init(const PIString & configuration, bool pult) {
}
void CDCore::stop() {
connection.stop();
}
void CDCore::startX(double freq) {
piCout << "start x" << x_timer.isRunning() << freq;
//piCout << "start x" << x_timer.isRunning() << freq;
if (!x_timer.isRunning())
x_timer.start(1000. / piMaxd(freq, 0.01));
}
@@ -194,7 +199,7 @@ void CDCore::stopX() {
void CDCore::sendCommand(const CDType & c) {
piCoutObj << "C_sendCommand" << c;
//piCoutObj << "C_sendCommand" << c;
PIByteArray sba = makeHeader(CD_Command, 0);
sba << c.path();
sendDirect(sba);
@@ -204,7 +209,7 @@ void CDCore::sendCommand(const CDType & c) {
void CDCore::registerCHandler(const CDType & c, PIObject * o, Handler h) {
PIString sp = pathToString(c.path());
if (sp.isEmpty() || !h) return;
piCout << "register" << sp;
//piCout << "register" << sp;
c_handlers[sp] = OHPair(o, h);
}
@@ -432,14 +437,14 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
} break;
case CD_XValues: {
if (!x_pult_side) break;
x_mutex.lock();
PIVector<PIDeque<int> > x_vals;
ba >> x_vals;
x_mutex.lock();
piForeachC (PIDeque<int> & p, x_vals) {
x_[p].readX(ba);
}
X_ReceivedX(x_vals); /// WARNING! under mutex
x_mutex.unlock();
X_ReceivedX(x_vals);
} break;
case CD_CQuery:
C_Send();

View File

@@ -64,6 +64,7 @@ public:
void initApp();
void initPult();
void init(const PIString & configuration, bool pult = false);
void stop();
void startX(double freq = 20.);
void stopX();
void sendCommand(const CDType & c);

View File

@@ -295,6 +295,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
int tcpos = 0;
switch (e->type()) {
case QEvent::MouseButtonPress:
if (!isEnabled()) break;
tc = ui->textCode->cursorForPosition(((QMouseEvent*)e)->pos());
tc.movePosition(QTextCursor::EndOfLine);
pos_el_press = tc.anchor();
@@ -305,6 +306,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
ui->textCode->setTextCursor(tc);
return true;
case QEvent::MouseMove:
if (!isEnabled()) break;
tc = ui->textCode->cursorForPosition(((QMouseEvent*)e)->pos());
tc.movePosition(QTextCursor::StartOfLine);
if (pos_press == tc.anchor()) {
@@ -323,6 +325,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
ui->textCode->setTextCursor(tc);
return true;
case QEvent::Wheel:
if (!isEnabled()) break;
QApplication::sendEvent(ui->textCode->viewport(), e);
return true;
default: break;

View File

@@ -3,7 +3,7 @@ find_qt(${QtVersions} Core Gui OpenGL)
qt_sources(SRC)
qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
qt_add_executable(${PROJECT_NAME} WIN32 out_CPP)
qt_target_link_libraries(${PROJECT_NAME} qad_utils qad_widgets qad_graphic qcd_utils qad_application)
qt_target_link_libraries(${PROJECT_NAME} qad_utils qad_widgets qad_graphic qad_application qcd_utils piqt_utils)
message(STATUS "Building ${PROJECT_NAME}")
if(LIB)
if(WIN32)

View File

@@ -9,14 +9,20 @@
#include "qcd_modedialog.h"
#include "chunkstream.h"
#include "qvariantedit.h"
#include "piqt.h"
#include "piqt_highlighter.h"
#include "qcodeedit.h"
#include <QFileDialog>
#include <QScrollBar>
using namespace CDUtils;
CDPultWindow::CDPultWindow(QWidget *parent) : EMainWindow(parent), Ui::CDPultWindow() {
setupUi(this);
centralWidget()->hide();
CDUtils::CDCore::instance()->initPult();
CDCore::instance()->initPult();
new ConfigHighlighter(codeConfig->document());
widgetK->setType(CDUtils::CDType::cdK);
widgetX->setType(CDUtils::CDType::cdX);
widgetC->setType(CDUtils::CDType::cdC);
@@ -51,6 +57,34 @@ void CDPultWindow::loadFile(const QString & fp) {
}
void CDPultWindow::apply(bool sessions) {
CDCore::instance()->stop();
widgetK->setFile(editFileK->value().value<QAD::File>().file);
widgetX->setFile(editFileX->value().value<QAD::File>().file);
widgetC->setFile(editFileC->value().value<QAD::File>().file);
if (checkDefaultConfig->isChecked())
CDCore::instance()->initPult();
else
CDCore::instance()->init(Q2PIString(codeConfig->text()), true);
widgetX->view->startX();
if (sessions) {
widgetGraphics->load(session_gr);
if (!session_mw.isEmpty())
restoreState(session_mw);
X.lock();
PIVector<PIDeque<int> > x_list = X.enabledList();
X.unlock();
piForeachC (PIDeque<int> & p, x_list)
X.enable(X[p]);
((CDItemModel*)widgetX->view->model())->updateModel();
widgetX->view->expandAll();
}
dockCDKView->setVisible(checkHasK->isChecked());
dockCDXView->setVisible(checkHasX->isChecked());
dockCDCView->setVisible(checkHasC->isChecked());
}
void CDPultWindow::closeEvent(QCloseEvent *e) {
EMainWindow::closeEvent(e);
if (!e->isAccepted())
@@ -80,15 +114,20 @@ bool CDPultWindow::load(const QString & path) {
checkHasK->setChecked(conf.getValue("has_k"));
checkHasX->setChecked(conf.getValue("has_x"));
checkHasC->setChecked(conf.getValue("has_c"));
checkDefaultConfig->setChecked(conf.getValue("default_config"));
codeConfig->setText(QByteArray2QString(conf.getValue("config", QByteArray())));
session_gr = conf.getValue("session_gr", QByteArray());
session_mw = conf.getValue("session_mw", QByteArray());
setChanged(false);
file_name = path;
apply(true);
return true;
}
bool CDPultWindow::save(const QString & path) {
session_gr = widgetGraphics->save();
session_mw = saveState();
QPIConfig conf(path, QIODevice::ReadWrite);
conf.clear();
conf.setValue("file_k", editFileK->value().value<QAD::File>().file);
@@ -99,7 +138,11 @@ bool CDPultWindow::save(const QString & path) {
conf.setValue("has_k", checkHasK->isChecked());
conf.setValue("has_x", checkHasX->isChecked());
conf.setValue("has_c", checkHasC->isChecked());
conf.setValue("has_c", checkHasC->isChecked());
conf.setValue("default_config", checkDefaultConfig->isChecked());
conf.setValue("config", QString2QByteArray(codeConfig->text()));
conf.setValue("session_gr", session_gr);
conf.setValue("session_mw", session_mw);
file_name = path;
return true;
@@ -160,22 +203,7 @@ void CDPultWindow::on_editFileK_valueChanged(const QVariant & p) {
void CDPultWindow::on_buttonSessionApply_clicked() {
// with session or not
widgetK->setFile(editFileK->value().value<QAD::File>().file);
widgetX->setFile(editFileX->value().value<QAD::File>().file);
widgetC->setFile(editFileC->value().value<QAD::File>().file);
dockCDKView->setVisible(checkHasK->isChecked());
dockCDXView->setVisible(checkHasX->isChecked());
dockCDCView->setVisible(checkHasC->isChecked());
widgetX->view->startX();
widgetGraphics->load(session_gr);
X.lock();
PIVector<PIDeque<int> > x_list = X.enabledList();
X.unlock();
piForeachC (PIDeque<int> & p, x_list)
X.enable(X[p]);
((CDItemModel*)widgetX->view->model())->updateModel();
widgetX->view->expandAll();
apply(false);
}

View File

@@ -17,6 +17,7 @@ public:
explicit CDPultWindow(QWidget *parent = 0);
~CDPultWindow();
void loadFile(const QString & fp);
void apply(bool sessions);
private:
@@ -31,7 +32,7 @@ private:
Ribbon * ribbon;
QMap<CDViewWidget::LogIcon, QIcon> log_icons;
QByteArray session_gr;
QByteArray session_gr, session_mw;
private slots:
void addToLog(CDViewWidget::LogIcon icon, const QString & msg);

View File

@@ -278,20 +278,37 @@
</item>
</layout>
</item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="checkDefaultConfig">
<property name="text">
<string>Default config</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<widget class="QCodeEdit" name="codeConfig">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
<property name="text">
<string>include = ip.conf
[connection]
device.cd = eth://udp:${ip.pult}:27002:${ip.app}:27001 #s
[]
</string>
</property>
</spacer>
<property name="editorFont">
<font>
<family>DejaVu Sans Mono</family>
<pointsize>9</pointsize>
</font>
</property>
</widget>
</item>
</layout>
</widget>
@@ -445,6 +462,8 @@
<addaction name="separator"/>
<addaction name="separator"/>
<addaction name="separator"/>
<addaction name="separator"/>
<addaction name="separator"/>
</widget>
<customwidgets>
<customwidget>
@@ -458,6 +477,11 @@
<extends>QLineEdit</extends>
<header>clineedit.h</header>
</customwidget>
<customwidget>
<class>QCodeEdit</class>
<extends>QWidget</extends>
<header>qcodeedit.h</header>
</customwidget>
<customwidget>
<class>QVariantEdit</class>
<extends>QWidget</extends>
@@ -618,5 +642,21 @@
</hint>
</hints>
</connection>
<connection>
<sender>checkDefaultConfig</sender>
<signal>toggled(bool)</signal>
<receiver>codeConfig</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>579</x>
<y>280</y>
</hint>
<hint type="destinationlabel">
<x>581</x>
<y>304</y>
</hint>
</hints>
</connection>
</connections>
</ui>