code format

This commit is contained in:
2022-12-14 14:13:33 +03:00
parent 37480c9d1f
commit 2622737a52
39 changed files with 1295 additions and 1265 deletions

View File

@@ -1,4 +1,5 @@
#include "cdutils_c.h" #include "cdutils_c.h"
#include "cdutils_core.h" #include "cdutils_core.h"
using namespace CDUtils; using namespace CDUtils;
@@ -6,8 +7,7 @@ using namespace CDUtils;
CInterface C; CInterface C;
CInterface::CInterface(): Interface(CDType::cdC) { CInterface::CInterface(): Interface(CDType::cdC) {}
}
void CInterface::sendCommand(const CDType & c) { void CInterface::sendCommand(const CDType & c) {
@@ -28,10 +28,10 @@ void CInterface::autoConnect(PIObject * o, const PIString & prefix) {
PIObject::__MetaData & md(PIObject::__meta_data()[cid]); PIObject::__MetaData & md(PIObject::__meta_data()[cid]);
for (auto it = md.eh_func.begin(); it != md.eh_func.end(); ++it) { for (auto it = md.eh_func.begin(); it != md.eh_func.end(); ++it) {
eh_map[it.value().func_name] = (Handler)it.value().addr; eh_map[it.value().func_name] = (Handler)it.value().addr;
//piCout << "func" << it.value().func_name; // piCout << "func" << it.value().func_name;
} }
PIVector<CDType * > cl = C.root().children(); PIVector<CDType *> cl = C.root().children();
piForeachC (CDType * c, cl) { piForeachC(CDType * c, cl) {
PIString cp = prefix + c->pathString().join("_"); PIString cp = prefix + c->pathString().join("_");
if (cp.isEmpty()) continue; if (cp.isEmpty()) continue;
if (!eh_map.contains(cp)) continue; if (!eh_map.contains(cp)) continue;

View File

@@ -1,45 +1,44 @@
/* /*
CD Utils - Control-Debug utilites CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CDUTILS_C_H #ifndef CDUTILS_C_H
#define CDUTILS_C_H #define CDUTILS_C_H
#include "cdutils_interface.h"
#include "cdutils_core.h" #include "cdutils_core.h"
#include "cdutils_interface.h"
namespace CDUtils { namespace CDUtils {
class CD_CORE_EXPORT CInterface: public Interface class CD_CORE_EXPORT CInterface: public Interface {
{
PIOBJECT_SUBCLASS(CInterface, Interface); PIOBJECT_SUBCLASS(CInterface, Interface);
public: public:
CInterface(); CInterface();
void sendCommand(const CDType & c); void sendCommand(const CDType & c);
void connect(const CDType & c, PIObject * o, Handler eh); void connect(const CDType & c, PIObject * o, Handler eh);
void autoConnect(PIObject * o, const PIString & prefix = PIStringAscii("c_")); void autoConnect(PIObject * o, const PIString & prefix = PIStringAscii("c_"));
}; };
} } // namespace CDUtils
extern CD_CORE_EXPORT CDUtils::CInterface C; extern CD_CORE_EXPORT CDUtils::CInterface C;

View File

@@ -1,14 +1,14 @@
#include "cdutils_core.h" #include "cdutils_core.h"
#include "cdutils_parser.h" #include "cdutils_parser.h"
#include "piconfig.h" #include "piconfig.h"
#include "pifile.h"
#include "piiobytearray.h" #include "piiobytearray.h"
#include "piiostring.h" #include "piiostring.h"
#include "pifile.h"
using namespace CDUtils; using namespace CDUtils;
const char CDCore::app_config[] = const char CDCore::app_config[] = "include = cd_ip.conf\n\
"include = cd_ip.conf\n\
port_rec = 2\n\ port_rec = 2\n\
port_send = 1\n\ port_send = 1\n\
[connection]\n\ [connection]\n\
@@ -17,8 +17,7 @@ const char CDCore::app_config[] =
connectionmodel = AAAM2Xja7VXLTttAFD12QpsikKjUSixYlLbKEpIUtVIlVEfqhk2FWuiGRRolUYtoHgrmpYiv6IItf8AveMMH9E/YsG6Ph3sde5hGoQoblLGuPHfunTPjc49nADxDA110+LTYC7FrPCAPeAO+vZu+aX7c/8PGd45WCJC0OGcfT6FDnmfSTPtwhZFt3HjgDs/Qtu5jPbZHtI/x50XfIzMQbdwEolbg9INP4ku++myPaUtCHYRaT2j1ldIh3VP60/Qff8vSfXLu9BP6JX9K/0TVH6jqVe22P1X/fao/oddWu/paDs1vBf9Jv/EZ91clbyHqv7BL6sscDOd4v4WTqs6jzaHGJ8QJerxlpJSpdZ7IWFJvDW7I2JxZqIM62k6A57RZmMQGmlyrxdV+WGBnmR01mXPI267hBKwp4FeBeo9VPtssxyb7rzHg1B7T9nCMU45U8BZlWuVWtIcD/CRGOqtsbW09851tXsHN0UTlLIAdASjSXnLyLn+H7L2+xbGYvC63Ezqg543egkLmn8qnRF6USbM4Qp9godkhzI777Ne5bCIt/5UtGz2o/yGby0nKpjqmbOa1ynkjmyzIrzvIZUeBPjvlUmbh32EFJbGyJZhR8YcvlS+3TpjhqeWSyvUkpbI9plSWtcKLcsK05beOJVEnhaEFfHEH+RwpeMcpn1JKGqWMNOL+G6wZyahlpdVOtufKfbDS+guLke9O\n\ connectionmodel = AAAM2Xja7VXLTttAFD12QpsikKjUSixYlLbKEpIUtVIlVEfqhk2FWuiGRRolUYtoHgrmpYiv6IItf8AveMMH9E/YsG6Ph3sde5hGoQoblLGuPHfunTPjc49nADxDA110+LTYC7FrPCAPeAO+vZu+aX7c/8PGd45WCJC0OGcfT6FDnmfSTPtwhZFt3HjgDs/Qtu5jPbZHtI/x50XfIzMQbdwEolbg9INP4ku++myPaUtCHYRaT2j1ldIh3VP60/Qff8vSfXLu9BP6JX9K/0TVH6jqVe22P1X/fao/oddWu/paDs1vBf9Jv/EZ91clbyHqv7BL6sscDOd4v4WTqs6jzaHGJ8QJerxlpJSpdZ7IWFJvDW7I2JxZqIM62k6A57RZmMQGmlyrxdV+WGBnmR01mXPI267hBKwp4FeBeo9VPtssxyb7rzHg1B7T9nCMU45U8BZlWuVWtIcD/CRGOqtsbW09851tXsHN0UTlLIAdASjSXnLyLn+H7L2+xbGYvC63Ezqg543egkLmn8qnRF6USbM4Qp9godkhzI777Ne5bCIt/5UtGz2o/yGby0nKpjqmbOa1ynkjmyzIrzvIZUeBPjvlUmbh32EFJbGyJZhR8YcvlS+3TpjhqeWSyvUkpbI9plSWtcKLcsK05beOJVEnhaEFfHEH+RwpeMcpn1JKGqWMNOL+G6wZyahlpdVOtufKfbDS+guLke9O\n\
"; ";
const char CDCore::pult_config[] = const char CDCore::pult_config[] = "include = cd_ip.conf\n\
"include = cd_ip.conf\n\
port_rec = 1\n\ port_rec = 1\n\
port_send = 2\n\ port_send = 2\n\
[connection]\n\ [connection]\n\
@@ -55,8 +54,6 @@ __Core_Initializer__::~__Core_Initializer__() {
} }
CDCore::CDCore() { CDCore::CDCore() {
setName("CDCore"); setName("CDCore");
x_timer.setName("__S__.CDCore.x_timer"); x_timer.setName("__S__.CDCore.x_timer");
@@ -67,10 +64,10 @@ CDCore::CDCore() {
connection.configureFromString(&s); connection.configureFromString(&s);
connection.start();*/ connection.start();*/
need_rebuild_x = x_pult_side = false; need_rebuild_x = x_pult_side = false;
k_.cd_type_ = CDType::cdK; k_.cd_type_ = CDType::cdK;
x_.cd_type_ = CDType::cdX; x_.cd_type_ = CDType::cdX;
c_.cd_type_ = CDType::cdC; c_.cd_type_ = CDType::cdC;
m_.cd_type_ = CDType::cdM; m_.cd_type_ = CDType::cdM;
initRoot(&k_); initRoot(&k_);
initRoot(&x_); initRoot(&x_);
initRoot(&c_); initRoot(&c_);
@@ -89,7 +86,7 @@ CDCore::CDCore() {
k_.section(11)[3] = KType(3, "1", "1", "88"); k_.section(11)[3] = KType(3, "1", "1", "88");
k_.section(11)[4] = KType(4, "0", "0", "88"); k_.section(11)[4] = KType(4, "0", "0", "88");
k_.section(11)[6] = KType(6, "0", "0", "88");*/ k_.section(11)[6] = KType(6, "0", "0", "88");*/
//piCout << s; // piCout << s;
} }
@@ -110,14 +107,13 @@ void CDCore::cd_write(CDSection * cd, PIIODevice * d) {
void CDCore::cd_read(CDSection * cd, PIIODevice * d) { void CDCore::cd_read(CDSection * cd, PIIODevice * d) {
PIConfig conf(d, PIIODevice::ReadOnly); PIConfig conf(d, PIIODevice::ReadOnly);
cd->read(&(conf.rootEntry())); cd->read(&(conf.rootEntry()));
if (cd->cd_type_ == CDType::cdX) if (cd->cd_type_ == CDType::cdX) x_selected = cd->collectX();
x_selected = cd->collectX();
initRoot(cd); initRoot(cd);
raiseChangedGlobal(cd->cd_type_); raiseChangedGlobal(cd->cd_type_);
/*PIVector<PIIODevice * > ds = connection.allDevices(); /*PIVector<PIIODevice * > ds = connection.allDevices();
piForeach(PIIODevice * d, ds) { piForeach(PIIODevice * d, ds) {
if (d) if (d)
piCoutObj << d->constructFullPath() << d->isOpened(); piCoutObj << d->constructFullPath() << d->isOpened();
}*/ }*/
} }
@@ -134,12 +130,12 @@ void CDCore::cd_update(CDSection * cd, PIIODevice * d, UpdateModeFlags mode) {
cd_parse(cd, d); cd_parse(cd, d);
/*bool kn = true; /*bool kn = true;
if (!ucd.isEmpty()) if (!ucd.isEmpty())
if (!ucd.isSameStructure(k_)) { if (!ucd.isSameStructure(k_)) {
piCout << "ask for save names"; piCout << "ask for save names";
K_KeepNamesRequest(&kn); K_KeepNamesRequest(&kn);
}*/ }*/
ucd.update(*cd, mode); ucd.update(*cd, mode);
//piCout << k_.count() << ucd.count(); // piCout << k_.count() << ucd.count();
*cd = ucd; *cd = ucd;
initRoot(cd); initRoot(cd);
raiseChangedGlobal(cd->cd_type_); raiseChangedGlobal(cd->cd_type_);
@@ -157,7 +153,7 @@ void CDCore::cd_send(CDSection * cd, CDPacketType pt, bool direct) {
PIByteArray ba, sba; PIByteArray ba, sba;
PIIOByteArray iob(&ba, PIIODevice::ReadWrite); PIIOByteArray iob(&ba, PIIODevice::ReadWrite);
cd_write(cd, &iob); cd_write(cd, &iob);
//piCoutObj << PIString(ba); // piCoutObj << PIString(ba);
sba = makeHeader(pt, 0); sba = makeHeader(pt, 0);
sba << ba; sba << ba;
if (direct) if (direct)
@@ -208,7 +204,7 @@ void CDCore::initPult() {
void CDCore::init(const PIString & configuration, bool pult) { void CDCore::init(const PIString & configuration, bool pult) {
PIString c = configuration; PIString c = configuration;
//piCoutObj << "init" << c; // piCoutObj << "init" << c;
connection.stop(); connection.stop();
connection.removeAllDevices(); connection.removeAllDevices();
connection.configureFromString(&c); connection.configureFromString(&c);
@@ -230,9 +226,8 @@ void CDCore::release() {
void CDCore::startX(double freq) { void CDCore::startX(double freq) {
//piCout << "start x" << x_timer.isRunning() << freq; // piCout << "start x" << x_timer.isRunning() << freq;
if (!x_timer.isRunning()) if (!x_timer.isRunning()) x_timer.start(1000. / piMaxd(freq, 0.01));
x_timer.start(1000. / piMaxd(freq, 0.01));
} }
@@ -242,7 +237,7 @@ void CDCore::stopX() {
void CDCore::sendCommand(const CDType & c) { void CDCore::sendCommand(const CDType & c) {
//piCoutObj << "C_sendCommand" << c; // piCoutObj << "C_sendCommand" << c;
PIByteArray sba = makeHeader(CD_Command, 0); PIByteArray sba = makeHeader(CD_Command, 0);
sba << c.path(); sba << c.path();
sendDirect(sba); sendDirect(sba);
@@ -252,7 +247,7 @@ void CDCore::sendCommand(const CDType & c) {
void CDCore::registerCHandler(const CDType & c, PIObject * o, Handler h) { void CDCore::registerCHandler(const CDType & c, PIObject * o, Handler h) {
PIString sp = pathToString(c.path()); PIString sp = pathToString(c.path());
if (sp.isEmpty() || !h) return; if (sp.isEmpty() || !h) return;
//piCout << "register" << sp; // piCout << "register" << sp;
c_handlers[sp] = OHPair(o, h); c_handlers[sp] = OHPair(o, h);
} }
@@ -298,20 +293,20 @@ CDCore * CDCore::instance() {
bool CDCore::destroy() { bool CDCore::destroy() {
if (!__Core_Initializer__::__instance__) return false; if (!__Core_Initializer__::__instance__) return false;
// piCout << "delete Core ..."; // piCout << "delete Core ...";
delete __Core_Initializer__::__instance__; delete __Core_Initializer__::__instance__;
// piCout << "delete Core ok"; // piCout << "delete Core ok";
__Core_Initializer__::__instance__ = 0; __Core_Initializer__::__instance__ = 0;
__Core_Initializer__::count_ = 0; __Core_Initializer__::count_ = 0;
return true; return true;
} }
void CDUtils::CDCore::K_DirectChange(PIDeque<int> path, PIString value) { void CDUtils::CDCore::K_DirectChange(PIDeque<int> path, PIString value) {
// piCoutObj << "K_DirectChange"; // piCoutObj << "K_DirectChange";
PacketKDirectChange p; PacketKDirectChange p;
p.path = path; p.path = path;
p.value = value; p.value = value;
PIByteArray sba = makeHeader(CD_KDirectChange, 0); PIByteArray sba = makeHeader(CD_KDirectChange, 0);
sba << p; sba << p;
sendDirect(sba); sendDirect(sba);
@@ -325,29 +320,37 @@ void CDCore::sendThread() {
bool ok = datatr.send(send_data); bool ok = datatr.send(send_data);
switch (h.type) { switch (h.type) {
case CD_KSend: case CD_KSend:
if (ok) K_Sended(); if (ok)
else K_SendFail(); K_Sended();
else
K_SendFail();
break; break;
case CD_KQuery: case CD_KQuery:
if (!ok) K_ReceiveFail(); if (!ok) K_ReceiveFail();
break; break;
case CD_XSend: case CD_XSend:
if (ok) X_Sended(); if (ok)
else X_SendFail(); X_Sended();
else
X_SendFail();
break; break;
case CD_XQuery: case CD_XQuery:
if (!ok) X_ReceiveFail(); if (!ok) X_ReceiveFail();
break; break;
case CD_CSend: case CD_CSend:
if (ok) C_Sended(); if (ok)
else C_SendFail(); C_Sended();
else
C_SendFail();
break; break;
case CD_CQuery: case CD_CQuery:
if (!ok) C_ReceiveFail(); if (!ok) C_ReceiveFail();
break; break;
case CD_MSend: case CD_MSend:
if (ok) M_Sended(); if (ok)
else M_SendFail(); M_Sended();
else
M_SendFail();
break; break;
case CD_MQuery: case CD_MQuery:
if (!ok) M_ReceiveFail(); if (!ok) M_ReceiveFail();
@@ -358,25 +361,25 @@ void CDCore::sendThread() {
void CDCore::xTimerTick() { void CDCore::xTimerTick() {
//piCout << "x tick" << x_pult_side; // piCout << "x tick" << x_pult_side;
PIByteArray ba; PIByteArray ba;
x_mutex.lock(); x_mutex.lock();
if (x_pult_side) { if (x_pult_side) {
ba = makeHeader(CD_XRequest, 0); ba = makeHeader(CD_XRequest, 0);
if (need_rebuild_x) { if (need_rebuild_x) {
x_selected = x_.collectX(); x_selected = x_.collectX();
//piCout << "collectX" << x_selected.size(); // piCout << "collectX" << x_selected.size();
need_rebuild_x = false; need_rebuild_x = false;
} }
ba << x_selected; ba << x_selected;
//piCout << "x pult send" << x_selected.size(); // piCout << "x pult send" << x_selected.size();
} else { } else {
ba = makeHeader(CD_XValues, 0); ba = makeHeader(CD_XValues, 0);
ba << x_selected; ba << x_selected;
piForeachC (PIDeque<int> & p, x_selected) { piForeachC(PIDeque<int> & p, x_selected) {
x_[p].writeX(ba); x_[p].writeX(ba);
} }
//piCout << "x app" << x_selected.size(); // piCout << "x app" << x_selected.size();
} }
x_mutex.unlock(); x_mutex.unlock();
sendDirect(ba); sendDirect(ba);
@@ -385,7 +388,7 @@ void CDCore::xTimerTick() {
void CDCore::piCoutFinished(int id, PIString * buffer) { void CDCore::piCoutFinished(int id, PIString * buffer) {
if (!buffer || !(id == 1)) return; if (!buffer || !(id == 1)) return;
PIString sp = buffer->takeRange("[", "]"); PIString sp = buffer->takeRange("[", "]");
PIDeque<int> p = CDCore::stringToPath(sp); PIDeque<int> p = CDCore::stringToPath(sp);
sendMessage(m_[p], Log, *buffer); sendMessage(m_[p], Log, *buffer);
delete buffer; delete buffer;
@@ -393,7 +396,7 @@ void CDCore::piCoutFinished(int id, PIString * buffer) {
void CDCore::initRoot(CDSection * r) { void CDCore::initRoot(CDSection * r) {
r->name = "__root__"; r->name = "__root__";
r->alias = "root"; r->alias = "root";
r->makePath(); r->makePath();
r->calculate(); r->calculate();
@@ -402,9 +405,10 @@ void CDCore::initRoot(CDSection * r) {
PIByteArray CDCore::makeHeader(CDPacketType type, int session_id) const { PIByteArray CDCore::makeHeader(CDPacketType type, int session_id) const {
PacketHeader h; PacketHeader h;
h.type = type; h.type = type;
h.session_id = session_id; h.session_id = session_id;
PIByteArray ret; ret << h; PIByteArray ret;
ret << h;
return ret; return ret;
} }
@@ -428,13 +432,11 @@ void CDCore::sendThreaded(PIByteArray & ba) {
void CDCore::procReceivedPacket(PIByteArray & ba) { void CDCore::procReceivedPacket(PIByteArray & ba) {
PacketHeader h; PacketHeader h;
ba >> h; ba >> h;
switch(h.type) { switch (h.type) {
case CD_Ping: case CD_Ping:
//piCoutObj << "ping"; // piCoutObj << "ping";
break;
case CD_KQuery:
send(CDType::cdK);
break; break;
case CD_KQuery: send(CDType::cdK); break;
case CD_KSend: { case CD_KSend: {
PIByteArray k; PIByteArray k;
ba >> k; ba >> k;
@@ -444,15 +446,13 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
cd_read(&k_, &ios); cd_read(&k_, &ios);
K_Received(); K_Received();
piCoutObj << "K received"; piCoutObj << "K received";
} break; } break;
case CD_KDirectChange: { case CD_KDirectChange: {
PacketKDirectChange p; PacketKDirectChange p;
ba >> p; ba >> p;
k_[p.path].setValue(p.value); k_[p.path].setValue(p.value);
} break; } break;
case CD_XQuery: case CD_XQuery: send(CDType::cdX); break;
send(CDType::cdX);
break;
case CD_XSend: { case CD_XSend: {
PIByteArray x; PIByteArray x;
ba >> x; ba >> x;
@@ -463,34 +463,32 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
x_selected = x_.collectX(); x_selected = x_.collectX();
X_Received(); X_Received();
piCoutObj << "X received"; piCoutObj << "X received";
} break; } break;
case CD_XRequest: { case CD_XRequest: {
if (x_pult_side) break; if (x_pult_side) break;
//break; // break;
x_mutex.lock(); x_mutex.lock();
x_selected.clear(); x_selected.clear();
ba >> x_selected; ba >> x_selected;
//piCout << "X req" << x_selected.size(); // piCout << "X req" << x_selected.size();
x_.setSelectedX(false); x_.setSelectedX(false);
piForeachC (PIDeque<int> & p, x_selected) { piForeachC(PIDeque<int> & p, x_selected) {
x_[p].x_enabled = true; x_[p].x_enabled = true;
} }
x_mutex.unlock(); x_mutex.unlock();
} break; } break;
case CD_XValues: { case CD_XValues: {
if (!x_pult_side) break; if (!x_pult_side) break;
PIVector<PIDeque<int> > x_vals; PIVector<PIDeque<int>> x_vals;
ba >> x_vals; ba >> x_vals;
x_mutex.lock(); x_mutex.lock();
piForeachC (PIDeque<int> & p, x_vals) { piForeachC(PIDeque<int> & p, x_vals) {
x_[p].readX(ba); x_[p].readX(ba);
} }
x_mutex.unlock(); x_mutex.unlock();
X_ReceivedX(x_vals); X_ReceivedX(x_vals);
} break; } break;
case CD_CQuery: case CD_CQuery: send(CDType::cdC); break;
send(CDType::cdC);
break;
case CD_CSend: { case CD_CSend: {
piCoutObj << "C received"; piCoutObj << "C received";
PIByteArray c; PIByteArray c;
@@ -500,20 +498,18 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
PIIOString ios(&s); PIIOString ios(&s);
cd_read(&c_, &ios); cd_read(&c_, &ios);
C_Received(); C_Received();
} break; } break;
case CD_Command: { case CD_Command: {
piCoutObj << "C command"; piCoutObj << "C command";
PIDeque<int> p; PIDeque<int> p;
ba >> p; ba >> p;
if (p.isEmpty()) return; if (p.isEmpty()) return;
PIString sp = pathToString(p); PIString sp = pathToString(p);
OHPair h = c_handlers.value(sp, OHPair(0, 0)); OHPair h = c_handlers.value(sp, OHPair(0, 0));
//piCoutObj << "found" << sp << h.first; // piCoutObj << "found" << sp << h.first;
if (h.first && h.second) h.second(h.first); if (h.first && h.second) h.second(h.first);
} break; } break;
case CD_MQuery: case CD_MQuery: send(CDType::cdM); break;
send(CDType::cdM);
break;
case CD_MSend: { case CD_MSend: {
piCoutObj << "M received"; piCoutObj << "M received";
PIByteArray c; PIByteArray c;
@@ -523,7 +519,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
PIIOString ios(&s); PIIOString ios(&s);
cd_read(&m_, &ios); cd_read(&m_, &ios);
M_Received(); M_Received();
} break; } break;
case CD_Message: { case CD_Message: {
PIDeque<int> p; PIDeque<int> p;
ba >> p; ba >> p;
@@ -532,10 +528,10 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
int t = 0; int t = 0;
PIString msg; PIString msg;
ba >> t >> msg; ba >> t >> msg;
//piCoutObj << "found" << sp << h.first; // piCoutObj << "found" << sp << h.first;
//piCoutObj << "M message invoke"; // piCoutObj << "M message invoke";
M_Message(p, t, msg); M_Message(p, t, msg);
} break; } break;
default: break; default: break;
} }
} }
@@ -565,19 +561,19 @@ PIString CDCore::pathToString(const PIDeque<int> & p) {
PIDeque<int> CDCore::stringToPath(const PIString & p) { PIDeque<int> CDCore::stringToPath(const PIString & p) {
PIDeque<int> ret; PIDeque<int> ret;
PIStringList sl = p.split("."); PIStringList sl = p.split(".");
piForeachC (PIString & s, sl) piForeachC(PIString & s, sl)
ret << s.toInt(); ret << s.toInt();
return ret; return ret;
} }
void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & data) { void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & data) {
//piCoutObj << "dataReceived" << from << data.size(); // piCoutObj << "dataReceived" << from << data.size();
PIIODevice * d = connection.deviceByName("cd"); PIIODevice * d = connection.deviceByName("cd");
if (d && d == connection.deviceByFullPath(from)) { if (d && d == connection.deviceByFullPath(from)) {
if (data.size() >= sizeof(4)) { if (data.size() >= sizeof(4)) {
PIByteArray ba = data; PIByteArray ba = data;
uchar header = ba.take_front(); uchar header = ba.take_front();
if (header == header_transfer) { if (header == header_transfer) {
datatr.received(ba); datatr.received(ba);
} }
@@ -592,7 +588,7 @@ void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & da
void CDCore::dtSendRequest(PIByteArray & data) { void CDCore::dtSendRequest(PIByteArray & data) {
data.push_front(header_transfer); data.push_front(header_transfer);
connection.writeByName("cd", data); connection.writeByName("cd", data);
//piCoutObj << "send" << data.size() << ret; // piCoutObj << "send" << data.size() << ret;
} }
@@ -601,4 +597,3 @@ void CDCore::dtReceiveFinished(bool ok) {
PIByteArray ba = datatr.data(); PIByteArray ba = datatr.data();
procReceivedPacket(ba); procReceivedPacket(ba);
} }

View File

@@ -1,37 +1,37 @@
/* /*
CD Utils - Control-Debug utilites CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CDUTILS_CORE_H #ifndef CDUTILS_CORE_H
#define CDUTILS_CORE_H #define CDUTILS_CORE_H
#include "cdutils_types.h" #include "cd_core_export.h"
#include "cdutils_protocol.h" #include "cdutils_protocol.h"
#include "cdutils_types.h"
#include "piconnection.h" #include "piconnection.h"
#include "pidatatransfer.h" #include "pidatatransfer.h"
#include "cd_core_export.h"
namespace CDUtils { namespace CDUtils {
class CDCore; class CDCore;
typedef void (*Handler)(void*); typedef void (*Handler)(void *);
class CD_CORE_EXPORT __Core_Initializer__ { class CD_CORE_EXPORT __Core_Initializer__ {
public: public:
@@ -42,13 +42,13 @@ public:
}; };
class CD_CORE_EXPORT CDCore: public PIObject class CD_CORE_EXPORT CDCore: public PIObject {
{
PIOBJECT(CDUtils::CDCore); PIOBJECT(CDUtils::CDCore);
friend class __Core_Initializer__; friend class __Core_Initializer__;
friend class CDSection; friend class CDSection;
friend class Interface; friend class Interface;
friend class XInterface; friend class XInterface;
public: public:
static CDCore * instance(); static CDCore * instance();
static bool destroy(); static bool destroy();
@@ -65,7 +65,7 @@ public:
EVENT(X_Received); EVENT(X_Received);
EVENT(X_ReceiveFail); EVENT(X_ReceiveFail);
EVENT(X_ChangedGlobal); EVENT(X_ChangedGlobal);
EVENT1(X_ReceivedX, PIVector<PIDeque<int> >, pathes); EVENT1(X_ReceivedX, PIVector<PIDeque<int>>, pathes);
EVENT(C_Sended); EVENT(C_Sended);
EVENT(C_SendFail); EVENT(C_SendFail);
@@ -80,12 +80,12 @@ public:
EVENT(M_ChangedGlobal); EVENT(M_ChangedGlobal);
EVENT3(M_Message, PIDeque<int>, path, int, type, PIString, msg); EVENT3(M_Message, PIDeque<int>, path, int, type, PIString, msg);
void cd_write (CDSection * cd, PIIODevice * d); void cd_write(CDSection * cd, PIIODevice * d);
void cd_read (CDSection * cd, PIIODevice * d); void cd_read(CDSection * cd, PIIODevice * d);
void cd_parse (CDSection * cd, PIIODevice * d); void cd_parse(CDSection * cd, PIIODevice * d);
void cd_update (CDSection * cd, PIIODevice * d, UpdateModeFlags mode); void cd_update(CDSection * cd, PIIODevice * d, UpdateModeFlags mode);
void cd_calculate(CDSection * cd); void cd_calculate(CDSection * cd);
void cd_send (CDSection * cd, CDPacketType pt, bool direct = false); void cd_send(CDSection * cd, CDPacketType pt, bool direct = false);
void send(CDType::cdT cdt); void send(CDType::cdT cdt);
void request(CDType::cdT cdt); void request(CDType::cdT cdt);
void initApp(); void initApp();
@@ -97,7 +97,7 @@ public:
void stopX(); void stopX();
void sendCommand(const CDType & c); void sendCommand(const CDType & c);
void registerCHandler(const CDType & c, PIObject * o, Handler h); void registerCHandler(const CDType & c, PIObject * o, Handler h);
bool inProgress() {return sendt.isRunning();} bool inProgress() { return sendt.isRunning(); }
void sendMessage(const CDType & m, MessageType mt, const PIString & msg); void sendMessage(const CDType & m, MessageType mt, const PIString & msg);
CDSection * root(CDType::cdT cdt); CDSection * root(CDType::cdT cdt);
@@ -105,8 +105,8 @@ public:
static PIString pathToString(const PIDeque<int> & p); static PIString pathToString(const PIDeque<int> & p);
static PIDeque<int> stringToPath(const PIString & p); static PIDeque<int> stringToPath(const PIString & p);
static PIString pultConfig() {return PIString(pult_config);} static PIString pultConfig() { return PIString(pult_config); }
static PIString appConfig() {return PIString(app_config);} static PIString appConfig() { return PIString(app_config); }
private: private:
CDCore(); CDCore();
@@ -116,7 +116,7 @@ private:
EVENT_HANDLER1(void, dtReceiveFinished, bool, ok); EVENT_HANDLER1(void, dtReceiveFinished, bool, ok);
EVENT_HANDLER(void, sendThread); EVENT_HANDLER(void, sendThread);
EVENT_HANDLER(void, xTimerTick); EVENT_HANDLER(void, xTimerTick);
EVENT_HANDLER2(void, piCoutFinished, int, id, PIString*, buffer); EVENT_HANDLER2(void, piCoutFinished, int, id, PIString *, buffer);
void initRoot(CDSection * r); void initRoot(CDSection * r);
PIByteArray makeHeader(CDPacketType type, int session_id = 0) const; PIByteArray makeHeader(CDPacketType type, int session_id = 0) const;
void sendDirect(PIByteArray & ba); void sendDirect(PIByteArray & ba);
@@ -124,7 +124,7 @@ private:
void procReceivedPacket(PIByteArray & ba); void procReceivedPacket(PIByteArray & ba);
void raiseChangedGlobal(CDType::cdT cdt); void raiseChangedGlobal(CDType::cdT cdt);
typedef PIPair<PIObject * , Handler> OHPair; typedef PIPair<PIObject *, Handler> OHPair;
static const char app_config[], pult_config[]; static const char app_config[], pult_config[];
PIConnection connection; PIConnection connection;
@@ -134,15 +134,14 @@ private:
PITimer x_timer; PITimer x_timer;
CDSection k_, x_, c_, m_; CDSection k_, x_, c_, m_;
PIMutex x_mutex; PIMutex x_mutex;
PIVector<PIDeque<int> > x_selected; PIVector<PIDeque<int>> x_selected;
PIMap<PIString, OHPair> c_handlers; PIMap<PIString, OHPair> c_handlers;
bool need_rebuild_x, x_pult_side; bool need_rebuild_x, x_pult_side;
}; };
static __Core_Initializer__ __Core_initializer__; static __Core_Initializer__ __Core_initializer__;
} } // namespace CDUtils
#endif // CDUTILS_CORE_H #endif // CDUTILS_CORE_H

View File

@@ -1,4 +1,5 @@
#include "cdutils_interface.h" #include "cdutils_interface.h"
#include "cdutils_core.h" #include "cdutils_core.h"
#include "piconfig.h" #include "piconfig.h"
#include "pifile.h" #include "pifile.h"
@@ -7,11 +8,11 @@ using namespace CDUtils;
Interface::Interface(CDType::cdT type_) { Interface::Interface(CDType::cdT type_) {
core = CDCore::instance(); core = CDCore::instance();
s = core->root(type_); s = core->root(type_);
type = type_; type = type_;
//piCoutObj << (void*)this << core; // piCoutObj << (void*)this << core;
file_ = core->typeLetter(type_) + PIStringAscii(".dat"); file_ = core->typeLetter(type_) + PIStringAscii(".dat");
file_size = 0; file_size = 0;
switch (type) { switch (type) {
case CDType::cdK: case CDType::cdK:
@@ -52,41 +53,41 @@ bool Interface::test(int v) {
} }
CDType & Interface::operator [](const PIString & name_) { CDType & Interface::operator[](const PIString & name_) {
return (*s)[name_]; return (*s)[name_];
} }
const CDType Interface::operator [](const PIString & name_) const { const CDType Interface::operator[](const PIString & name_) const {
return (*s)[name_]; return (*s)[name_];
} }
CDType & Interface::operator [](const PIDeque<int> & path_) { CDType & Interface::operator[](const PIDeque<int> & path_) {
return (*s)[path_]; return (*s)[path_];
} }
const CDType Interface::operator [](const PIDeque<int> & path_) const { const CDType Interface::operator[](const PIDeque<int> & path_) const {
return (*s)[path_]; return (*s)[path_];
} }
CDType & Interface::operator [](int v) { CDType & Interface::operator[](int v) {
//piCout << (void*)this << "[]" << core; // piCout << (void*)this << "[]" << core;
return (*s)[v]; return (*s)[v];
} }
const CDType Interface::operator [](int v) const { const CDType Interface::operator[](int v) const {
//piCout << (void*)this << "[]" << core; // piCout << (void*)this << "[]" << core;
return (*s)[v]; return (*s)[v];
} }
CDSection & Interface::section(int v) { CDSection & Interface::section(int v) {
// CDSection & ret = s->section(v); // CDSection & ret = s->section(v);
// piCout << "[get section]" << v << ret.name; // piCout << "[get section]" << v << ret.name;
return s->section(v); return s->section(v);
} }
@@ -96,9 +97,9 @@ const CDSection Interface::section(int v) const {
} }
CDSection & Interface::section(const PIDeque<int> &path) { CDSection & Interface::section(const PIDeque<int> & path) {
PIDeque<int> spath = path; PIDeque<int> spath = path;
CDSection * rs = s; CDSection * rs = s;
while (!spath.isEmpty()) { while (!spath.isEmpty()) {
rs = &(rs->section(spath.take_front())); rs = &(rs->section(spath.take_front()));
} }

View File

@@ -1,28 +1,28 @@
/* /*
CD Utils - Control-Debug utilites CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CDUTILS_INTERFACE_H #ifndef CDUTILS_INTERFACE_H
#define CDUTILS_INTERFACE_H #define CDUTILS_INTERFACE_H
#include "cd_core_export.h"
#include "cdutils_types.h" #include "cdutils_types.h"
#include "piobject.h" #include "piobject.h"
#include "cd_core_export.h"
namespace CDUtils { namespace CDUtils {
@@ -30,19 +30,19 @@ namespace CDUtils {
class CDCore; class CDCore;
class CD_CORE_EXPORT Interface: public PIObject class CD_CORE_EXPORT Interface: public PIObject {
{
PIOBJECT(CDUtils::Interface); PIOBJECT(CDUtils::Interface);
public: public:
Interface(CDType::cdT type_); Interface(CDType::cdT type_);
bool test(int v); bool test(int v);
CDType & operator [](int v); CDType & operator[](int v);
const CDType operator [](int v) const; const CDType operator[](int v) const;
CDType & operator [](const PIString & name_); CDType & operator[](const PIString & name_);
const CDType operator [](const PIString & name_) const; const CDType operator[](const PIString & name_) const;
CDType & operator [](const PIDeque<int> & path_); CDType & operator[](const PIDeque<int> & path_);
const CDType operator [](const PIDeque<int> & path_) const; const CDType operator[](const PIDeque<int> & path_) const;
CDSection & section(int v); CDSection & section(int v);
const CDSection section(int v) const; const CDSection section(int v) const;
CDSection & section(const PIDeque<int> & path); CDSection & section(const PIDeque<int> & path);
@@ -50,9 +50,9 @@ public:
const CDSection & root() const; const CDSection & root() const;
int count(bool recursive = true) const; int count(bool recursive = true) const;
const PIString file() const {return file_;} const PIString file() const { return file_; }
int fileSize() const {return file_size;} int fileSize() const { return file_size; }
CDType::cdT cdType() const {return type;} CDType::cdT cdType() const { return type; }
bool exists(PIDeque<int> path) const; bool exists(PIDeque<int> path) const;
void setFileName(const PIString & _file); void setFileName(const PIString & _file);
@@ -86,11 +86,10 @@ protected:
CDType::cdT type; CDType::cdT type;
PIString file_; PIString file_;
int file_size; int file_size;
}; };
} } // namespace CDUtils
#endif // CDUTILS_INTERFACE_H #endif // CDUTILS_INTERFACE_H

View File

@@ -1,4 +1,5 @@
#include "cdutils_k.h" #include "cdutils_k.h"
#include "cdutils_core.h" #include "cdutils_core.h"
using namespace CDUtils; using namespace CDUtils;
@@ -6,8 +7,7 @@ using namespace CDUtils;
KInterface K; KInterface K;
KInterface::KInterface(): Interface(CDType::cdK) { KInterface::KInterface(): Interface(CDType::cdK) {}
}
void KInterface::directChange(const CDType & k) { void KInterface::directChange(const CDType & k) {

View File

@@ -1,46 +1,45 @@
/* /*
CD Utils - Control-Debug utilites CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CDUTILS_K_H #ifndef CDUTILS_K_H
#define CDUTILS_K_H #define CDUTILS_K_H
#include "cdutils_interface.h"
#include "cd_core_export.h" #include "cd_core_export.h"
#include "cdutils_interface.h"
namespace CDUtils { namespace CDUtils {
class CD_CORE_EXPORT KInterface: public Interface class CD_CORE_EXPORT KInterface: public Interface {
{
PIOBJECT_SUBCLASS(KInterface, Interface); PIOBJECT_SUBCLASS(KInterface, Interface);
public: public:
KInterface(); KInterface();
EVENT1(keepNamesRequest, bool*, kn); EVENT1(keepNamesRequest, bool *, kn);
void directChange(const CDType & k); void directChange(const CDType & k);
void directChange(const CDType & k, double v); void directChange(const CDType & k, double v);
}; };
} } // namespace CDUtils
extern CD_CORE_EXPORT CDUtils::KInterface K; extern CD_CORE_EXPORT CDUtils::KInterface K;

View File

@@ -1,4 +1,5 @@
#include "cdutils_m.h" #include "cdutils_m.h"
#include "cdutils_core.h" #include "cdutils_core.h"
using namespace CDUtils; using namespace CDUtils;

View File

@@ -1,44 +1,44 @@
/* /*
CD Utils - Control-Debug utilites CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CDUTILS_M_H #ifndef CDUTILS_M_H
#define CDUTILS_M_H #define CDUTILS_M_H
#include "cdutils_interface.h"
#include "cd_core_export.h" #include "cd_core_export.h"
#include "cdutils_interface.h"
namespace CDUtils { namespace CDUtils {
class CD_CORE_EXPORT MInterface: public Interface class CD_CORE_EXPORT MInterface: public Interface {
{
PIOBJECT_SUBCLASS(MInterface, Interface); PIOBJECT_SUBCLASS(MInterface, Interface);
public: public:
MInterface(); MInterface();
PICout operator [](int v) {return createPICout((*s)[v]);} PICout operator[](int v) { return createPICout((*s)[v]); }
PICout operator [](int v) const {return createPICout((*s)[v]);} PICout operator[](int v) const { return createPICout((*s)[v]); }
PICout operator [](const PIString & name_) {return createPICout((*s)[name_]);} PICout operator[](const PIString & name_) { return createPICout((*s)[name_]); }
PICout operator [](const PIString & name_) const {return createPICout((*s)[name_]);} PICout operator[](const PIString & name_) const { return createPICout((*s)[name_]); }
PICout operator [](const PIDeque<int> & path_) {return createPICout((*s)[path_]);} PICout operator[](const PIDeque<int> & path_) { return createPICout((*s)[path_]); }
PICout operator [](const PIDeque<int> & path_) const {return createPICout((*s)[path_]);} PICout operator[](const PIDeque<int> & path_) const { return createPICout((*s)[path_]); }
void messageBox(const CDType & m, const PIString & msg); void messageBox(const CDType & m, const PIString & msg);
@@ -46,10 +46,9 @@ public:
private: private:
PICout createPICout(const CDType & m) const; PICout createPICout(const CDType & m) const;
}; };
} } // namespace CDUtils
extern CD_CORE_EXPORT CDUtils::MInterface M; extern CD_CORE_EXPORT CDUtils::MInterface M;

View File

@@ -1,8 +1,9 @@
#include "cdutils_parser.h" #include "cdutils_parser.h"
#include "cdutils_types.h" #include "cdutils_types.h"
#include "piiostring.h"
#include "piiobytearray.h"
#include "pifile.h" #include "pifile.h"
#include "piiobytearray.h"
#include "piiostring.h"
using namespace CDUtils; using namespace CDUtils;
@@ -63,14 +64,14 @@ PIVector<int> enumValues(const PIString & e, const PIMap<PIString, CDSection> &
PIVector<int> ret; PIVector<int> ret;
enames.clear(); enames.clear();
if (sections.contains(e)) { if (sections.contains(e)) {
ret = sections.at(e).indexes(); ret = sections.at(e).indexes();
enames = sections.at(e).index_names(); enames = sections.at(e).index_names();
} else { } else {
int v = e.toInt(); int v = e.toInt();
if (v < 2) return ret; if (v < 2) return ret;
for (int i = 0; i < v; ++i) { for (int i = 0; i < v; ++i) {
ret << i; ret << i;
enames << "";//PIString::fromNumber(i); enames << ""; // PIString::fromNumber(i);
} }
} }
return ret; return ret;
@@ -81,7 +82,7 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
CDType::cdT et = (CDType::cdT)cdsection_type; CDType::cdT et = (CDType::cdT)cdsection_type;
if (!d) return CDSection(et); if (!d) return CDSection(et);
if (!d->canRead()) return CDSection(et); if (!d->canRead()) return CDSection(et);
//piCout << "[CDSection] parse start"; // piCout << "[CDSection] parse start";
CDSection cs(et); CDSection cs(et);
CDType ck; CDType ck;
PIMap<PIString, CDSection> sections; PIMap<PIString, CDSection> sections;
@@ -89,14 +90,14 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
PIString content, line, alias, type, comment; PIString content, line, alias, type, comment;
PIStringList iarr; PIStringList iarr;
if (PIStringAscii(d->className()) == PIStringAscii("PIFile")) { if (PIStringAscii(d->className()) == PIStringAscii("PIFile")) {
PIByteArray c = ((PIFile*)d)->readAll(); PIByteArray c = ((PIFile *)d)->readAll();
c << uchar(0); c << uchar(0);
content = PIString::fromUTF8((const char *)c.data()); content = PIString::fromUTF8((const char *)c.data());
} }
if (PIStringAscii(d->className()) == PIStringAscii("PIIOString")) content = *(((PIIOString*)d)->string()); if (PIStringAscii(d->className()) == PIStringAscii("PIIOString")) content = *(((PIIOString *)d)->string());
if (PIStringAscii(d->className()) == PIStringAscii("PIIOByteArray")) content = PIString(*(((PIIOByteArray*)d)->byteArray())); if (PIStringAscii(d->className()) == PIStringAscii("PIIOByteArray")) content = PIString(*(((PIIOByteArray *)d)->byteArray()));
PIIOString ios(&content); PIIOString ios(&content);
//int phase = 0; // int phase = 0;
int cind = -1; int cind = -1;
while ((cind = content.find("enum", cind)) >= 0) { while ((cind = content.find("enum", cind)) >= 0) {
ios.seek(cind); ios.seek(cind);
@@ -114,11 +115,11 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
cind += 4; cind += 4;
continue; continue;
} }
cs = CDSection(et); cs = CDSection(et);
cs.name = line; cs.name = line;
//piCout << "enum" << cs.name; // piCout << "enum" << cs.name;
int cev = 0; int cev = 0;
// cevalues.clear(); // cevalues.clear();
while (!ios.isEnd()) { while (!ios.isEnd()) {
line = ios.readLine().trim(); line = ios.readLine().trim();
comment.clear(); comment.clear();
@@ -128,7 +129,7 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
if (comment.find("=") >= 0) { if (comment.find("=") >= 0) {
parseInsert(comment, alias, iarr); parseInsert(comment, alias, iarr);
if (!iarr.isEmpty()) { if (!iarr.isEmpty()) {
// piCout << "#" << enum_values; // piCout << "#" << enum_values;
if (!enum_values.contains(alias)) { if (!enum_values.contains(alias)) {
piCout << "Parse error: can`t find section alias \"" << alias << "\"!"; piCout << "Parse error: can`t find section alias \"" << alias << "\"!";
return CDSection(et); return CDSection(et);
@@ -137,16 +138,16 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
piCout << "Parse error: can`t find section \"" << iarr.front() << "\"!"; piCout << "Parse error: can`t find section \"" << iarr.front() << "\"!";
return CDSection(et); return CDSection(et);
} }
//piCout << "insert" << alias << iarr; // piCout << "insert" << alias << iarr;
int aval = enum_values.value(alias); int aval = enum_values.value(alias);
CDSection is = sections.value(iarr.take_front()), ts; CDSection is = sections.value(iarr.take_front()), ts;
int ibpos = is.name.size_s(); int ibpos = is.name.size_s();
piForeachRC (PIString & a, iarr) { piForeachRC(PIString & a, iarr) {
PIStringList enames; PIStringList enames;
PIVector<int> evals = enumValues(a, sections, enames); PIVector<int> evals = enumValues(a, sections, enames);
//piCout << a << evals; // piCout << a << evals;
for (int i = 0; i < evals.size_s(); ++i) { for (int i = 0; i < evals.size_s(); ++i) {
ts.section(evals[i]) = is; ts.section(evals[i]) = is;
ts.section(evals[i]).alias = enames[i]; ts.section(evals[i]).alias = enames[i];
} }
ts.name = is.name; ts.name = is.name;
@@ -154,13 +155,13 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
is = ts; is = ts;
ts = CDSection(et); ts = CDSection(et);
} }
is.alias = alias; is.alias = alias;
cs.section(aval) = is; cs.section(aval) = is;
} }
} }
} else { } else {
parseEnumLine(line, &cev, &type, &comment); parseEnumLine(line, &cev, &type, &comment);
//piCout << line << "=" << cev << "//" << type << comment; // piCout << line << "=" << cev << "//" << type << comment;
ck = CDType(cev, line, type, "", "", comment, et); ck = CDType(cev, line, type, "", "", comment, et);
if (type == "e") { if (type == "e") {
if (comment.startsWith("${")) { if (comment.startsWith("${")) {
@@ -169,22 +170,22 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
comment.cutLeft(en.size_s() + 2).trim(); comment.cutLeft(en.size_s() + 2).trim();
ck.setEnumValues(sections.value(en).enumValues()); ck.setEnumValues(sections.value(en).enumValues());
ck.setComment(comment); ck.setComment(comment);
//piCout << "enum" << en << ck.enumValues(); // piCout << "enum" << en << ck.enumValues();
} }
} }
cs[cev] = ck; cs[cev] = ck;
//cevalues[line] = cev; // cevalues[line] = cev;
enum_values[line] = cev; enum_values[line] = cev;
++cev; ++cev;
} }
} }
//piCout << cs.name << cs.k; // piCout << cs.name << cs.k;
sections[cs.name] = cs; sections[cs.name] = cs;
// piCout << "#" << cevalues; // piCout << "#" << cevalues;
// enum_values << cevalues; // enum_values << cevalues;
cind += 4; cind += 4;
} }
// piCout << "[CDSection] parse end"; // piCout << "[CDSection] parse end";
switch (et) { switch (et) {
case CDType::cdK: return sections.value("KDescription"); case CDType::cdK: return sections.value("KDescription");
case CDType::cdX: return sections.value("XDescription"); case CDType::cdX: return sections.value("XDescription");

View File

@@ -1,20 +1,20 @@
/* /*
CD Utils - Control-Debug utilites CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CDUTILS_PARSER_H #ifndef CDUTILS_PARSER_H
@@ -34,6 +34,6 @@ CD_CORE_EXPORT CDSection parse(PIIODevice * d, int cdsection_type);
} }
} } // namespace CDUtils
#endif // CDUTILS_PARSER_H #endif // CDUTILS_PARSER_H

View File

@@ -1,74 +1,86 @@
/* /*
CD Utils - Control-Debug utilites CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CDUTILS_PROTOCOL_H #ifndef CDUTILS_PROTOCOL_H
#define CDUTILS_PROTOCOL_H #define CDUTILS_PROTOCOL_H
#include "pistring.h"
#include "cd_core_export.h" #include "cd_core_export.h"
#include "pistring.h"
namespace CDUtils { namespace CDUtils {
enum CDPacketType { enum CDPacketType {
CD_Ping, CD_Ping,
CD_Pong, CD_Pong,
CD_KQuery, CD_KQuery,
CD_KSend, CD_KSend,
CD_KDirectChange, CD_KDirectChange,
CD_XQuery, CD_XQuery,
CD_XSend, CD_XSend,
CD_XRequest, CD_XRequest,
CD_XValues, CD_XValues,
CD_CQuery, CD_CQuery,
CD_CSend, CD_CSend,
CD_Command, CD_Command,
CD_MQuery, CD_MQuery,
CD_MSend, CD_MSend,
CD_Message, CD_Message,
}; };
# pragma pack(push,1) #pragma pack(push, 1)
struct CD_CORE_EXPORT PacketHeader { struct CD_CORE_EXPORT PacketHeader {
int type; // CDPacketType int type; // CDPacketType
int session_id; int session_id;
}; };
struct CD_CORE_EXPORT PacketKDirectChange { struct CD_CORE_EXPORT PacketKDirectChange {
PIDeque<int> path; PIDeque<int> path;
PIString value; PIString value;
}; };
# pragma pack(pop) #pragma pack(pop)
#ifdef PIP_BINARY_STREAM #ifdef PIP_BINARY_STREAM
BINARY_STREAM_WRITE(PacketKDirectChange) {s << v.path << v.value; return s;} BINARY_STREAM_WRITE(PacketKDirectChange) {
BINARY_STREAM_READ (PacketKDirectChange) {s >> v.path >> v.value; return s;} s << v.path << v.value;
return s;
}
BINARY_STREAM_READ(PacketKDirectChange) {
s >> v.path >> v.value;
return s;
}
#else #else
inline PIByteArray & operator <<(PIByteArray & s, const PacketKDirectChange & v) {s << v.path << v.value; return s;} inline PIByteArray & operator<<(PIByteArray & s, const PacketKDirectChange & v) {
inline PIByteArray & operator >>(PIByteArray & s, PacketKDirectChange & v) {s >> v.path >> v.value; return s;} s << v.path << v.value;
return s;
}
inline PIByteArray & operator>>(PIByteArray & s, PacketKDirectChange & v) {
s >> v.path >> v.value;
return s;
}
#endif #endif
} } // namespace CDUtils
#endif // CDUTILS_PROTOCOL_H #endif // CDUTILS_PROTOCOL_H

View File

@@ -1,8 +1,9 @@
#include "cdutils_types.h" #include "cdutils_types.h"
#include "piconfig.h"
#include "pifile.h"
#include "pievaluator.h"
#include "cdutils_core.h" #include "cdutils_core.h"
#include "piconfig.h"
#include "pievaluator.h"
#include "pifile.h"
using namespace CDUtils; using namespace CDUtils;
@@ -10,46 +11,45 @@ using namespace CDUtils;
const int cd_x_history_max_size = 4000; const int cd_x_history_max_size = 4000;
CDType::CDType() { CDType::CDType() {
index_ = -1; index_ = -1;
value_d = 0.; value_d = 0.;
value_i = 0; value_i = 0;
value_b = calculated = x_enabled = false; value_b = calculated = x_enabled = false;
cd_type_ = cdNull; cd_type_ = cdNull;
parent = 0; parent = 0;
avg_size = 1; avg_size = 1;
mode_ = rmode_ = X_Current; mode_ = rmode_ = X_Current;
} }
CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t) { CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t) {
index_ = i; index_ = i;
name_ = n.trimmed(); name_ = n.trimmed();
type_ = t.trimmed(); type_ = t.trimmed();
value_s = v.trimmed(); value_s = v.trimmed();
formula_ = f.trimmed(); formula_ = f.trimmed();
comment_ = c.trimmed(); comment_ = c.trimmed();
value_d = v.toDouble(); value_d = v.toDouble();
value_i = v.toInt(); value_i = v.toInt();
value_b = v.toBool(); value_b = v.toBool();
cd_type_ = cd_t; cd_type_ = cd_t;
calculated = x_enabled = false; calculated = x_enabled = false;
parent = 0; parent = 0;
avg_size = 1; avg_size = 1;
mode_ = rmode_ = X_Current; mode_ = rmode_ = X_Current;
if (type_ == "e") { if (type_ == "e") {
enum_values = parseEnumComment(comment_); enum_values = parseEnumComment(comment_);
// piCout << enum_values.size() << enum_values; // piCout << enum_values.size() << enum_values;
} }
// piCout << type_.size() << type_.toUTF8(); // piCout << type_.size() << type_.toUTF8();
// piCout << formula_.size() << formula_.toUTF8(); // piCout << formula_.size() << formula_.toUTF8();
// piCout << comment_.size() << comment_.toUTF8(); // piCout << comment_.size() << comment_.toUTF8();
// piCout << "[CDType] create" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK); // piCout << "[CDType] create" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ <<
//":" << (cd_type_ == cdK);
} }
CDType & CDType::operator =(double x) { CDType & CDType::operator=(double x) {
value_d = x; value_d = x;
value_i = x; value_i = x;
value_b = x > 0.; value_b = x > 0.;
@@ -96,7 +96,7 @@ PIVariant CDType::variantValue() const {
e.selectValue(toInt()); e.selectValue(toInt());
return PIVariant(e); return PIVariant(e);
break; break;
} }
default: break; default: break;
} }
return PIVariant(value()); return PIVariant(value());
@@ -105,9 +105,9 @@ PIVariant CDType::variantValue() const {
void CDType::setValue(const PIString & value_) { void CDType::setValue(const PIString & value_) {
formula_ = value_; formula_ = value_;
value_d = formula_.toDouble(); value_d = formula_.toDouble();
value_i = formula_.toInt(); value_i = formula_.toInt();
value_b = formula_.toBool(); value_b = formula_.toBool();
} }
@@ -117,10 +117,10 @@ void CDType::setVariantValue(const PIVariant & value_) {
void CDType::setFormula(const PIString & f) { void CDType::setFormula(const PIString & f) {
formula_ = f; formula_ = f;
calculated = false; calculated = false;
//PIEvaluator e; // PIEvaluator e;
//calculate(&e); // calculate(&e);
} }
@@ -130,30 +130,32 @@ PIStringList CDType::pathString() const {
if (!ps) return ret; if (!ps) return ret;
for (int i = 0; i < path_.size_s() - 1; ++i) { for (int i = 0; i < path_.size_s() - 1; ++i) {
ps = &(ps->section(path_[i])); ps = &(ps->section(path_[i]));
if (!ps->alias.isEmpty()) ret << ps->alias; if (!ps->alias.isEmpty())
else ret << PIString::fromNumber(path_[i]); ret << ps->alias;
else
ret << PIString::fromNumber(path_[i]);
} }
if (!name_.isEmpty()) ret << name_; if (!name_.isEmpty())
else ret << PIString::fromNumber(index_); ret << name_;
else
ret << PIString::fromNumber(index_);
return ret; return ret;
} }
void CDType::readX(PIByteArray & ba) { void CDType::readX(PIByteArray & ba) {
if (ba.size() < 5) return; if (ba.size() < 5) return;
uchar t(0); ba >> t; uchar t(0);
ba >> t;
rmode_ = (XMode)t; rmode_ = (XMode)t;
switch (rmode_) { switch (rmode_) {
case X_Current: case X_Current: ba >> value_d; break;
ba >> value_d;
break;
case X_All_Avg: { case X_All_Avg: {
PIVector<double> ah; PIVector<double> ah;
ba >> ah; ba >> ah;
history << ah; history << ah;
if (!history.isEmpty()) if (!history.isEmpty()) value_d = history.back();
value_d = history.back(); } break;
} break;
default: break; default: break;
} }
value_i = value_d; value_i = value_d;
@@ -164,9 +166,7 @@ void CDType::readX(PIByteArray & ba) {
void CDType::writeX(PIByteArray & ba) { void CDType::writeX(PIByteArray & ba) {
ba << uchar(mode_); ba << uchar(mode_);
switch (mode_) { switch (mode_) {
case X_Current: case X_Current: ba << value_d; break;
ba << value_d;
break;
case X_All_Avg: case X_All_Avg:
ba << history; ba << history;
history.clear(); history.clear();
@@ -176,14 +176,14 @@ void CDType::writeX(PIByteArray & ba) {
} }
bool CDType::calculate(PIEvaluator * e, PIVector<const CDType * > stack) { bool CDType::calculate(PIEvaluator * e, PIVector<const CDType *> stack) {
if (stack.contains(this)) { if (stack.contains(this)) {
error_ = "Circular dependencies: "; error_ = "Circular dependencies: ";
for (const CDType * k : stack) { for (const CDType * k: stack) {
error_ += k->name() + " -> "; error_ += k->name() + " -> ";
} }
error_ += name(); error_ += name();
//piCout << error_; // piCout << error_;
return false; return false;
} }
stack << this; stack << this;
@@ -191,7 +191,7 @@ bool CDType::calculate(PIEvaluator * e, PIVector<const CDType * > stack) {
calculated = true; calculated = true;
error_.clear(); error_.clear();
if (!parent) return true; if (!parent) return true;
//piCout << "calc" << name_ << (parent ? parent->alias : "root"); // piCout << "calc" << name_ << (parent ? parent->alias : "root");
value_s = formula_.trimmed(); value_s = formula_.trimmed();
for (;;) { for (;;) {
int ki = value_s.find("K["); int ki = value_s.find("K[");
@@ -199,14 +199,14 @@ bool CDType::calculate(PIEvaluator * e, PIVector<const CDType * > stack) {
int ke = value_s.find("]", ki + 2); int ke = value_s.find("]", ki + 2);
if (ke < 0) break; if (ke < 0) break;
PIString kp = value_s.mid(ki + 2, ke - ki - 2); PIString kp = value_s.mid(ki + 2, ke - ki - 2);
//piCout << kp; // piCout << kp;
CDType & k((*parent)[kp]); CDType & k((*parent)[kp]);
k.calculate(e, stack); k.calculate(e, stack);
value_s.replace(ki, ke - ki + 1, PIString::fromNumber(k.value_d)); value_s.replace(ki, ke - ki + 1, PIString::fromNumber(k.value_d));
} }
value_d = formula_.toDouble(); value_d = formula_.toDouble();
value_i = formula_.toInt(); value_i = formula_.toInt();
value_b = formula_.toBool(); value_b = formula_.toBool();
double ev = 0.; double ev = 0.;
if (!e->check(value_s) && value_d == 0. && value_i == 0 && !value_b) { if (!e->check(value_s) && value_d == 0. && value_i == 0 && !value_b) {
PIString f = formula_.trimmed().toLowerCase(); PIString f = formula_.trimmed().toLowerCase();
@@ -214,12 +214,11 @@ bool CDType::calculate(PIEvaluator * e, PIVector<const CDType * > stack) {
error_ = e->error(); error_ = e->error();
return false; return false;
} }
} else } else if (e->isCorrect())
if (e->isCorrect()) ev = e->evaluate().real();
ev = e->evaluate().real(); // piCout << value_s << value_i << value_d << ev;
//piCout << value_s << value_i << value_d << ev; // if ((value_d == 0.) || (piAbsd(value_d) < piAbsd(ev))) value_d = ev;
//if ((value_d == 0.) || (piAbsd(value_d) < piAbsd(ev))) value_d = ev; // if ((value_i == 0) || (piAbsd(value_i) < piAbsd(ev))) value_i = int(ev);
//if ((value_i == 0) || (piAbsd(value_i) < piAbsd(ev))) value_i = int(ev);
if ((value_d == 0.) || (ev != 0.)) value_d = ev; if ((value_d == 0.) || (ev != 0.)) value_d = ev;
if ((value_i == 0) || (ev != 0.)) value_i = int(ev); if ((value_i == 0) || (ev != 0.)) value_i = int(ev);
value_b = value_b || (ev > 0.); value_b = value_b || (ev > 0.);
@@ -245,8 +244,8 @@ PIVariantTypes::Enum CDType::parseEnumComment(PIString c) {
if (c.isEmpty()) return ret; if (c.isEmpty()) return ret;
if (type_ == "e") { if (type_ == "e") {
PIStringList sl = c.inBrackets('{', '}').split(","); PIStringList sl = c.inBrackets('{', '}').split(",");
int cval = 0; int cval = 0;
for (PIString & s : sl) { for (PIString & s: sl) {
s.trim(); s.trim();
if (s.isEmpty()) continue; if (s.isEmpty()) continue;
if (s[0].isDigit()) { if (s[0].isDigit()) {
@@ -260,13 +259,13 @@ PIVariantTypes::Enum CDType::parseEnumComment(PIString c) {
++cval; ++cval;
} }
} }
//piCout << c << "=" << ret; // piCout << c << "=" << ret;
return ret; return ret;
} }
CDSection::CDSection(CDType::cdT type_) { CDSection::CDSection(CDType::cdT type_) {
cd_type_ = type_; cd_type_ = type_;
null.cd_type_ = type_; null.cd_type_ = type_;
} }
@@ -331,8 +330,8 @@ void CDSection::calculate() {
CDType & CDSection::getByName(const PIString & name_) { CDType & CDSection::getByName(const PIString & name_) {
PIStringList np = name_.split("."); PIStringList np = name_.split(".");
if (np.isEmpty()) return null; if (np.isEmpty()) return null;
//piCout << np; // piCout << np;
CDSection * cs = this, * ns = 0; CDSection *cs = this, *ns = 0;
if (np.front().isEmpty()) { if (np.front().isEmpty()) {
if (np.size_s() < 2) return null; if (np.size_s() < 2) return null;
cs = CDCore::instance()->root(cd_type_); cs = CDCore::instance()->root(cd_type_);
@@ -341,37 +340,40 @@ CDType & CDSection::getByName(const PIString & name_) {
for (int i = 0; i < np.size_s() - 1; ++i) { for (int i = 0; i < np.size_s() - 1; ++i) {
if (np[i].isEmpty()) return null; if (np[i].isEmpty()) return null;
bool isd = np[i][0].isDigit() || (np[i][0] == '-'); bool isd = np[i][0].isDigit() || (np[i][0] == '-');
int dv = 0; int dv = 0;
if (isd) dv = np[i].toInt(); if (isd) dv = np[i].toInt();
ns = 0; ns = 0;
auto it = cs->s.makeIterator(); auto it = cs->s.makeIterator();
while (it.next()) { while (it.next()) {
bool f = false; bool f = false;
if (isd) f = (dv == it.key()); if (isd)
else f = (np[i] == it.value().alias); f = (dv == it.key());
//piCout << "s..." << it.key() << it.value().alias << f; else
f = (np[i] == it.value().alias);
// piCout << "s..." << it.key() << it.value().alias << f;
if (f) { if (f) {
ns = &(it.value()); ns = &(it.value());
break; break;
} }
} }
//piCout << ns; // piCout << ns;
if (!ns) return null; if (!ns) return null;
cs = ns; cs = ns;
} }
if (np.back().isEmpty()) return null; if (np.back().isEmpty()) return null;
bool isd = np.back()[0].isDigit() || (np.back()[0] == '-'); bool isd = np.back()[0].isDigit() || (np.back()[0] == '-');
int dv = 0; int dv = 0;
if (isd) dv = np.back().toInt(); if (isd) dv = np.back().toInt();
//piCout << np.back() << isd << dv; // piCout << np.back() << isd << dv;
auto it = cs->cd.makeIterator(); auto it = cs->cd.makeIterator();
while (it.next()) { while (it.next()) {
bool f = false; bool f = false;
if (isd) f = (dv == it.key()); if (isd)
else f = (np.back() == it.value().name()); f = (dv == it.key());
//piCout << "k..." << it.key() << it.value().name() << f; else
if (f) f = (np.back() == it.value().name());
return cs->cd[it.key()]; // piCout << "k..." << it.key() << it.value().name() << f;
if (f) return cs->cd[it.key()];
} }
return null; return null;
} }
@@ -390,12 +392,18 @@ CDType & CDSection::getByPath(const PIDeque<int> & path_) {
void CDSection::write(PIIODevice * d, const PIString & prefix) { void CDSection::write(PIIODevice * d, const PIString & prefix) {
if (!d) return; if (!d) return;
if (cd.isEmpty() && s.isEmpty()) return; if (cd.isEmpty() && s.isEmpty()) return;
// piCout << "[CDSection] write start"; // piCout << "[CDSection] write start";
PIString l; PIString l;
PIStringList cdtl; PIStringList cdtl;
cdtl << "null" << "k" << "x" << "c" << "m"; cdtl << "null"
if (prefix.isEmpty()) l = "[" + cdtl[cd_type_] + "]"; << "k"
else l = "[" + prefix + "." + cdtl[cd_type_] + "]"; << "x"
<< "c"
<< "m";
if (prefix.isEmpty())
l = "[" + cdtl[cd_type_] + "]";
else
l = "[" + prefix + "." + cdtl[cd_type_] + "]";
l += "\n"; l += "\n";
d->write(l.toUTF8()); d->write(l.toUTF8());
l = "name = " + name + " \n"; l = "name = " + name + " \n";
@@ -415,7 +423,7 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
d->write(l.toUTF8()); d->write(l.toUTF8());
if (!ck.enumValues().enum_list.isEmpty()) { if (!ck.enumValues().enum_list.isEmpty()) {
l = PIString::fromNumber(ck.index()) + ".ev = {"; l = PIString::fromNumber(ck.index()) + ".ev = {";
for (const PIVariantTypes::Enumerator & e : ck.enumValues().enum_list) { for (const PIVariantTypes::Enumerator & e: ck.enumValues().enum_list) {
l += PIString::fromNumber(e.value) + " - " + e.name + ", "; l += PIString::fromNumber(e.value) + " - " + e.name + ", ";
} }
l.cutRight(2); l.cutRight(2);
@@ -426,7 +434,8 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
case CDType::cdX: case CDType::cdX:
l = PIString::fromNumber(ck.index()) + ".name = " + ck.name() + " #s " + ck.comment() + " \n"; l = PIString::fromNumber(ck.index()) + ".name = " + ck.name() + " #s " + ck.comment() + " \n";
d->write(l.toUTF8()); d->write(l.toUTF8());
l = PIString::fromNumber(ck.index()) + ".mode = " + PIString::fromNumber((int)ck.xmode()) + " #e (0 - cur, 1 - all_avg) " + "\n"; l = PIString::fromNumber(ck.index()) + ".mode = " + PIString::fromNumber((int)ck.xmode()) + " #e (0 - cur, 1 - all_avg) " +
"\n";
d->write(l.toUTF8()); d->write(l.toUTF8());
l = PIString::fromNumber(ck.index()) + ".avg = " + PIString::fromNumber(ck.avg()) + " #n " + "\n"; l = PIString::fromNumber(ck.index()) + ".avg = " + PIString::fromNumber(ck.avg()) + " #n " + "\n";
d->write(l.toUTF8()); d->write(l.toUTF8());
@@ -441,8 +450,10 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
} }
} }
if (!s.isEmpty()) { if (!s.isEmpty()) {
if (prefix.isEmpty()) l = "s"; if (prefix.isEmpty())
else l = prefix + ".s"; l = "s";
else
l = prefix + ".s";
auto j = s.makeIterator(); auto j = s.makeIterator();
while (j.next()) { while (j.next()) {
j.value().write(d, l + "." + PIString::fromNumber(j.key())); j.value().write(d, l + "." + PIString::fromNumber(j.key()));
@@ -452,45 +463,54 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
l = "[]\n"; l = "[]\n";
d->write(l.toUTF8()); d->write(l.toUTF8());
} }
// piCout << "[CDSection] write end"; // piCout << "[CDSection] write end";
} }
void CDSection::read(const void * ep) { void CDSection::read(const void * ep) {
// piCout << "[CDSection] read start"; // piCout << "[CDSection] read start";
PIStringList cdtl; PIStringList cdtl;
cdtl << "null" << "k" << "x" << "c" << "m"; cdtl << "null"
<< "k"
<< "x"
<< "c"
<< "m";
cd.clear(); cd.clear();
s.clear(); s.clear();
PIConfig::Entry & e(*(PIConfig::Entry*)ep); PIConfig::Entry & e(*(PIConfig::Entry *)ep);
name = e.getValue(cdtl[cd_type_] + ".name").value(); name = e.getValue(cdtl[cd_type_] + ".name").value();
alias = e.getValue(cdtl[cd_type_] + ".alias").value(); alias = e.getValue(cdtl[cd_type_] + ".alias").value();
PIConfig::Entry & cdl = e.getValue(cdtl[cd_type_]); PIConfig::Entry & cdl = e.getValue(cdtl[cd_type_]);
for (int i = 0; i < cdl.childCount(); ++i) { for (int i = 0; i < cdl.childCount(); ++i) {
const PIConfig::Entry * e(cdl.child(i)); const PIConfig::Entry * e(cdl.child(i));
bool ok = false; bool ok = false;
int id = e->name().toInt(-1, &ok); int id = e->name().toInt(-1, &ok);
// piCout << "[read]" << ke->name() << ke->value() << ok; // piCout << "[read]" << ke->name() << ke->value() << ok;
if (ok) { if (ok) {
CDType c; CDType c;
PIString ev; PIString ev;
switch (cd_type_) { switch (cd_type_) {
case CDType::cdNull: break; case CDType::cdNull: break;
case CDType::cdK: case CDType::cdK:
c = CDType(id, e->getValue("v").comment(), e->getValue("v").type(), e->getValue("v").value(), e->getValue("f").value(), e->getValue("f").comment(), cd_type_); c = CDType(id,
e->getValue("v").comment(),
e->getValue("v").type(),
e->getValue("v").value(),
e->getValue("f").value(),
e->getValue("f").comment(),
cd_type_);
ev = e->getValue("ev", "").value(); ev = e->getValue("ev", "").value();
if (!ev.isEmpty()) if (!ev.isEmpty()) c.enum_values = c.parseEnumComment(ev);
c.enum_values = c.parseEnumComment(ev);
break; break;
case CDType::cdX: case CDType::cdX:
c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_); c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString(), e->getValue("name").comment(), cd_type_);
c.setXMode((CDType::XMode)e->getValue("mode", int(CDType::X_Current)).value().toInt()); c.setXMode((CDType::XMode)e->getValue("mode", int(CDType::X_Current)).value().toInt());
c.setAvg((CDType::XMode)e->getValue("avg", 1).value().toInt()); c.setAvg((CDType::XMode)e->getValue("avg", 1).value().toInt());
c.x_enabled = e->getValue("sel", false).value().toBool(); c.x_enabled = e->getValue("sel", false).value().toBool();
break; break;
case CDType::cdC: case CDType::cdC:
case CDType::cdM: case CDType::cdM:
c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_); c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString(), e->getValue("name").comment(), cd_type_);
break; break;
} }
cd[id] = c; cd[id] = c;
@@ -504,7 +524,7 @@ void CDSection::read(const void * ep) {
rs.cd_type_ = cd_type_; rs.cd_type_ = cd_type_;
rs.read(se); rs.read(se);
} }
// piCout << "[CDSection] read end"; // piCout << "[CDSection] read end";
} }
@@ -513,8 +533,8 @@ void CDSection::update(CDSection & v, UpdateModeFlags mode) {
piCout << "[CDSection] update error: SaveByIndex | SaveByName mode is denied!"; piCout << "[CDSection] update error: SaveByIndex | SaveByName mode is denied!";
return; return;
} }
//piCout << "[CDSection] update start"; // piCout << "[CDSection] update start";
//piCout << "before" << k.size() << v.k.size(); // piCout << "before" << k.size() << v.k.size();
PIMap<int, PIString> prev_cd_f_bi; PIMap<int, PIString> prev_cd_f_bi;
PIMap<PIString, PIString> prev_cd_f_bn; PIMap<PIString, PIString> prev_cd_f_bn;
@@ -530,9 +550,9 @@ void CDSection::update(CDSection & v, UpdateModeFlags mode) {
} }
if (!mode[Merge]) cd.clear(); if (!mode[Merge]) cd.clear();
for (auto i = v.cd.begin(); i != v.cd.end(); ++i) { for (auto i = v.cd.begin(); i != v.cd.end(); ++i) {
int id = i.key(); int id = i.key();
PIString n = i.value().name(); PIString n = i.value().name();
cd[id] = i.value(); cd[id] = i.value();
if (mode[SaveByIndex]) { if (mode[SaveByIndex]) {
if (prev_cd_f_bi.contains(id)) { if (prev_cd_f_bi.contains(id)) {
cd[id].setFormula(prev_cd_f_bi[id]); cd[id].setFormula(prev_cd_f_bi[id]);
@@ -559,9 +579,9 @@ void CDSection::update(CDSection & v, UpdateModeFlags mode) {
} }
if (!mode[Merge]) s.clear(); if (!mode[Merge]) s.clear();
for (auto j = v.s.begin(); j != v.s.end(); ++j) { for (auto j = v.s.begin(); j != v.s.end(); ++j) {
int id = j.key(); int id = j.key();
PIString n = j.value().alias; PIString n = j.value().alias;
s[id] = j.value(); s[id] = j.value();
if (mode[SaveByIndex]) { if (mode[SaveByIndex]) {
if (prev_s_bi.contains(id)) s[id] = prev_s_bi[id]; if (prev_s_bi.contains(id)) s[id] = prev_s_bi[id];
} }
@@ -580,7 +600,7 @@ bool CDSection::isSameStructure(CDSection & v) {
} }
for (auto i = v.cd.begin(); i != v.cd.end(); ++i) { for (auto i = v.cd.begin(); i != v.cd.end(); ++i) {
if (!cd_ids.contains(i.value().name())) continue; if (!cd_ids.contains(i.value().name())) continue;
//piCout << i.key() << k[i.key()].name() << i.value().name(); // piCout << i.key() << k[i.key()].name() << i.value().name();
if (cd[cd_ids[i.value().name()]].index() != i.key()) return false; if (cd[cd_ids[i.value().name()]].index() != i.key()) return false;
} }
for (auto j = v.s.begin(); j != v.s.end(); ++j) { for (auto j = v.s.begin(); j != v.s.end(); ++j) {
@@ -593,7 +613,7 @@ bool CDSection::isSameStructure(CDSection & v) {
void CDSection::prepareCalculate() { void CDSection::prepareCalculate() {
for (auto i = cd.begin(); i != cd.end(); ++i) { for (auto i = cd.begin(); i != cd.end(); ++i) {
i.value().parent = this; i.value().parent = this;
i.value().calculated = false; i.value().calculated = false;
} }
for (auto j = s.begin(); j != s.end(); ++j) { for (auto j = s.begin(); j != s.end(); ++j) {
@@ -622,8 +642,8 @@ void CDSection::setSelectedX(bool yes) {
} }
PIVector<PIDeque<int> > CDSection::collectX() const { PIVector<PIDeque<int>> CDSection::collectX() const {
PIVector<PIDeque<int> > ret; PIVector<PIDeque<int>> ret;
for (auto i = cd.begin(); i != cd.end(); ++i) { for (auto i = cd.begin(); i != cd.end(); ++i) {
if (i.value().x_enabled) { if (i.value().x_enabled) {
ret << i.value().path(); ret << i.value().path();
@@ -642,7 +662,7 @@ void CDSection::makePath(PIDeque<int> p) {
tp = p; tp = p;
tp << i.key(); tp << i.key();
i.value().path_ = tp; i.value().path_ = tp;
//piCout << "path for" << i.value().name() << tp; // piCout << "path for" << i.value().name() << tp;
} }
for (auto j = s.begin(); j != s.end(); ++j) { for (auto j = s.begin(); j != s.end(); ++j) {
tp = p; tp = p;
@@ -652,10 +672,10 @@ void CDSection::makePath(PIDeque<int> p) {
} }
PIVector<CDType * > CDSection::children(bool recursive) const { PIVector<CDType *> CDSection::children(bool recursive) const {
PIVector<CDType * > ret; PIVector<CDType *> ret;
for (auto i = cd.begin(); i != cd.end(); ++i) { for (auto i = cd.begin(); i != cd.end(); ++i) {
ret << const_cast<CDType * >(&(i.value())); ret << const_cast<CDType *>(&(i.value()));
} }
if (!recursive) return ret; if (!recursive) return ret;
for (auto j = s.begin(); j != s.end(); ++j) { for (auto j = s.begin(); j != s.end(); ++j) {
@@ -672,5 +692,3 @@ PIVariantTypes::Enum CDSection::enumValues() const {
} }
return ret; return ret;
} }

View File

@@ -1,29 +1,29 @@
/* /*
CD Utils - Control-Debug utilites CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CDUTILS_TYPES_H #ifndef CDUTILS_TYPES_H
#define CDUTILS_TYPES_H #define CDUTILS_TYPES_H
#include "pistring.h"
#include "pimap.h"
#include "pivariant.h"
#include "cd_core_export.h" #include "cd_core_export.h"
#include "pimap.h"
#include "pistring.h"
#include "pivariant.h"
class PIIODevice; class PIIODevice;
class PIEvaluator; class PIEvaluator;
@@ -53,49 +53,59 @@ class CD_CORE_EXPORT CDType {
friend class CDCore; friend class CDCore;
friend class Interface; friend class Interface;
friend class XInterface; friend class XInterface;
public: public:
enum cdT {cdNull, cdK, cdX, cdC, cdM}; enum cdT {
enum XMode {X_Current, X_All_Avg}; cdNull,
cdK,
cdX,
cdC,
cdM
};
enum XMode {
X_Current,
X_All_Avg
};
CDType(); CDType();
CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t); CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t);
CDType & operator =(double x); CDType & operator=(double x);
int index() const {return index_;} int index() const { return index_; }
PIString name() const {return name_;} PIString name() const { return name_; }
PIString type() const; PIString type() const;
PIString value() const; PIString value() const;
PIVariant variantValue() const; PIVariant variantValue() const;
PIString formula() const {return formula_;} PIString formula() const { return formula_; }
PIString comment() const {return comment_;} PIString comment() const { return comment_; }
double toDouble() const {return value_d;} double toDouble() const { return value_d; }
int toInt() const {return value_i;} int toInt() const { return value_i; }
bool toBool() const {return value_b;} bool toBool() const { return value_b; }
cdT cd_type() const {return cd_type_;} cdT cd_type() const { return cd_type_; }
void setValue(const PIString & value_); void setValue(const PIString & value_);
void setVariantValue(const PIVariant & value_); void setVariantValue(const PIVariant & value_);
void setFormula(const PIString & formula); void setFormula(const PIString & formula);
void setComment(const PIString & comment) {comment_ = comment;} void setComment(const PIString & comment) { comment_ = comment; }
operator double() const {return value_d;} operator double() const { return value_d; }
const PIVariantTypes::Enum & enumValues() const {return enum_values;} const PIVariantTypes::Enum & enumValues() const { return enum_values; }
void setEnumValues(const PIVariantTypes::Enum & ev) {enum_values = ev;} void setEnumValues(const PIVariantTypes::Enum & ev) { enum_values = ev; }
const PIString & errorString() const {return error_;} const PIString & errorString() const { return error_; }
PIDeque<int> path() const {return path_;} PIDeque<int> path() const { return path_; }
PIStringList pathString() const; PIStringList pathString() const;
void setXMode(XMode mode) {mode_ = mode;} void setXMode(XMode mode) { mode_ = mode; }
void setAvg(int avg) {avg_size = avg;} void setAvg(int avg) { avg_size = avg; }
XMode xmode() const {return mode_;} XMode xmode() const { return mode_; }
XMode xmode_rec() const {return rmode_;} XMode xmode_rec() const { return rmode_; }
int avg() const {return avg_size;} int avg() const { return avg_size; }
bool isSelectedX() const {return x_enabled;} bool isSelectedX() const { return x_enabled; }
void readX(PIByteArray & ba); void readX(PIByteArray & ba);
void writeX(PIByteArray & ba); void writeX(PIByteArray & ba);
PIVector<double> history; PIVector<double> history;
protected: protected:
bool calculate(PIEvaluator * e, PIVector<const CDType * > stack = PIVector<const CDType * >()); bool calculate(PIEvaluator * e, PIVector<const CDType *> stack = PIVector<const CDType *>());
PIVariantTypes::Enum parseEnumComment(PIString c); PIVariantTypes::Enum parseEnumComment(PIString c);
cdT cd_type_; cdT cd_type_;
int index_; int index_;
@@ -120,27 +130,27 @@ class CD_CORE_EXPORT CDSection {
friend class ::CD_Pult; friend class ::CD_Pult;
friend class ::CDItem; friend class ::CDItem;
friend class ::CDItemModel; friend class ::CDItemModel;
public:
public:
CDSection(CDType::cdT type_ = CDType::cdNull); CDSection(CDType::cdT type_ = CDType::cdNull);
bool test(int v) {return cd.value(v).toBool();} bool test(int v) { return cd.value(v).toBool(); }
// CDType & operator [](int v) {if (!k.contains(v)) k[v].index_ = v; return k[v];} // CDType & operator [](int v) {if (!k.contains(v)) k[v].index_ = v; return k[v];}
CDType & operator [](int v) {return cd[v];} CDType & operator[](int v) { return cd[v]; }
CDType & operator [](const PIString & name_) {return getByName(name_);} CDType & operator[](const PIString & name_) { return getByName(name_); }
CDType & operator [](const PIDeque<int> & path_) {return getByPath(path_);} CDType & operator[](const PIDeque<int> & path_) { return getByPath(path_); }
CDSection & section(int v); CDSection & section(int v);
const CDSection section(int v) const; const CDSection section(int v) const;
bool isEmpty() const {return cd.isEmpty() && s.isEmpty();} bool isEmpty() const { return cd.isEmpty() && s.isEmpty(); }
bool exists(PIDeque<int> path) const; bool exists(PIDeque<int> path) const;
int count(bool recursive = true) const; int count(bool recursive = true) const;
int sectionsCount() const; int sectionsCount() const;
PIVector<int> indexes() const {return cd.keys();} PIVector<int> indexes() const { return cd.keys(); }
PIStringList index_names() const; PIStringList index_names() const;
void calculate(); void calculate();
void makePath(PIDeque<int> p = PIDeque<int>()); void makePath(PIDeque<int> p = PIDeque<int>());
PIVector<CDType * > children(bool recursive = true) const; PIVector<CDType *> children(bool recursive = true) const;
PIVariantTypes::Enum enumValues() const; PIVariantTypes::Enum enumValues() const;
PIString name; PIString name;
@@ -149,7 +159,7 @@ public:
protected: protected:
CDSection(PIMap<int, CDType> k_, PIMap<int, CDSection> s_) { CDSection(PIMap<int, CDType> k_, PIMap<int, CDSection> s_) {
cd = k_; cd = k_;
s = s_; s = s_;
} }
CDType & getByName(const PIString & name_); CDType & getByName(const PIString & name_);
CDType & getByPath(const PIDeque<int> & path_); CDType & getByPath(const PIDeque<int> & path_);
@@ -160,7 +170,7 @@ protected:
void prepareCalculate(); void prepareCalculate();
void calculateRecursive(PIEvaluator * e); void calculateRecursive(PIEvaluator * e);
void setSelectedX(bool yes); void setSelectedX(bool yes);
PIVector<PIDeque<int> > collectX() const; PIVector<PIDeque<int>> collectX() const;
PIMap<int, CDType> cd; PIMap<int, CDType> cd;
mutable PIMap<int, CDSection> s; mutable PIMap<int, CDSection> s;
@@ -168,18 +178,18 @@ protected:
CDType::cdT cd_type_; CDType::cdT cd_type_;
}; };
} } // namespace CDUtils
inline PICout operator <<(PICout s, const CDUtils::CDType & v) { inline PICout operator<<(PICout s, const CDUtils::CDType & v) {
s.space(); s.space();
s.saveAndSetControls(0); s.saveAndSetControls(0);
switch (v.cd_type()) { switch (v.cd_type()) {
case CDUtils::CDType::cdK : s << "K["; break; case CDUtils::CDType::cdK: s << "K["; break;
case CDUtils::CDType::cdX : s << "X["; break; case CDUtils::CDType::cdX: s << "X["; break;
case CDUtils::CDType::cdC : s << "C["; break; case CDUtils::CDType::cdC: s << "C["; break;
case CDUtils::CDType::cdM : s << "M["; break; case CDUtils::CDType::cdM: s << "M["; break;
default : s << "Null["; break; default: s << "Null["; break;
} }
s << v.name() << "(" << v.index() << ")] = " << v.value(); s << v.name() << "(" << v.index() << ")] = " << v.value();
s.restoreControls(); s.restoreControls();

View File

@@ -1,4 +1,5 @@
#include "cdutils_x.h" #include "cdutils_x.h"
#include "cdutils_core.h" #include "cdutils_core.h"
using namespace CDUtils; using namespace CDUtils;
@@ -18,19 +19,19 @@ void XInterface::setEnabled(const CDType & x, bool en) {
core->x_mutex.unlock(); core->x_mutex.unlock();
return; return;
} }
t.x_enabled = en; t.x_enabled = en;
//piCout << t << "x_enabled" << en; // piCout << t << "x_enabled" << en;
core->need_rebuild_x = true; core->need_rebuild_x = true;
core->x_mutex.unlock(); core->x_mutex.unlock();
} }
PIVector<PIDeque<int> > XInterface::enabledList() const { PIVector<PIDeque<int>> XInterface::enabledList() const {
return CDCore::instance()->x_selected; return CDCore::instance()->x_selected;
} }
void XInterface::setEnabledList(const PIVector<PIDeque<int> > & l) { void XInterface::setEnabledList(const PIVector<PIDeque<int>> & l) {
CDCore::instance()->x_selected = l; CDCore::instance()->x_selected = l;
} }

View File

@@ -1,56 +1,55 @@
/* /*
CD Utils - Control-Debug utilites CD Utils - Control-Debug utilites
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CDUTILS_X_H #ifndef CDUTILS_X_H
#define CDUTILS_X_H #define CDUTILS_X_H
#include "cdutils_interface.h"
#include "cd_core_export.h" #include "cd_core_export.h"
#include "cdutils_interface.h"
namespace CDUtils { namespace CDUtils {
class CD_CORE_EXPORT XInterface: public Interface class CD_CORE_EXPORT XInterface: public Interface {
{
PIOBJECT_SUBCLASS(XInterface, Interface); PIOBJECT_SUBCLASS(XInterface, Interface);
public: public:
XInterface(); XInterface();
EVENT1(keepNamesRequest, bool*, xn); EVENT1(keepNamesRequest, bool *, xn);
EVENT1(receivedX, PIVector<PIDeque<int> >, pathes); EVENT1(receivedX, PIVector<PIDeque<int>>, pathes);
void enable(const CDType & x) {setEnabled(x, true);} void enable(const CDType & x) { setEnabled(x, true); }
void disable(const CDType & x) {setEnabled(x, false);} void disable(const CDType & x) { setEnabled(x, false); }
void setEnabled(const CDType & x, bool en); void setEnabled(const CDType & x, bool en);
void setDisabled(const CDType & x, bool dis) {setEnabled(x, !dis);} void setDisabled(const CDType & x, bool dis) { setEnabled(x, !dis); }
PIVector<PIDeque<int> > enabledList() const; PIVector<PIDeque<int>> enabledList() const;
void setEnabledList(const PIVector<PIDeque<int> > & l); void setEnabledList(const PIVector<PIDeque<int>> & l);
void lock(); void lock();
void unlock(); void unlock();
void start(double freq = 20.); void start(double freq = 20.);
void stop(); void stop();
}; };
} } // namespace CDUtils
extern CD_CORE_EXPORT CDUtils::XInterface X; extern CD_CORE_EXPORT CDUtils::XInterface X;

View File

@@ -1,17 +1,17 @@
#include "cdutils_k.h"
#include "cdutils_x.h"
#include "cdutils_c.h"
#include "cdutils_m.h"
#include "cdutils_core.h"
#include "cdtest.h" #include "cdtest.h"
#include "pip.h" #include "cdutils_c.h"
#include "cdutils_core.h"
#include "cdutils_k.h"
#include "cdutils_m.h"
#include "cdutils_x.h"
#include "k_description.h" #include "k_description.h"
#include "pip.h"
using namespace CDUtils; using namespace CDUtils;
class Core : public PIObject class Core: public PIObject {
{
PIOBJECT(Core); PIOBJECT(Core);
public: public:
Core() { Core() {
CDCore::instance()->initApp(); CDCore::instance()->initApp();
@@ -33,25 +33,25 @@ public:
rf.resize(0); rf.resize(0);
K.write(&rf); K.write(&rf);
rf.close(); rf.close();
// rf.open("k_out.txt", PIIODevice::ReadWrite); // rf.open("k_out.txt", PIIODevice::ReadWrite);
// K.read(&rf); // K.read(&rf);
// rf.close(); // rf.close();
// rf.open("k_out2.txt", PIIODevice::ReadWrite); // rf.open("k_out2.txt", PIIODevice::ReadWrite);
// rf.resize(0); // rf.resize(0);
// K.write(&rf); // K.write(&rf);
// rf.close(); // rf.close();
// rf.open("k_out2.txt", PIIODevice::ReadWrite); // rf.open("k_out2.txt", PIIODevice::ReadWrite);
// K.read(&rf); // K.read(&rf);
// rf.close(); // rf.close();
// rf.open("k_out3.txt", PIIODevice::ReadWrite); // rf.open("k_out3.txt", PIIODevice::ReadWrite);
// rf.resize(0); // rf.resize(0);
// K.write(&rf); // K.write(&rf);
// rf.close(); // rf.close();
} }
void test() { void test() {
X.lock(); X.lock();
X[KD::Frequency] = 100; X[KD::Frequency] = 100;
X.section(KD::Spectrometer)[KD::Temperature_default] = sin(t); X.section(KD::Spectrometer)[KD::Temperature_default] = sin(t);
t += 0.01; t += 0.01;
X.unlock(); X.unlock();
@@ -60,7 +60,7 @@ public:
piCout << K[Second];*/ piCout << K[Second];*/
} }
EVENT_HANDLER(void, ksend) {piCout << "sended k";} EVENT_HANDLER(void, ksend) { piCout << "sended k"; }
EVENT_HANDLER(void, crecv) { EVENT_HANDLER(void, crecv) {
piCout << "received c"; piCout << "received c";
C.connect(C.section(KD::Logs).section(KD::Spec).section(KD::Formats)[KD::Binary], this, HANDLER(cmd)); C.connect(C.section(KD::Logs).section(KD::Spec).section(KD::Formats)[KD::Binary], this, HANDLER(cmd));
@@ -71,14 +71,14 @@ public:
if (!timer.isRunning()) timer.start(10); if (!timer.isRunning()) timer.start(10);
X.start(); X.start();
} }
EVENT_HANDLER(void, timerDone) {test();} EVENT_HANDLER(void, timerDone) { test(); }
EVENT_HANDLER(void, cmd) {piCout << "command cmd";} EVENT_HANDLER(void, cmd) { piCout << "command cmd"; }
EVENT_HANDLER(void, c_Pause) { EVENT_HANDLER(void, c_Pause) {
piCout << "command pause"; piCout << "command pause";
M[KD::Main] << "rec command" << C[KD::Pause]; M[KD::Main] << "rec command" << C[KD::Pause];
M.messageBox(M.root()[KD::Core], "init successfull"); M.messageBox(M.root()[KD::Core], "init successfull");
} }
EVENT_HANDLER(void, c_Spectrometer_Connection) {piCout << "command spec_conn";} EVENT_HANDLER(void, c_Spectrometer_Connection) { piCout << "command spec_conn"; }
private: private:
PIFile rf; PIFile rf;
@@ -87,11 +87,10 @@ private:
}; };
int main(int argc, char *argv[]) { int main(int argc, char * argv[]) {
X.start(); X.start();
piSleep(1); piSleep(1);
//CDCore::instance()->destroy(); // CDCore::instance()->destroy();
piCout << "DELETED"; piCout << "DELETED";
return 0; return 0;
} }

View File

@@ -1,20 +1,22 @@
#include "qcd_core.h" #include "qcd_core.h"
#include "cdutils_k.h"
#include "cdutils_core.h" #include "cdutils_core.h"
#include "cdutils_k.h"
#include "piqt.h" #include "piqt.h"
#include <QWidget>
#include <QCheckBox> #include <QCheckBox>
#include <QGroupBox>
#include <QSpinBox>
#include <QSlider>
#include <QScrollBar>
#include <QDoubleSpinBox> #include <QDoubleSpinBox>
#include <QGroupBox>
#include <QLineEdit> #include <QLineEdit>
#include <spinslider.h> #include <QScrollBar>
#include <QSlider>
#include <QSpinBox>
#include <QWidget>
#include <clineedit.h> #include <clineedit.h>
#include <evalspinbox.h> #include <evalspinbox.h>
#include <qvariantedit.h>
#include <qcd_view.h> #include <qcd_view.h>
#include <qvariantedit.h>
#include <spinslider.h>
using namespace CDUtils; using namespace CDUtils;
@@ -40,8 +42,6 @@ __QCore_Initializer__::~__QCore_Initializer__() {
} }
QCDCore::QCDCore() { QCDCore::QCDCore() {
setObjectName("QCDCore"); setObjectName("QCDCore");
setName("QCDCore"); setName("QCDCore");
@@ -50,8 +50,7 @@ QCDCore::QCDCore() {
} }
QCDCore::~QCDCore() { QCDCore::~QCDCore() {}
}
void QCDCore::K_ChangedGlobal() { void QCDCore::K_ChangedGlobal() {
@@ -60,10 +59,10 @@ void QCDCore::K_ChangedGlobal() {
void QCDCore::slotBool(bool v) { void QCDCore::slotBool(bool v) {
QWidget * w = (QWidget*)sender(); QWidget * w = (QWidget *)sender();
if (!w || updating) return; if (!w || updating) return;
QList<PIDeque<int> > pathes = binded_widgets.values(w); QList<PIDeque<int>> pathes = binded_widgets.values(w);
foreach (const PIDeque<int> & path, pathes) foreach(const PIDeque<int> & path, pathes)
K[path].setValue(PIString::fromBool(v)); K[path].setValue(PIString::fromBool(v));
K.calculate(); K.calculate();
emit updateViewRequest(); emit updateViewRequest();
@@ -71,40 +70,40 @@ void QCDCore::slotBool(bool v) {
void QCDCore::slotInt(int v) { void QCDCore::slotInt(int v) {
QWidget * w = (QWidget*)sender(); QWidget * w = (QWidget *)sender();
if (!w || updating) return; if (!w || updating) return;
QList<PIDeque<int> > pathes = binded_widgets.values(w); QList<PIDeque<int>> pathes = binded_widgets.values(w);
foreach (const PIDeque<int> & path, pathes) foreach(const PIDeque<int> & path, pathes)
K[path].setValue(PIString::fromNumber(v)); K[path].setValue(PIString::fromNumber(v));
finishEdit(pathes); finishEdit(pathes);
} }
void QCDCore::slotDouble(double v) { void QCDCore::slotDouble(double v) {
QWidget * w = (QWidget*)sender(); QWidget * w = (QWidget *)sender();
if (!w || updating) return; if (!w || updating) return;
QList<PIDeque<int> > pathes = binded_widgets.values(w); QList<PIDeque<int>> pathes = binded_widgets.values(w);
foreach (const PIDeque<int> & path, pathes) foreach(const PIDeque<int> & path, pathes)
K[path].setValue(PIString::fromNumber(v)); K[path].setValue(PIString::fromNumber(v));
finishEdit(pathes); finishEdit(pathes);
} }
void QCDCore::slotText(QString v) { void QCDCore::slotText(QString v) {
QWidget * w = (QWidget*)sender(); QWidget * w = (QWidget *)sender();
if (!w || updating) return; if (!w || updating) return;
QList<PIDeque<int> > pathes = binded_widgets.values(w); QList<PIDeque<int>> pathes = binded_widgets.values(w);
foreach (const PIDeque<int> & path, pathes) foreach(const PIDeque<int> & path, pathes)
K[path].setValue(Q2PIString(v)); K[path].setValue(Q2PIString(v));
finishEdit(pathes); finishEdit(pathes);
} }
void QCDCore::slotVariant(QVariant v) { void QCDCore::slotVariant(QVariant v) {
QWidget * w = (QWidget*)sender(); QWidget * w = (QWidget *)sender();
if (!w || updating) return; if (!w || updating) return;
QList<PIDeque<int> > pathes = binded_widgets.values(w); QList<PIDeque<int>> pathes = binded_widgets.values(w);
foreach (const PIDeque<int> & path, pathes) foreach(const PIDeque<int> & path, pathes)
K[path].setVariantValue(Q2PIVariant(v)); K[path].setVariantValue(Q2PIVariant(v));
finishEdit(pathes); finishEdit(pathes);
} }
@@ -112,21 +111,21 @@ void QCDCore::slotVariant(QVariant v) {
void QCDCore::slotDestroyed(QObject * o) { void QCDCore::slotDestroyed(QObject * o) {
if (!o) return; if (!o) return;
if (!binded_widgets.contains((QWidget*)o)) return; if (!binded_widgets.contains((QWidget *)o)) return;
binded_widgets.remove((QWidget*)o); binded_widgets.remove((QWidget *)o);
} }
int QCDCore::bindWindow(QWidget * wnd) { int QCDCore::bindWindow(QWidget * wnd) {
if (!wnd) return 0; if (!wnd) return 0;
//K.root().makePath(); // K.root().makePath();
return bindWidgets(wnd->findChildren<QWidget * >()); return bindWidgets(wnd->findChildren<QWidget *>());
} }
int QCDCore::bindWidgets(QList<QWidget * > wl) { int QCDCore::bindWidgets(QList<QWidget *> wl) {
int ret = 0; int ret = 0;
foreach (QWidget * w, wl) foreach(QWidget * w, wl)
if (bindWidget(w)) ++ret; if (bindWidget(w)) ++ret;
return ret; return ret;
} }
@@ -140,8 +139,8 @@ bool QCDCore::bindWidget(QWidget * w) {
bindView(w); bindView(w);
return false; return false;
} }
PIVector<CDType * > ak = K.root().children(); PIVector<CDType *> ak = K.root().children();
piForeachC (CDType * k, ak) { piForeachC(CDType * k, ak) {
if (!on.endsWith(PI2QString(k->pathString().join("_")))) continue; if (!on.endsWith(PI2QString(k->pathString().join("_")))) continue;
if (bindWidget(w, *k)) return true; if (bindWidget(w, *k)) return true;
} }
@@ -151,9 +150,9 @@ bool QCDCore::bindWidget(QWidget * w) {
bool QCDCore::bindWidget(QWidget * w, const CDType & k) { bool QCDCore::bindWidget(QWidget * w, const CDType & k) {
if (!w) return false; if (!w) return false;
//piCout << "bind..." << k.name() << k.path(); // piCout << "bind..." << k.name() << k.path();
QString cn = w->metaObject()->className(); QString cn = w->metaObject()->className();
bool ok = false; bool ok = false;
if (cn == "QCheckBox" || cn == "QGroupBox") { if (cn == "QCheckBox" || cn == "QGroupBox") {
connect(w, SIGNAL(toggled(bool)), this, SLOT(slotBool(bool)), Qt::UniqueConnection); connect(w, SIGNAL(toggled(bool)), this, SLOT(slotBool(bool)), Qt::UniqueConnection);
ok = true; ok = true;
@@ -177,17 +176,17 @@ bool QCDCore::bindWidget(QWidget * w, const CDType & k) {
if (cn == "CDView") { if (cn == "CDView") {
bindView(w); bindView(w);
} }
connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(slotDestroyed(QObject*)), Qt::UniqueConnection); connect(w, SIGNAL(destroyed(QObject *)), this, SLOT(slotDestroyed(QObject *)), Qt::UniqueConnection);
setWidgetValue(w, k); setWidgetValue(w, k);
if (!ok) return false; if (!ok) return false;
//piCout << k.name() << k.path() << "ok"; // piCout << k.name() << k.path() << "ok";
binded_widgets.insert(w, k.path()); binded_widgets.insert(w, k.path());
return true; return true;
} }
void QCDCore::updateBindedWidgets() { void QCDCore::updateBindedWidgets() {
QMultiMapIterator<QWidget * , PIDeque<int> > it(binded_widgets); QMultiMapIterator<QWidget *, PIDeque<int>> it(binded_widgets);
QWidgetList to_remove; QWidgetList to_remove;
updating = true; updating = true;
while (it.hasNext()) { while (it.hasNext()) {
@@ -197,14 +196,14 @@ void QCDCore::updateBindedWidgets() {
else else
setWidgetValue(w, K[it.value()]); setWidgetValue(w, K[it.value()]);
} }
foreach (QWidget * w, to_remove) foreach(QWidget * w, to_remove)
unbindWidget(w); unbindWidget(w);
updating = false; updating = false;
} }
void QCDCore::bindView(QWidget * v) { void QCDCore::bindView(QWidget * v) {
CDView * w = qobject_cast<CDView * >(v); CDView * w = qobject_cast<CDView *>(v);
if (!w) return; if (!w) return;
connect(this, SIGNAL(updateViewRequest()), w, SLOT(refreshValues()), Qt::UniqueConnection); connect(this, SIGNAL(updateViewRequest()), w, SLOT(refreshValues()), Qt::UniqueConnection);
} }
@@ -213,24 +212,24 @@ void QCDCore::bindView(QWidget * v) {
void QCDCore::setWidgetValue(QWidget * w, const CDType & k) { void QCDCore::setWidgetValue(QWidget * w, const CDType & k) {
if (!w) return; if (!w) return;
QString cn = w->metaObject()->className(); QString cn = w->metaObject()->className();
if (cn == "QCheckBox") qobject_cast<QCheckBox*>(w)->setChecked(k.toBool()); if (cn == "QCheckBox") qobject_cast<QCheckBox *>(w)->setChecked(k.toBool());
if (cn == "QGroupBox") qobject_cast<QGroupBox*>(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 == "QSpinBox") qobject_cast<QSpinBox *>(w)->setValue(k.toInt());
if (cn == "QSlider") qobject_cast<QSlider*>(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 == "QScrollBar") qobject_cast<QScrollBar *>(w)->setValue(k.toInt());
if (cn == "QDoubleSpinBox") qobject_cast<QDoubleSpinBox*>(w)->setValue(k.toDouble()); if (cn == "QDoubleSpinBox") qobject_cast<QDoubleSpinBox *>(w)->setValue(k.toDouble());
if (cn == "SpinSlider") qobject_cast<SpinSlider*>(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 == "QLineEdit") qobject_cast<QLineEdit *>(w)->setText(PI2QString(k.value()));
if (cn == "CLineEdit") qobject_cast<CLineEdit*>(w)->setText(PI2QString(k.value())); if (cn == "CLineEdit") qobject_cast<CLineEdit *>(w)->setText(PI2QString(k.value()));
if (cn == "EvalSpinBox") qobject_cast<EvalSpinBox*>(w)->setValue(k.toDouble()); if (cn == "EvalSpinBox") qobject_cast<EvalSpinBox *>(w)->setValue(k.toDouble());
if (cn == "QVariantEdit") qobject_cast<QVariantEdit*>(w)->setValue(PI2QVariant(k.variantValue())); if (cn == "QVariantEdit") qobject_cast<QVariantEdit *>(w)->setValue(PI2QVariant(k.variantValue()));
} }
void QCDCore::finishEdit(const QList<PIDeque<int> > & pathes) { void QCDCore::finishEdit(const QList<PIDeque<int>> & pathes) {
K.calculate(); K.calculate();
if (direct_on) { if (direct_on) {
foreach (const PIDeque<int> & path, pathes) foreach(const PIDeque<int> & path, pathes)
K.directChange(K[path]); K.directChange(K[path]);
} }
emit updateViewRequest(); emit updateViewRequest();
@@ -239,13 +238,13 @@ void QCDCore::finishEdit(const QList<PIDeque<int> > & pathes) {
int QCDCore::unbindWindow(QWidget * wnd) { int QCDCore::unbindWindow(QWidget * wnd) {
if (!wnd) return 0; if (!wnd) return 0;
return unbindWidgets(wnd->findChildren<QWidget * >()); return unbindWidgets(wnd->findChildren<QWidget *>());
} }
int QCDCore::unbindWidgets(QList<QWidget * > wl) { int QCDCore::unbindWidgets(QList<QWidget *> wl) {
int ret = 0; int ret = 0;
foreach (QWidget * w, wl) foreach(QWidget * w, wl)
if (unbindWidget(w)) ++ret; if (unbindWidget(w)) ++ret;
return ret; return ret;
} }
@@ -253,29 +252,25 @@ int QCDCore::unbindWidgets(QList<QWidget * > wl) {
bool QCDCore::unbindWidget(QWidget * w) { bool QCDCore::unbindWidget(QWidget * w) {
if (!w) return false; if (!w) return false;
//qDebug() << "unbind" << w; // qDebug() << "unbind" << w;
if (!binded_widgets.contains(w)) return false; if (!binded_widgets.contains(w)) return false;
QString cn = w->metaObject()->className(); QString cn = w->metaObject()->className();
if (cn == "QCheckBox" || cn == "QGroupBox") if (cn == "QCheckBox" || cn == "QGroupBox") disconnect(w, SIGNAL(toggled(bool)), this, SLOT(slotBool(bool)));
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 == "QSpinBox" || cn == "QSlider" || cn == "QScrollBar")
disconnect(w, SIGNAL(valueChanged(int)), this, SLOT(slotInt(int)));
if (cn == "QDoubleSpinBox" || cn == "SpinSlider" || cn == "EvalSpinBox") if (cn == "QDoubleSpinBox" || cn == "SpinSlider" || cn == "EvalSpinBox")
disconnect(w, SIGNAL(valueChanged(double)), this, SLOT(slotDouble(double))); disconnect(w, SIGNAL(valueChanged(double)), this, SLOT(slotDouble(double)));
if (cn == "QLineEdit" || cn == "CLineEdit") if (cn == "QLineEdit" || cn == "CLineEdit") disconnect(w, SIGNAL(textChanged(QString)), this, SLOT(slotText(QString)));
disconnect(w, SIGNAL(textChanged(QString)), this, SLOT(slotText(QString))); if (cn == "QVariantEdit") disconnect(w, SIGNAL(valueChanged(QVariant)), this, SLOT(slotVariant(QVariant)));
if (cn == "QVariantEdit") // qDebug() << "remove b" << binded_widgets.size();
disconnect(w, SIGNAL(valueChanged(QVariant)), this, SLOT(slotVariant(QVariant)));
//qDebug() << "remove b" << binded_widgets.size();
binded_widgets.remove(w); binded_widgets.remove(w);
//qDebug() << "remove a" << binded_widgets.size(); // qDebug() << "remove a" << binded_widgets.size();
return true; return true;
} }
void QCDCore::unbindAllWidgets() { void QCDCore::unbindAllWidgets() {
QList<QWidget * > bwk = binded_widgets.keys(); QList<QWidget *> bwk = binded_widgets.keys();
foreach (QWidget * w, bwk) { foreach(QWidget * w, bwk) {
unbindWidget(w); unbindWidget(w);
} }
binded_widgets.clear(); binded_widgets.clear();
@@ -283,7 +278,7 @@ void QCDCore::unbindAllWidgets() {
void QCDCore::updateBindedWidget(const CDType & k_) { void QCDCore::updateBindedWidget(const CDType & k_) {
QMultiMapIterator<QWidget * , PIDeque<int> > it(binded_widgets); QMultiMapIterator<QWidget *, PIDeque<int>> it(binded_widgets);
updating = true; updating = true;
while (it.hasNext()) { while (it.hasNext()) {
QWidget * w = it.next().key(); QWidget * w = it.next().key();

View File

@@ -1,31 +1,32 @@
/* /*
QCD Utils - Qt bindings/utilites for CD Utils QCD Utils - Qt bindings/utilites for CD Utils
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef QCD_CORE_H #ifndef QCD_CORE_H
#define QCD_CORE_H #define QCD_CORE_H
#include <QObject>
#include <QMultiMap>
#include <QVariant>
#include "piobject.h"
#include "cdutils_types.h"
#include "cd_qt_export.h" #include "cd_qt_export.h"
#include "cdutils_types.h"
#include "piobject.h"
#include <QMultiMap>
#include <QObject>
#include <QVariant>
class QCDCore; class QCDCore;
@@ -40,27 +41,29 @@ public:
}; };
class CD_QT_EXPORT QCDCore: public QObject, public PIObject class CD_QT_EXPORT QCDCore
{ : public QObject
, public PIObject {
Q_OBJECT Q_OBJECT
PIOBJECT(QCDCore); PIOBJECT(QCDCore);
friend class __QCore_Initializer__; friend class __QCore_Initializer__;
public: public:
static QCDCore * instance() {return __QCore_Initializer__::__instance__;} static QCDCore * instance() { return __QCore_Initializer__::__instance__; }
int bindWindow(QWidget * wnd); int bindWindow(QWidget * wnd);
int bindWidgets(QList<QWidget * > wl); int bindWidgets(QList<QWidget *> wl);
bool bindWidget(QWidget * w); bool bindWidget(QWidget * w);
bool bindWidget(QWidget * w, const CDUtils::CDType & k); bool bindWidget(QWidget * w, const CDUtils::CDType & k);
int unbindWindow(QWidget * wnd); int unbindWindow(QWidget * wnd);
int unbindWidgets(QList<QWidget * > wl); int unbindWidgets(QList<QWidget *> wl);
bool unbindWidget(QWidget * w); bool unbindWidget(QWidget * w);
void unbindAllWidgets(); void unbindAllWidgets();
void updateBindedWidget(const CDUtils::CDType & k_); void updateBindedWidget(const CDUtils::CDType & k_);
void setDirectKEnabled(bool yes) {direct_on = yes;} void setDirectKEnabled(bool yes) { direct_on = yes; }
bool isDirectKEnabled() const {return direct_on;} bool isDirectKEnabled() const { return direct_on; }
private: private:
QCDCore(); QCDCore();
@@ -68,10 +71,10 @@ private:
void bindView(QWidget * v); void bindView(QWidget * v);
void setWidgetValue(QWidget * w, const CDUtils::CDType & k); void setWidgetValue(QWidget * w, const CDUtils::CDType & k);
void finishEdit(const QList<PIDeque<int> > & pathes); void finishEdit(const QList<PIDeque<int>> & pathes);
EVENT_HANDLER(void, K_ChangedGlobal); EVENT_HANDLER(void, K_ChangedGlobal);
QMultiMap<QWidget * , PIDeque<int> > binded_widgets; QMultiMap<QWidget *, PIDeque<int>> binded_widgets;
bool updating, direct_on; bool updating, direct_on;
private slots: private slots:
@@ -80,14 +83,13 @@ private slots:
void slotDouble(double v); void slotDouble(double v);
void slotText(QString v); void slotText(QString v);
void slotVariant(QVariant v); void slotVariant(QVariant v);
void slotDestroyed(QObject * ); void slotDestroyed(QObject *);
public slots: public slots:
void updateBindedWidgets(); void updateBindedWidgets();
signals: signals:
void updateViewRequest(); void updateViewRequest();
}; };

View File

@@ -1,9 +1,10 @@
#include "qcd_graphic.h" #include "qcd_graphic.h"
#include "ui_qcd_graphic.h"
#include "cdutils_core.h" #include "cdutils_core.h"
#include "cdutils_x.h" #include "cdutils_x.h"
#include "graphic.h" #include "graphic.h"
#include "piqt.h" #include "piqt.h"
#include "ui_qcd_graphic.h"
using namespace CDUtils; using namespace CDUtils;

View File

@@ -1,37 +1,38 @@
/* /*
QCD Utils - Qt bindings/utilites for CD Utils QCD Utils - Qt bindings/utilites for CD Utils
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef QCD_GRAPHIC_H #ifndef QCD_GRAPHIC_H
#define QCD_GRAPHIC_H #define QCD_GRAPHIC_H
#include "cd_qt_export.h"
#include <QWidget> #include <QWidget>
#include <evalspinbox.h> #include <evalspinbox.h>
#include <pistring.h> #include <pistring.h>
#include "cd_qt_export.h"
namespace CDUtils { namespace CDUtils {
class CDType; class CDType;
class CDSection; class CDSection;
} } // namespace CDUtils
namespace Ui { namespace Ui {
class CDGraphicWidget; class CDGraphicWidget;
} }
class Graphic; class Graphic;
@@ -42,6 +43,7 @@ class CD_QT_EXPORT CDGraphicWidget: public QWidget {
Q_OBJECT Q_OBJECT
friend class CDGraphics; friend class CDGraphics;
friend class GDockWidget; friend class GDockWidget;
public: public:
CDGraphicWidget(QWidget * p = 0); CDGraphicWidget(QWidget * p = 0);
@@ -60,7 +62,6 @@ private:
private slots: private slots:
signals: signals:
}; };

View File

@@ -1,4 +1,5 @@
#include "qcd_modedialog.h" #include "qcd_modedialog.h"
#include "ui_qcd_modedialog.h" #include "ui_qcd_modedialog.h"
@@ -22,14 +23,11 @@ CDUtils::UpdateModeFlags QCDModeDialog::mode() const {
} }
void QCDModeDialog::changeEvent(QEvent *e) { void QCDModeDialog::changeEvent(QEvent * e) {
QDialog::changeEvent(e); QDialog::changeEvent(e);
switch (e->type()) { switch (e->type()) {
case QEvent::LanguageChange: case QEvent::LanguageChange: ui->retranslateUi(this); break;
ui->retranslateUi(this); default: break;
break;
default:
break;
} }
} }

View File

@@ -1,36 +1,37 @@
/* /*
QCD Utils - Qt bindings/utilites for CD Utils QCD Utils - Qt bindings/utilites for CD Utils
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef QCD_MODEDIALOG_H #ifndef QCD_MODEDIALOG_H
#define QCD_MODEDIALOG_H #define QCD_MODEDIALOG_H
#include <QDialog>
#include <cdutils_types.h>
#include "cd_qt_export.h" #include "cd_qt_export.h"
#include <QDialog>
#include <cdutils_types.h>
namespace Ui { namespace Ui {
class QCDModeDialog; class QCDModeDialog;
} }
class CD_QT_EXPORT QCDModeDialog: public QDialog class CD_QT_EXPORT QCDModeDialog: public QDialog {
{
Q_OBJECT Q_OBJECT
public: public:
explicit QCDModeDialog(QWidget * parent = 0); explicit QCDModeDialog(QWidget * parent = 0);
~QCDModeDialog(); ~QCDModeDialog();
@@ -38,14 +39,13 @@ public:
CDUtils::UpdateModeFlags mode() const; CDUtils::UpdateModeFlags mode() const;
protected: protected:
void changeEvent(QEvent *e); void changeEvent(QEvent * e);
Ui::QCDModeDialog * ui; Ui::QCDModeDialog * ui;
private slots: private slots:
void on_checkSaveIndex_clicked(bool checked); void on_checkSaveIndex_clicked(bool checked);
void on_checkSaveName_clicked(bool checked); void on_checkSaveName_clicked(bool checked);
}; };
#endif // QCD_MODEDIALOG_H #endif // QCD_MODEDIALOG_H

View File

@@ -1,28 +1,30 @@
#include "qcd_model.h" #include "qcd_model.h"
#include "cdutils_interface.h"
#include "cdutils_core.h" #include "cdutils_core.h"
#include "cdutils_interface.h"
#include "cdutils_x.h" #include "cdutils_x.h"
#include "piqt.h" #include "piqt.h"
#include <QDebug> #include "qad_types.h"
#include "qvariantedit.h"
#include <QBrush> #include <QBrush>
#include <QColor> #include <QColor>
#include <QDebug>
#include <QMimeData> #include <QMimeData>
#include <QPainter> #include <QPainter>
#include "qvariantedit.h"
#include "qad_types.h"
using namespace CDUtils; using namespace CDUtils;
// CDKItem // CDKItem
CDItem::CDItem(CDUtils::Interface * i, int _index, CDItem::CDItemType type, CDItem *parent) { CDItem::CDItem(CDUtils::Interface * i, int _index, CDItem::CDItemType type, CDItem * parent) {
interface = i; interface = i;
index_ = _index; index_ = _index;
parent_ = parent; parent_ = parent;
type_ = type; type_ = type;
item_count = 0; item_count = 0;
expanded = true; expanded = true;
} }
@@ -34,19 +36,23 @@ CDItem::~CDItem() {
QVariant CDItem::data(int column, int role) const { QVariant CDItem::data(int column, int role) const {
if (role == Qt::BackgroundRole) { if (role == Qt::BackgroundRole) {
switch (type_) { switch (type_) {
case ItemCDType: { case ItemCDType: {
CDType & t(interface->section(buildPath())[index_]); CDType & t(interface->section(buildPath())[index_]);
if (t.errorString().isEmpty()) return QBrush(QColor(255, 250, 230)); if (t.errorString().isEmpty())
else return QBrush(QColor(255, 128, 128)); return QBrush(QColor(255, 250, 230));
} else
case ItemCDSection: return QBrush(QColor(230, 250, 230)); return QBrush(QColor(255, 128, 128));
}
case ItemCDSection: return QBrush(QColor(230, 250, 230));
} }
} }
if (role == Qt::CheckStateRole && type_ == ItemCDType) { if (role == Qt::CheckStateRole && type_ == ItemCDType) {
CDType & t(interface->section(buildPath())[index_]); CDType & t(interface->section(buildPath())[index_]);
if (column == cValue && t.cd_type() == CDType::cdK) { if (column == cValue && t.cd_type() == CDType::cdK) {
if (t.type() == "b") return t.toBool() ? Qt::Checked : Qt::Unchecked; if (t.type() == "b")
else QVariant(); return t.toBool() ? Qt::Checked : Qt::Unchecked;
else
QVariant();
} }
if (column == cName_Cmd && t.cd_type() == CDType::cdX) { if (column == cName_Cmd && t.cd_type() == CDType::cdX) {
return t.isSelectedX() ? Qt::Checked : Qt::Unchecked; return t.isSelectedX() ? Qt::Checked : Qt::Unchecked;
@@ -58,31 +64,31 @@ QVariant CDItem::data(int column, int role) const {
} }
if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant(); if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant();
PIDeque<int> path = buildPath(); PIDeque<int> path = buildPath();
CDSection & rs = interface->section(path); CDSection & rs = interface->section(path);
CDSection s; CDSection s;
switch (type_) { switch (type_) {
case ItemCDType: case ItemCDType:
switch (column) { switch (column) {
case cID: return QString::number(index_); case cID: return QString::number(index_);
case cName_Cmd: return PI2QString(rs[index_].name()); case cName_Cmd: return PI2QString(rs[index_].name());
case cType: return stringType(rs[index_].type()); case cType: return stringType(rs[index_].type());
case cXMode: return QVariant::fromValue(xModeEnum(rs[index_].xmode())); case cXMode: return QVariant::fromValue(xModeEnum(rs[index_].xmode()));
case cXAvg: return rs[index_].avg(); case cXAvg: return rs[index_].avg();
case cExpression: return PI2QString(rs[index_].formula()); case cExpression: return PI2QString(rs[index_].formula());
case cValue: return value(rs[index_], role); case cValue: return value(rs[index_], role);
case cComment: return PI2QString(rs[index_].comment()); case cComment: return PI2QString(rs[index_].comment());
default: break; default: break;
} }
break; break;
case ItemCDSection: case ItemCDSection:
s = rs.section(index_); s = rs.section(index_);
// piCout << rs.name << rs.alias << s.name << s.alias; // piCout << rs.name << rs.alias << s.name << s.alias;
switch (column) { switch (column) {
case cID: return QString("[") + QString::number(index_) + QString("]"); case cID: return QString("[") + QString::number(index_) + QString("]");
case cName_Cmd: return PI2QString(s.alias); case cName_Cmd: return PI2QString(s.alias);
case cType: return PI2QString(s.name); case cType: return PI2QString(s.name);
default: break; default: break;
} }
break; break;
} }
return QVariant(); return QVariant();
@@ -96,8 +102,10 @@ QVariant CDItem::value(CDType & t, int role) const {
if (t.type() == "e") { if (t.type() == "e") {
QAD::Enum et = PI2QADEnum(t.enumValues()); QAD::Enum et = PI2QADEnum(t.enumValues());
et.selectValue(t.toInt()); et.selectValue(t.toInt());
if (role == Qt::EditRole) return QVariant::fromValue<QAD::Enum>(et); if (role == Qt::EditRole)
else return et.selectedName(); return QVariant::fromValue<QAD::Enum>(et);
else
return et.selectedName();
} }
return PI2QString(t.value()); return PI2QString(t.value());
} }
@@ -113,15 +121,9 @@ bool CDItem::setData(int column, const QVariant & value) {
} }
if (t.cd_type() == CDType::cdX) { if (t.cd_type() == CDType::cdX) {
switch (column) { switch (column) {
case cName_Cmd: case cName_Cmd: X.setEnabled(t, value.toBool()); return true;
X.setEnabled(t, value.toBool()); case cXMode: t.setXMode((CDType::XMode)value.toInt()); return true;
return true; case cXAvg: t.setAvg(piMax(value.toInt(), 1)); return true;
case cXMode:
t.setXMode((CDType::XMode)value.toInt());
return true;
case cXAvg:
t.setAvg(piMax(value.toInt(), 1));
return true;
default: break; default: break;
} }
} }
@@ -166,8 +168,7 @@ QString CDItem::stringType(const PIString & t) const {
QAD::Enum CDItem::xModeEnum(int v) const { QAD::Enum CDItem::xModeEnum(int v) const {
QAD::Enum ret; QAD::Enum ret;
ret << QAD::Enumerator(CDType::X_Current, "Current") ret << QAD::Enumerator(CDType::X_Current, "Current") << QAD::Enumerator(CDType::X_All_Avg, "All, Averaging");
<< QAD::Enumerator(CDType::X_All_Avg, "All, Averaging");
ret.selectValue(v); ret.selectValue(v);
return ret; return ret;
} }
@@ -175,12 +176,11 @@ QAD::Enum CDItem::xModeEnum(int v) const {
// CDKDelegate // CDKDelegate
CDDelegate::CDDelegate(QObject *parent) : QStyledItemDelegate(parent) { CDDelegate::CDDelegate(QObject * parent): QStyledItemDelegate(parent) {}
}
void CDDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { void CDDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const {
CDItem * item = ((CDItemModel*)index.model())->getItem(index); CDItem * item = ((CDItemModel *)index.model())->getItem(index);
if (item) { if (item) {
if (item->itemType() == CDItem::ItemCDType && item->interface->cdType() == CDType::cdC) { if (item->itemType() == CDItem::ItemCDType && item->interface->cdType() == CDType::cdC) {
QStyleOptionButton bo; QStyleOptionButton bo;
@@ -188,15 +188,14 @@ void CDDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option,
bo.fontMetrics = option.fontMetrics; bo.fontMetrics = option.fontMetrics;
bo.palette = option.palette; bo.palette = option.palette;
bo.rect = option.rect; bo.rect = option.rect;
bo.state = option.state;// & ~(QStyle::State_HasFocus | QStyle::State_MouseOver); bo.state = option.state; // & ~(QStyle::State_HasFocus | QStyle::State_MouseOver);
bo.text = item->data(1, Qt::DisplayRole).toString(); bo.text = item->data(1, Qt::DisplayRole).toString();
QWidget * v = (QWidget*)(painter->device()); QWidget * v = (QWidget *)(painter->device());
if (v) { if (v) {
QPoint cp = v->mapFromGlobal(QCursor::pos()); QPoint cp = v->mapFromGlobal(QCursor::pos());
if (bo.rect.contains(cp, true)) { if (bo.rect.contains(cp, true)) {
//bo.state |= QStyle::State_MouseOver; // bo.state |= QStyle::State_MouseOver;
if (qApp->mouseButtons().testFlag(Qt::LeftButton)) if (qApp->mouseButtons().testFlag(Qt::LeftButton)) bo.state |= QStyle::State_On;
bo.state |= QStyle::State_On;
} }
} }
qApp->style()->drawControl(QStyle::CE_PushButton, &bo, painter); qApp->style()->drawControl(QStyle::CE_PushButton, &bo, painter);
@@ -204,37 +203,37 @@ void CDDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option,
} }
} }
QStyledItemDelegate::paint(painter, option, index); QStyledItemDelegate::paint(painter, option, index);
} }
QWidget * CDDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { QWidget * CDDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const {
return new QVariantEdit(parent); return new QVariantEdit(parent);
} }
void CDDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { void CDDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const {
QVariantEdit *edit = static_cast<QVariantEdit*>(editor); QVariantEdit * edit = static_cast<QVariantEdit *>(editor);
edit->setValue(index.model()->data(index, Qt::EditRole)); edit->setValue(index.model()->data(index, Qt::EditRole));
} }
void CDDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { void CDDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const {
QVariantEdit *edit = static_cast<QVariantEdit*>(editor); QVariantEdit * edit = static_cast<QVariantEdit *>(editor);
QVariant v = edit->value(); QVariant v = edit->value();
if (v.canConvert<QAD::Enum>()) { if (v.canConvert<QAD::Enum>()) {
QAD::Enum et = v.value<QAD::Enum>(); QAD::Enum et = v.value<QAD::Enum>();
model->setData(index, et.selectedValue(), Qt::EditRole); model->setData(index, et.selectedValue(), Qt::EditRole);
} else model->setData(index, v, Qt::EditRole); } else
model->setData(index, v, Qt::EditRole);
} }
void CDDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { void CDDelegate::updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const {
editor->setGeometry(option.rect); editor->setGeometry(option.rect);
} }
QSize CDDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QSize CDDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const {
QSize s = QStyledItemDelegate::sizeHint(option, index); QSize s = QStyledItemDelegate::sizeHint(option, index);
s.setWidth(s.width() + 20); s.setWidth(s.width() + 20);
return s; return s;
@@ -243,9 +242,9 @@ QSize CDDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex
// CDItemModel // CDItemModel
CDItemModel::CDItemModel(int type_, QObject *parent) : QAbstractItemModel(parent) { CDItemModel::CDItemModel(int type_, QObject * parent): QAbstractItemModel(parent) {
interface = new Interface((CDType::cdT)type_); interface = new Interface((CDType::cdT)type_);
root = 0; root = 0;
internalRebuild(); internalRebuild();
} }
@@ -256,7 +255,7 @@ CDItemModel::~CDItemModel() {
} }
QVariant CDItemModel::data(const QModelIndex &index, int role) const { QVariant CDItemModel::data(const QModelIndex & index, int role) const {
if (!index.isValid()) return QVariant(); if (!index.isValid()) return QVariant();
CDItem * item = getItem(index); CDItem * item = getItem(index);
return item->data(index.column(), role); return item->data(index.column(), role);
@@ -266,30 +265,32 @@ QVariant CDItemModel::data(const QModelIndex &index, int role) const {
QVariant CDItemModel::headerData(int section, Qt::Orientation orientation, int role) const { QVariant CDItemModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) { switch (section) {
case cID: return tr("Index"); case cID: return tr("Index");
case cName_Cmd: return interface->cdType() == CDType::cdC ? tr("Command") : tr("Name"); case cName_Cmd: return interface->cdType() == CDType::cdC ? tr("Command") : tr("Name");
case cType: return tr("Type"); case cType: return tr("Type");
case cXMode: return tr("Mode"); case cXMode: return tr("Mode");
case cXAvg: return tr("Averaging"); case cXAvg: return tr("Averaging");
case cExpression: return tr("Expression"); case cExpression: return tr("Expression");
case cValue: return tr("Value"); case cValue: return tr("Value");
case cComment: return tr("Comment"); case cComment: return tr("Comment");
} }
} }
return QVariant(); return QVariant();
} }
QModelIndex CDItemModel::index(int row, int column, const QModelIndex &parent) const { QModelIndex CDItemModel::index(int row, int column, const QModelIndex & parent) const {
if (parent.isValid() && parent.column() != cID) return QModelIndex(); if (parent.isValid() && parent.column() != cID) return QModelIndex();
CDItem * p = getItem(parent); CDItem * p = getItem(parent);
CDItem * c = p->childs.value(row, 0); CDItem * c = p->childs.value(row, 0);
if (c) return createIndex(row, column, c); if (c)
else return QModelIndex(); return createIndex(row, column, c);
else
return QModelIndex();
} }
QModelIndex CDItemModel::parent(const QModelIndex &index) const { QModelIndex CDItemModel::parent(const QModelIndex & index) const {
if (!index.isValid()) return QModelIndex(); if (!index.isValid()) return QModelIndex();
CDItem * c = getItem(index); CDItem * c = getItem(index);
CDItem * p = c->parent_; CDItem * p = c->parent_;
@@ -298,13 +299,13 @@ QModelIndex CDItemModel::parent(const QModelIndex &index) const {
} }
int CDItemModel::rowCount(const QModelIndex &parent) const { int CDItemModel::rowCount(const QModelIndex & parent) const {
CDItem * p = getItem(parent); CDItem * p = getItem(parent);
return p->childs.count(); return p->childs.count();
} }
int CDItemModel::columnCount(const QModelIndex &parent) const { int CDItemModel::columnCount(const QModelIndex & parent) const {
return cLastColumn; return cLastColumn;
} }
@@ -312,23 +313,18 @@ int CDItemModel::columnCount(const QModelIndex &parent) const {
Qt::ItemFlags CDItemModel::flags(const QModelIndex & index) const { Qt::ItemFlags CDItemModel::flags(const QModelIndex & index) const {
if (!index.isValid()) return Qt::ItemFlags(); if (!index.isValid()) return Qt::ItemFlags();
Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable; Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
CDItem * item = getItem(index); CDItem * item = getItem(index);
if (!item) return Qt::ItemFlags(); if (!item) return Qt::ItemFlags();
if (item->type_ == CDItem::ItemCDType) { if (item->type_ == CDItem::ItemCDType) {
CDType & t(interface->section(item->buildPath())[item->index_]); CDType & t(interface->section(item->buildPath())[item->index_]);
if (t.cd_type() == CDType::cdK) { if (t.cd_type() == CDType::cdK) {
if (index.column() == cExpression || index.column() == cValue) if (index.column() == cExpression || index.column() == cValue) f |= Qt::ItemIsEditable;
f |= Qt::ItemIsEditable; if (index.column() == cValue && t.type() == "b") f |= Qt::ItemIsUserCheckable;
if (index.column() == cValue && t.type() == "b") if (index.column() == cName_Cmd) f |= Qt::ItemIsDragEnabled;
f |= Qt::ItemIsUserCheckable;
if (index.column() == cName_Cmd)
f |= Qt::ItemIsDragEnabled;
} }
if (t.cd_type() == CDType::cdX) { if (t.cd_type() == CDType::cdX) {
if (index.column() == cXMode || index.column() == cXAvg) if (index.column() == cXMode || index.column() == cXAvg) f |= Qt::ItemIsEditable;
f |= Qt::ItemIsEditable; if (index.column() == cName_Cmd) f |= Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled;
if (index.column() == cName_Cmd)
f |= Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled;
} }
} }
return f; return f;
@@ -350,15 +346,15 @@ bool CDItemModel::setData(const QModelIndex & index, const QVariant & value, int
} }
if (index.column() == cName_Cmd && (t.cd_type() == CDType::cdX)) { if (index.column() == cName_Cmd && (t.cd_type() == CDType::cdX)) {
bool result = item->setData(index.column(), value); bool result = item->setData(index.column(), value);
//QModelIndex rin(CDItemModel::index(index.row(), 1, index.parent())); // QModelIndex rin(CDItemModel::index(index.row(), 1, index.parent()));
//emit dataChanged(rin, rin); // emit dataChanged(rin, rin);
return result; return result;
} }
} }
} }
if (role != Qt::EditRole) return false; if (role != Qt::EditRole) return false;
CDItem * item = getItem(index); CDItem * item = getItem(index);
bool result = item->setData(index.column(), value); bool result = item->setData(index.column(), value);
if (result) { if (result) {
QModelIndex rin(CDItemModel::index(index.row(), cExpression, index.parent())); QModelIndex rin(CDItemModel::index(index.row(), cExpression, index.parent()));
emit dataChanged(rin, rin); emit dataChanged(rin, rin);
@@ -371,13 +367,12 @@ bool CDItemModel::setData(const QModelIndex & index, const QVariant & value, int
QMimeData * CDItemModel::mimeData(const QModelIndexList & indexes) const { QMimeData * CDItemModel::mimeData(const QModelIndexList & indexes) const {
if (indexes.size() == 1) { if (indexes.size() == 1) {
QModelIndex index = indexes[0]; QModelIndex index = indexes[0];
if (index.isValid()/* && interface->cdType() == CDType::cdX*/) { if (index.isValid() /* && interface->cdType() == CDType::cdX*/) {
CDItem * item = getItem(index); CDItem * item = getItem(index);
if (item) { if (item) {
CDType & t(interface->section(item->buildPath())[item->index_]); CDType & t(interface->section(item->buildPath())[item->index_]);
QMimeData * mime = new QMimeData(); QMimeData * mime = new QMimeData();
mime->setText(PI2QString(CDCore::instance()->typeLetter(interface->cdType()) + mime->setText(PI2QString(CDCore::instance()->typeLetter(interface->cdType()) + CDCore::pathToString(t.path())));
CDCore::pathToString(t.path())));
return mime; return mime;
} }
} }
@@ -394,13 +389,13 @@ void CDItemModel::rebuildModel() {
void CDItemModel::buildItem(CDItem * it, CDSection & r) { void CDItemModel::buildItem(CDItem * it, CDSection & r) {
//piCout << "build item" << r.name << r.alias; // piCout << "build item" << r.name << r.alias;
auto i = r.cd.makeIterator(); auto i = r.cd.makeIterator();
while (i.next()) { while (i.next()) {
it->childs << new CDItem(interface, i.key(), CDItem::ItemCDType, it); it->childs << new CDItem(interface, i.key(), CDItem::ItemCDType, it);
} }
it->item_count = it->childs.size(); it->item_count = it->childs.size();
auto j = r.s.makeIterator(); auto j = r.s.makeIterator();
while (j.next()) { while (j.next()) {
it->childs << new CDItem(interface, j.key(), CDItem::ItemCDSection, it); it->childs << new CDItem(interface, j.key(), CDItem::ItemCDSection, it);
buildItem(it->childs.back(), j.value()); buildItem(it->childs.back(), j.value());
@@ -415,17 +410,17 @@ void CDItemModel::updateModel() {
void CDItemModel::internalRebuild() { void CDItemModel::internalRebuild() {
//qDebug() << "[CDKItemModel]" << "internalRebuild()"; // qDebug() << "[CDKItemModel]" << "internalRebuild()";
if (root) delete root; if (root) delete root;
root = new CDItem(interface, 0, CDItem::ItemCDSection, 0); root = new CDItem(interface, 0, CDItem::ItemCDSection, 0);
CDSection & r = interface->root(); CDSection & r = interface->root();
buildItem(root, r); buildItem(root, r);
} }
CDItem * CDItemModel::getItem(const QModelIndex &index) const { CDItem * CDItemModel::getItem(const QModelIndex & index) const {
if (index.isValid()) { if (index.isValid()) {
CDItem * item = static_cast<CDItem*>(index.internalPointer()); CDItem * item = static_cast<CDItem *>(index.internalPointer());
if (item) return item; if (item) return item;
} }
return root; return root;
@@ -435,27 +430,27 @@ CDItem * CDItemModel::getItem(const QModelIndex &index) const {
QModelIndex CDItemModel::indexByPath(const PIDeque<int> & path, int column) const { QModelIndex CDItemModel::indexByPath(const PIDeque<int> & path, int column) const {
if (path.isEmpty()) return QModelIndex(); if (path.isEmpty()) return QModelIndex();
CDItem * item = root; CDItem * item = root;
//piCout << path << "..."; // piCout << path << "...";
bool ok = false; bool ok = false;
for (int i = 0; i < path.size_s() - 1; ++i) { for (int i = 0; i < path.size_s() - 1; ++i) {
ok = false; ok = false;
foreach (CDItem * j, item->childs) foreach(CDItem * j, item->childs)
if (j->type_ == CDItem::ItemCDSection && j->index_ == path[i]) { if (j->type_ == CDItem::ItemCDSection && j->index_ == path[i]) {
item = j; item = j;
ok = true; ok = true;
break; break;
} }
if (!ok) return QModelIndex(); if (!ok) return QModelIndex();
} }
ok = false; ok = false;
foreach (CDItem * j, item->childs) foreach(CDItem * j, item->childs)
if (j->type_ == CDItem::ItemCDType && j->index_ == path.back()) { if (j->type_ == CDItem::ItemCDType && j->index_ == path.back()) {
item = j; item = j;
ok = true; ok = true;
break; break;
} }
if (!ok || !item->parent_) return QModelIndex(); if (!ok || !item->parent_) return QModelIndex();
QModelIndex ret = createIndex(item->parent_->childs.indexOf(item), column, item); QModelIndex ret = createIndex(item->parent_->childs.indexOf(item), column, item);
//piCout << path << Q2PIString(item->data(cName_Cmd, Qt::DisplayRole).toString()) << getItem(ret)->buildPath(); // piCout << path << Q2PIString(item->data(cName_Cmd, Qt::DisplayRole).toString()) << getItem(ret)->buildPath();
return ret; return ret;
} }

View File

@@ -1,51 +1,52 @@
/* /*
QCD Utils - Qt bindings/utilites for CD Utils QCD Utils - Qt bindings/utilites for CD Utils
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef QCD_MODEL_H #ifndef QCD_MODEL_H
#define QCD_MODEL_H #define QCD_MODEL_H
#include "cd_qt_export.h"
#include "pistring.h"
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QItemDelegate> #include <QItemDelegate>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include "pistring.h"
#include "cd_qt_export.h"
namespace CDUtils { namespace CDUtils {
class CDType; class CDType;
class CDSection; class CDSection;
class Interface; class Interface;
enum Column { enum Column {
cID , cID,
cName_Cmd , cName_Cmd,
cType , cType,
cXMode , cXMode,
cXAvg , cXAvg,
cExpression, cExpression,
cValue , cValue,
cComment , cComment,
cLastColumn, cLastColumn,
}; };
} } // namespace CDUtils
namespace QAD { namespace QAD {
struct Enum; struct Enum;
} }
class CDItemModel; class CDItemModel;
@@ -54,16 +55,20 @@ class CDItemModel;
class CD_QT_EXPORT CDItem { class CD_QT_EXPORT CDItem {
friend class CDItemModel; friend class CDItemModel;
friend class CDView; friend class CDView;
public: public:
enum CDItemType{ItemCDType, ItemCDSection}; enum CDItemType {
ItemCDType,
ItemCDSection
};
CDItem(CDUtils::Interface * interface, int _index, CDItemType type, CDItem * parent); CDItem(CDUtils::Interface * interface, int _index, CDItemType type, CDItem * parent);
~CDItem(); ~CDItem();
QVariant data(int column, int role) const; QVariant data(int column, int role) const;
QVariant value(CDUtils::CDType & t, int role) const; QVariant value(CDUtils::CDType & t, int role) const;
bool setData(int column, const QVariant & value); bool setData(int column, const QVariant & value);
CDItemType itemType() const {return type_;} CDItemType itemType() const { return type_; }
PIDeque<int> buildPath() const; PIDeque<int> buildPath() const;
int index() const {return index_;} int index() const { return index_; }
CDUtils::Interface * interface; CDUtils::Interface * interface;
bool expanded; bool expanded;
@@ -79,42 +84,42 @@ private:
}; };
class CD_QT_EXPORT CDDelegate : public QStyledItemDelegate class CD_QT_EXPORT CDDelegate: public QStyledItemDelegate {
{
Q_OBJECT Q_OBJECT
public: public:
CDDelegate(QObject *parent = 0); CDDelegate(QObject * parent = 0);
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const; void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const; void setEditorData(QWidget * editor, const QModelIndex & index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, 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; void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
}; };
class CD_QT_EXPORT CDItemModel : public QAbstractItemModel { class CD_QT_EXPORT CDItemModel: public QAbstractItemModel {
Q_OBJECT Q_OBJECT
friend class CDView; friend class CDView;
public: public:
explicit CDItemModel(int type_, QObject *parent = 0); explicit CDItemModel(int type_, QObject * parent = 0);
~CDItemModel(); ~CDItemModel();
QVariant data(const QModelIndex & index, int role) const; QVariant data(const QModelIndex & index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) 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 index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const; QModelIndex parent(const QModelIndex & index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex & parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex & parent = QModelIndex()) const;
Qt::ItemFlags flags(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex & index) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
QMimeData * mimeData(const QModelIndexList & indexes) const; QMimeData * mimeData(const QModelIndexList & indexes) const;
CDItem * getItem(const QModelIndex & index) const; CDItem * getItem(const QModelIndex & index) const;
QModelIndex indexByPath(const PIDeque<int> & path, int column = CDUtils::cID) const; QModelIndex indexByPath(const PIDeque<int> & path, int column = CDUtils::cID) const;
void buildItem(CDItem * it, CDUtils::CDSection &r); void buildItem(CDItem * it, CDUtils::CDSection & r);
public slots: public slots:
void rebuildModel(); void rebuildModel();
@@ -127,7 +132,6 @@ private:
CDItem * root; CDItem * root;
signals: signals:
}; };
#endif // QCD_MODEL_H #endif // QCD_MODEL_H

View File

@@ -1,30 +1,32 @@
#include "qcd_view.h"
#include "cdutils_c.h"
#include "cdutils_core.h"
#include "cdutils_k.h"
#include "cdutils_m.h"
#include "cdutils_x.h"
#include "pifile.h"
#include "piqt.h"
#include "qcd_model.h"
#include <QDir> #include <QDir>
#include <QMouseEvent> #include <QMouseEvent>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include "cdutils_k.h"
#include "cdutils_x.h"
#include "cdutils_c.h"
#include "cdutils_m.h"
#include "cdutils_core.h"
#include "qcd_view.h"
#include "qcd_model.h"
#include "piqt.h"
#include "pifile.h"
using namespace CDUtils; using namespace CDUtils;
CDView::CDView(QWidget * parent) : QTreeView(parent) { CDView::CDView(QWidget * parent): QTreeView(parent) {
type_ = -1; type_ = -1;
model_ = 0; model_ = 0;
proxy_ = 0; proxy_ = 0;
connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(indexClicked(QModelIndex))); connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(indexClicked(QModelIndex)));
connect(this, SIGNAL(_qcd_sendFailed()), this, SLOT(cd_sendFailed()), Qt::QueuedConnection); connect(this, SIGNAL(_qcd_sendFailed()), this, SLOT(cd_sendFailed()), Qt::QueuedConnection);
connect(this, SIGNAL(_qcd_sendSucceed()), this, SLOT(cd_sendSucceed()), Qt::QueuedConnection); connect(this, SIGNAL(_qcd_sendSucceed()), this, SLOT(cd_sendSucceed()), Qt::QueuedConnection);
connect(this, SIGNAL(_qcd_receiveFailed()), this, SLOT(cd_receiveFailed()), Qt::QueuedConnection); connect(this, SIGNAL(_qcd_receiveFailed()), this, SLOT(cd_receiveFailed()), Qt::QueuedConnection);
connect(this, SIGNAL(_qcd_receiveSucceed()), this, SLOT(cd_receiveSucceed()), Qt::QueuedConnection); connect(this, SIGNAL(_qcd_receiveSucceed()), this, SLOT(cd_receiveSucceed()), Qt::QueuedConnection);
connect(this, SIGNAL(_qcd_receivedX()), this, SLOT(cd_receivedX()), Qt::QueuedConnection); connect(this, SIGNAL(_qcd_receivedX()), this, SLOT(cd_receivedX()), Qt::QueuedConnection);
connect(this, SIGNAL(_qcd_changedGlobal()), this, SLOT(cd_changedGlobal()), Qt::QueuedConnection); connect(this, SIGNAL(_qcd_changedGlobal()), this, SLOT(cd_changedGlobal()), Qt::QueuedConnection);
} }
@@ -44,46 +46,44 @@ void CDView::setType(int cdt) {
type_ = cdt; type_ = cdt;
switch ((CDType::cdT)type_) { switch ((CDType::cdT)type_) {
case CDType::cdK: case CDType::cdK:
CONNECTU(&K, sended, this, pi_cd_sendSucceed); CONNECTU(&K, sended, this, pi_cd_sendSucceed);
CONNECTU(&K, sendFailed, this, pi_cd_sendFailed); CONNECTU(&K, sendFailed, this, pi_cd_sendFailed);
CONNECTU(&K, received, this, pi_cd_receiveSucceed); CONNECTU(&K, received, this, pi_cd_receiveSucceed);
CONNECTU(&K, receiveFailed, this, pi_cd_receiveFailed); CONNECTU(&K, receiveFailed, this, pi_cd_receiveFailed);
CONNECTU(&K, changedGlobal, this, pi_cd_changedGlobal); CONNECTU(&K, changedGlobal, this, pi_cd_changedGlobal);
break; break;
case CDType::cdX: case CDType::cdX:
CONNECTU(&X, sended, this, pi_cd_sendSucceed); CONNECTU(&X, sended, this, pi_cd_sendSucceed);
CONNECTU(&X, sendFailed, this, pi_cd_sendFailed); CONNECTU(&X, sendFailed, this, pi_cd_sendFailed);
CONNECTU(&X, received, this, pi_cd_receiveSucceed); CONNECTU(&X, received, this, pi_cd_receiveSucceed);
CONNECTU(&X, receiveFailed, this, pi_cd_receiveFailed); CONNECTU(&X, receiveFailed, this, pi_cd_receiveFailed);
CONNECTU(&X, receivedX, this, pi_cd_receivedX); CONNECTU(&X, receivedX, this, pi_cd_receivedX);
CONNECTU(&X, changedGlobal, this, pi_cd_changedGlobal); CONNECTU(&X, changedGlobal, this, pi_cd_changedGlobal);
break; break;
case CDType::cdC: case CDType::cdC:
CONNECTU(&C, sended, this, pi_cd_sendSucceed); CONNECTU(&C, sended, this, pi_cd_sendSucceed);
CONNECTU(&C, sendFailed, this, pi_cd_sendFailed); CONNECTU(&C, sendFailed, this, pi_cd_sendFailed);
CONNECTU(&C, received, this, pi_cd_receiveSucceed); CONNECTU(&C, received, this, pi_cd_receiveSucceed);
CONNECTU(&C, receiveFailed, this, pi_cd_receiveFailed); CONNECTU(&C, receiveFailed, this, pi_cd_receiveFailed);
CONNECTU(&C, changedGlobal, this, pi_cd_changedGlobal); CONNECTU(&C, changedGlobal, this, pi_cd_changedGlobal);
break; break;
case CDType::cdM: case CDType::cdM:
CONNECTU(&M, sended, this, pi_cd_sendSucceed); CONNECTU(&M, sended, this, pi_cd_sendSucceed);
CONNECTU(&M, sendFailed, this, pi_cd_sendFailed); CONNECTU(&M, sendFailed, this, pi_cd_sendFailed);
CONNECTU(&M, received, this, pi_cd_receiveSucceed); CONNECTU(&M, received, this, pi_cd_receiveSucceed);
CONNECTU(&M, receiveFailed, this, pi_cd_receiveFailed); CONNECTU(&M, receiveFailed, this, pi_cd_receiveFailed);
CONNECTU(&M, changedGlobal, this, pi_cd_changedGlobal); CONNECTU(&M, changedGlobal, this, pi_cd_changedGlobal);
CONNECTU(&M, messageReceived, this, pi_cd_messageReceived); CONNECTU(&M, messageReceived, this, pi_cd_messageReceived);
break; break;
default: break; default: break;
} }
} }
void CDView::mousePressEvent(QMouseEvent * e) { void CDView::mousePressEvent(QMouseEvent * e) {
if (type_ == CDType::cdC) { if (type_ == CDType::cdC) {
QModelIndex i = indexAt(e->pos()); QModelIndex i = indexAt(e->pos());
if (i.isValid() && i.column() == cName_Cmd) if (i.isValid() && i.column() == cName_Cmd) update(i);
update(i);
} }
QTreeView::mousePressEvent(e); QTreeView::mousePressEvent(e);
} }
@@ -92,8 +92,7 @@ void CDView::mousePressEvent(QMouseEvent * e) {
void CDView::mouseReleaseEvent(QMouseEvent * e) { void CDView::mouseReleaseEvent(QMouseEvent * e) {
if (type_ == CDType::cdC) { if (type_ == CDType::cdC) {
QModelIndex i = indexAt(e->pos()); QModelIndex i = indexAt(e->pos());
if (i.isValid() && i.column() == cName_Cmd) if (i.isValid() && i.column() == cName_Cmd) update(i);
update(i);
} }
QTreeView::mouseReleaseEvent(e); QTreeView::mouseReleaseEvent(e);
} }
@@ -101,8 +100,7 @@ void CDView::mouseReleaseEvent(QMouseEvent * e) {
void CDView::currentChanged(const QModelIndex & cur, const QModelIndex & prev) { void CDView::currentChanged(const QModelIndex & cur, const QModelIndex & prev) {
if (type_ == CDType::cdC) { if (type_ == CDType::cdC) {
if (prev.isValid() && prev.column() == cName_Cmd) if (prev.isValid() && prev.column() == cName_Cmd) update(prev);
update(prev);
} }
QTreeView::currentChanged(cur, prev); QTreeView::currentChanged(cur, prev);
} }
@@ -121,30 +119,28 @@ void CDView::refresh() {
proxy_->setSourceModel(model_); proxy_->setSourceModel(model_);
setModel(proxy_); setModel(proxy_);
setItemDelegateForColumn(type_ == CDType::cdC ? cName_Cmd : cValue, new CDDelegate()); setItemDelegateForColumn(type_ == CDType::cdC ? cName_Cmd : cValue, new CDDelegate());
if (type_ == CDType::cdX) if (type_ == CDType::cdX) setItemDelegateForColumn(cXMode, new CDDelegate());
setItemDelegateForColumn(cXMode, new CDDelegate());
} }
model_->rebuildModel(); model_->rebuildModel();
switch ((CDType::cdT)type_) { switch ((CDType::cdT)type_) {
case CDType::cdK: case CDType::cdK:
setColumnHidden(cXMode, true); setColumnHidden(cXMode, true);
setColumnHidden(cXAvg, true); setColumnHidden(cXAvg, true);
break;
case CDType::cdX:
setColumnHidden(cExpression, true);
break; break;
case CDType::cdX: setColumnHidden(cExpression, true); break;
case CDType::cdC: case CDType::cdC:
case CDType::cdM: case CDType::cdM:
setColumnHidden(cType, true); setColumnHidden(cType, true);
setColumnHidden(cXMode, true); setColumnHidden(cXMode, true);
setColumnHidden(cXAvg, true); setColumnHidden(cXAvg, true);
setColumnHidden(cExpression, true); setColumnHidden(cExpression, true);
setColumnHidden(cValue, true); setColumnHidden(cValue, true);
break; break;
default: break; default: break;
} }
expandAll(); expandAll();
for (int i = 0; i < model_->columnCount(); i++) resizeColumnToContents(i); for (int i = 0; i < model_->columnCount(); i++)
resizeColumnToContents(i);
} }
@@ -255,7 +251,7 @@ void CDView::load() {
void CDView::clear() { void CDView::clear() {
//piCout << "clearK"; // piCout << "clearK";
switch ((CDType::cdT)type_) { switch ((CDType::cdT)type_) {
case CDType::cdK: K.root() = CDSection(); break; case CDType::cdK: K.root() = CDSection(); break;
case CDType::cdX: X.root() = CDSection(); break; case CDType::cdX: X.root() = CDSection(); break;
@@ -310,7 +306,7 @@ void CDView::indexClicked(const QModelIndex & i) {
CDType & t(model_->interface->section(item->buildPath())[item->index()]); CDType & t(model_->interface->section(item->buildPath())[item->index()]);
C.sendCommand(t); C.sendCommand(t);
emit commandSended(PI2QString(t.pathString().join("."))); emit commandSended(PI2QString(t.pathString().join(".")));
//piCout << t; // piCout << t;
qDebug() << PI2QString(t.pathString().join(".")); qDebug() << PI2QString(t.pathString().join("."));
} }
@@ -346,16 +342,16 @@ void CDView::cd_receiveSucceed() {
void CDView::cd_receivedX() { void CDView::cd_receivedX() {
X.lock(); X.lock();
PIVector<PIDeque<int> > xl = X.enabledList(); PIVector<PIDeque<int>> xl = X.enabledList();
//piCout << "X" << xl.size(); // piCout << "X" << xl.size();
piForeachC (PIDeque<int> & x, xl) { piForeachC(PIDeque<int> & x, xl) {
CDType & t(X[x]); CDType & t(X[x]);
//piCout << t; // piCout << t;
//piCout << t.path(); // piCout << t.path();
if (t.cd_type() != CDType::cdX) continue; if (t.cd_type() != CDType::cdX) continue;
update(model_->indexByPath(t.path(), cValue)); update(model_->indexByPath(t.path(), cValue));
//piCout << CDCore::pathToString(t.path()) << t.toDouble() << "model"; // piCout << CDCore::pathToString(t.path()) << t.toDouble() << "model";
//qDebug() << "val" << model_->data(model_->indexByPath(t.path(), cValue), Qt::DisplayRole).toDouble(); // qDebug() << "val" << model_->data(model_->indexByPath(t.path(), cValue), Qt::DisplayRole).toDouble();
} }
X.unlock(); X.unlock();
emit receivedX(); emit receivedX();
@@ -368,8 +364,10 @@ void CDView::cd_changedGlobal() {
void CDView::pi_cd_messageReceived(PIDeque<int> path, int type, PIString msg) { void CDView::pi_cd_messageReceived(PIDeque<int> path, int type, PIString msg) {
QMetaObject::invokeMethod(this, "messageReceived", Qt::QueuedConnection, QMetaObject::invokeMethod(this,
Q_ARG(QString, PI2QString(CDCore::pathToString(path))), "messageReceived",
Q_ARG(int, type), Qt::QueuedConnection,
Q_ARG(QString, PI2QString(msg))); Q_ARG(QString, PI2QString(CDCore::pathToString(path))),
Q_ARG(int, type),
Q_ARG(QString, PI2QString(msg)));
} }

View File

@@ -1,43 +1,46 @@
/* /*
QCD Utils - Qt bindings/utilites for CD Utils QCD Utils - Qt bindings/utilites for CD Utils
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef QCD_VIEW_H #ifndef QCD_VIEW_H
#define QCD_VIEW_H #define QCD_VIEW_H
#include <QTreeView>
#include "piobject.h"
#include "cd_qt_export.h" #include "cd_qt_export.h"
#include "piobject.h"
#include <QTreeView>
namespace CDUtils { namespace CDUtils {
class CDType; class CDType;
class CDSection; class CDSection;
} } // namespace CDUtils
class CDItemModel; class CDItemModel;
class QSortFilterProxyModel; class QSortFilterProxyModel;
class CD_QT_EXPORT CDView: public QTreeView, public PIObject class CD_QT_EXPORT CDView
{ : public QTreeView
, public PIObject {
Q_OBJECT Q_OBJECT
PIOBJECT(CDView); PIOBJECT(CDView);
public: public:
explicit CDView(QWidget *parent = 0); explicit CDView(QWidget * parent = 0);
~CDView(); ~CDView();
void setType(int cdt); void setType(int cdt);
@@ -47,11 +50,11 @@ public:
CDUtils::CDSection * root(); CDUtils::CDSection * root();
QString typeLetter() const; QString typeLetter() const;
CDItemModel * CDModel() {return model_;} CDItemModel * CDModel() { return model_; }
protected: protected:
void mousePressEvent(QMouseEvent * ) override; void mousePressEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent * ) override; void mouseReleaseEvent(QMouseEvent *) override;
void currentChanged(const QModelIndex & cur, const QModelIndex & prev) override; void currentChanged(const QModelIndex & cur, const QModelIndex & prev) override;
public slots: public slots:
@@ -77,12 +80,12 @@ private slots:
private: private:
bool filterTree(const QModelIndex & ti, const QString & filter); bool filterTree(const QModelIndex & ti, const QString & filter);
EVENT_HANDLER(void, pi_cd_sendFailed) {emit _qcd_sendFailed();} EVENT_HANDLER(void, pi_cd_sendFailed) { emit _qcd_sendFailed(); }
EVENT_HANDLER(void, pi_cd_sendSucceed) {emit _qcd_sendSucceed();} EVENT_HANDLER(void, pi_cd_sendSucceed) { emit _qcd_sendSucceed(); }
EVENT_HANDLER(void, pi_cd_receiveFailed) {emit _qcd_receiveFailed();} EVENT_HANDLER(void, pi_cd_receiveFailed) { emit _qcd_receiveFailed(); }
EVENT_HANDLER(void, pi_cd_receiveSucceed) {emit _qcd_receiveSucceed();} EVENT_HANDLER(void, pi_cd_receiveSucceed) { emit _qcd_receiveSucceed(); }
EVENT_HANDLER(void, pi_cd_receivedX) {emit _qcd_receivedX();} EVENT_HANDLER(void, pi_cd_receivedX) { emit _qcd_receivedX(); }
EVENT_HANDLER(void, pi_cd_changedGlobal) {emit _qcd_changedGlobal();} EVENT_HANDLER(void, pi_cd_changedGlobal) { emit _qcd_changedGlobal(); }
EVENT_HANDLER3(void, pi_cd_messageReceived, PIDeque<int>, path, int, type, PIString, msg); EVENT_HANDLER3(void, pi_cd_messageReceived, PIDeque<int>, path, int, type, PIString, msg);
CDItemModel * model_; CDItemModel * model_;
@@ -101,13 +104,12 @@ signals:
void messageReceived(QString path, int type, QString msg); void messageReceived(QString path, int type, QString msg);
void busyStatusChanged(bool busy); void busyStatusChanged(bool busy);
void _qcd_sendFailed(); // PRIVATE void _qcd_sendFailed(); // PRIVATE
void _qcd_sendSucceed(); // PRIVATE void _qcd_sendSucceed(); // PRIVATE
void _qcd_receiveFailed(); // PRIVATE void _qcd_receiveFailed(); // PRIVATE
void _qcd_receiveSucceed(); // PRIVATE void _qcd_receiveSucceed(); // PRIVATE
void _qcd_receivedX(); // PRIVATE void _qcd_receivedX(); // PRIVATE
void _qcd_changedGlobal(); // PRIVATE void _qcd_changedGlobal(); // PRIVATE
}; };
#endif // QCD_VIEW_H #endif // QCD_VIEW_H

View File

@@ -1,27 +1,29 @@
#include "cddirectk.h" #include "cddirectk.h"
#include "ui_cddirectk_type_dialog.h"
#include "cdutils_core.h" #include "cdutils_core.h"
#include "cdutils_k.h" #include "cdutils_k.h"
#include "qcd_core.h"
#include "qcd_model.h"
#include "graphic.h" #include "graphic.h"
#include "piqt.h" #include "piqt.h"
#include "qcd_core.h"
#include "qcd_model.h"
#include "qvariantedit.h" #include "qvariantedit.h"
#include <QFormLayout> #include "ui_cddirectk_type_dialog.h"
#include <QMimeData>
#include <QDockWidget>
#include <QDragEnterEvent> #include <QDragEnterEvent>
#include <QDragMoveEvent> #include <QDragMoveEvent>
#include <QDropEvent> #include <QDropEvent>
#include <QMainWindow> #include <QFormLayout>
#include <QDockWidget>
#include <QInputDialog> #include <QInputDialog>
#include <QMainWindow>
#include <QMimeData>
using namespace CDUtils; using namespace CDUtils;
KDockWidget::KDockWidget(QString title, QMainWindow * p): QDockWidget(title, p) { KDockWidget::KDockWidget(QString title, QMainWindow * p): QDockWidget(title, p) {
da = p; da = p;
menu = new QMenu(this); menu = new QMenu(this);
QAction * a = new QAction(QIcon(":/icons/document-edit.png"), "Rename ...", this); QAction * a = new QAction(QIcon(":/icons/document-edit.png"), "Rename ...", this);
connect(a, SIGNAL(triggered(bool)), this, SLOT(rename())); connect(a, SIGNAL(triggered(bool)), this, SLOT(rename()));
dactions << a; dactions << a;
@@ -48,20 +50,18 @@ void KDockWidget::addK(const CDType & t, CDDirectKTypeDialog::TypeInfo ti) {
if (k_list.contains(xp)) return; if (k_list.contains(xp)) return;
k_list << xp; k_list << xp;
info_list << ti; info_list << ti;
//piCout << "add" << xp; // piCout << "add" << xp;
QWidget * ve = ti.create(); QWidget * ve = ti.create();
//qDebug() << "add" << ve; // qDebug() << "add" << ve;
lay->addRow(PI2QString(t.pathString().join(".")) + ":", ve); lay->addRow(PI2QString(t.pathString().join(".")) + ":", ve);
QCDCore::instance()->bindWidget(ve, t); QCDCore::instance()->bindWidget(ve, t);
//ve->setValue(); // ve->setValue();
} }
QByteArray KDockWidget::save() const { QByteArray KDockWidget::save() const {
ChunkStream cs; ChunkStream cs;
cs.add(1, windowTitle()) cs.add(1, windowTitle()).add(2, getList(k_list)).add(3, info_list);
.add(2, getList(k_list))
.add(3, info_list);
return cs.data(); return cs.data();
} }
@@ -70,13 +70,13 @@ void KDockWidget::load(QByteArray ba) {
clear(); clear();
if (ba.isEmpty()) return; if (ba.isEmpty()) return;
ChunkStream cs(ba); ChunkStream cs(ba);
PIVector<PIDeque<int> > list; PIVector<PIDeque<int>> list;
QVector<CDDirectKTypeDialog::TypeInfo> ilist; QVector<CDDirectKTypeDialog::TypeInfo> ilist;
while (!cs.atEnd()) { while (!cs.atEnd()) {
switch (cs.read()) { switch (cs.read()) {
case 1: setWindowTitle(cs.getData<QString>()); break; case 1: setWindowTitle(cs.getData<QString>()); break;
case 2: list = setList(cs.getData<QStringList>()); break; case 2: list = setList(cs.getData<QStringList>()); break;
case 3: ilist = cs.getData<QVector<CDDirectKTypeDialog::TypeInfo> >(); break; case 3: ilist = cs.getData<QVector<CDDirectKTypeDialog::TypeInfo>>(); break;
default: break; default: break;
} }
} }
@@ -96,9 +96,9 @@ void KDockWidget::clear() {
void KDockWidget::changedGlobal() { void KDockWidget::changedGlobal() {
//piCout << "changedGlobal ..." << k_list.size_s() << info_list.size() << lay->count() << lay->rowCount(); // piCout << "changedGlobal ..." << k_list.size_s() << info_list.size() << lay->count() << lay->rowCount();
for (int i = 0; i < k_list.size_s(); ++i) { for (int i = 0; i < k_list.size_s(); ++i) {
//piCout << "update" << i << "0"; // piCout << "update" << i << "0";
if (!K.exists(k_list[i])) { if (!K.exists(k_list[i])) {
k_list.remove(i); k_list.remove(i);
info_list.remove(i); info_list.remove(i);
@@ -106,57 +106,57 @@ void KDockWidget::changedGlobal() {
--i; --i;
continue; continue;
} }
//piCout << "update" << i << "1"; // piCout << "update" << i << "1";
QLabel * lbl = qobject_cast<QLabel*>(lay->itemAt(i, QFormLayout::LabelRole)->widget()); QLabel * lbl = qobject_cast<QLabel *>(lay->itemAt(i, QFormLayout::LabelRole)->widget());
//piCout << "update" << i << "2"; // piCout << "update" << i << "2";
if (lbl) lbl->setText(PI2QString(K[k_list[i]].pathString().join(".")) + ":"); if (lbl) lbl->setText(PI2QString(K[k_list[i]].pathString().join(".")) + ":");
//piCout << "update" << i << "3"; // piCout << "update" << i << "3";
} }
//piCout << "changedGlobal ok"; // piCout << "changedGlobal ok";
} }
bool KDockWidget::eventFilter(QObject * o, QEvent * e) { bool KDockWidget::eventFilter(QObject * o, QEvent * e) {
//if (o == graphic->viewport()) { // if (o == graphic->viewport()) {
switch (e->type()) { switch (e->type()) {
case QEvent::DragMove: { case QEvent::DragMove: {
QDragMoveEvent * de = (QDragMoveEvent*)e; QDragMoveEvent * de = (QDragMoveEvent *)e;
const QMimeData * mime = de->mimeData(); const QMimeData * mime = de->mimeData();
if (!mime) break; if (!mime) break;
if (!mime->text().startsWith("k")) break; if (!mime->text().startsWith("k")) break;
de->setDropAction(Qt::CopyAction); de->setDropAction(Qt::CopyAction);
de->accept(); de->accept();
return true; return true;
} break; } break;
case QEvent::DragEnter: { case QEvent::DragEnter: {
QDragEnterEvent * de = (QDragEnterEvent*)e; QDragEnterEvent * de = (QDragEnterEvent *)e;
const QMimeData * mime = de->mimeData(); const QMimeData * mime = de->mimeData();
if (!mime) break; if (!mime) break;
if (!mime->text().startsWith("k")) break; if (!mime->text().startsWith("k")) break;
de->setDropAction(Qt::CopyAction); de->setDropAction(Qt::CopyAction);
de->accept(); de->accept();
return true; return true;
} break; } break;
case QEvent::Drop: { case QEvent::Drop: {
QDropEvent * de = (QDropEvent*)e; QDropEvent * de = (QDropEvent *)e;
const QMimeData * mime = de->mimeData(); const QMimeData * mime = de->mimeData();
if (!mime) break; if (!mime) break;
//qDebug() << "drop" << mime->text(); // qDebug() << "drop" << mime->text();
if (!mime->text().startsWith("k")) break; if (!mime->text().startsWith("k")) break;
CDDirectKTypeDialog::TypeInfo ti; CDDirectKTypeDialog::TypeInfo ti;
CDType & k(K[CDCore::stringToPath(Q2PIString(mime->text().mid(1)))]); CDType & k(K[CDCore::stringToPath(Q2PIString(mime->text().mid(1)))]);
if (k.type().left(1) == "n" || k.type().left(1) == "f") { if (k.type().left(1) == "n" || k.type().left(1) == "f") {
if (type_dialog->exec() == QDialog::Accepted) if (type_dialog->exec() == QDialog::Accepted)
ti = type_dialog->getType(); ti = type_dialog->getType();
else else
return true; return true;
}
addK(k, ti);
de->accept();
return true;
} break;
default: break;
} }
addK(k, ti);
de->accept();
return true;
} break;
default: break;
}
//} //}
return QWidget::eventFilter(o, e); return QWidget::eventFilter(o, e);
} }
@@ -186,41 +186,46 @@ void KDockWidget::removeRow(int r) {
if (r < 0 || r >= lay->rowCount()) return; if (r < 0 || r >= lay->rowCount()) return;
#if QT_VERSION >= 0x050800 #if QT_VERSION >= 0x050800
QFormLayout::TakeRowResult rr = lay->takeRow(r); QFormLayout::TakeRowResult rr = lay->takeRow(r);
if (rr.fieldItem) {delete rr.fieldItem->widget(); delete rr.fieldItem;} if (rr.fieldItem) {
if (rr.labelItem) {delete rr.labelItem->widget(); delete rr.labelItem;} delete rr.fieldItem->widget();
delete rr.fieldItem;
}
if (rr.labelItem) {
delete rr.labelItem->widget();
delete rr.labelItem;
}
#else #else
piForTimes (2) { piForTimes(2) {
QLayoutItem * i = lay->itemAt(r+r); QLayoutItem * i = lay->itemAt(r + r);
lay->removeItem(i); lay->removeItem(i);
if (i) {delete i->widget(); delete i;} if (i) {
delete i->widget();
delete i;
}
} }
#endif #endif
} }
void KDockWidget::rename() { void KDockWidget::rename() {
QString nn = QInputDialog::getText(this, tr("Rename area"), tr("New area name:"), QString nn = QInputDialog::getText(this, tr("Rename area"), tr("New area name:"), QLineEdit::Normal, windowTitle());
QLineEdit::Normal, windowTitle());
if (nn.isEmpty()) return; if (nn.isEmpty()) return;
setWindowTitle(nn); setWindowTitle(nn);
} }
void KDockWidget::removeK() { void KDockWidget::removeK() {
QAction * a = qobject_cast<QAction * >(sender()); QAction * a = qobject_cast<QAction *>(sender());
if (!a) return; if (!a) return;
int ind = a->data().toInt(); int ind = a->data().toInt();
if (ind < 0 || ind >= k_list.size_s()) return; if (ind < 0 || ind >= k_list.size_s()) return;
k_list.remove(ind); k_list.remove(ind);
if (ind >= 0 && ind < info_list.size()) if (ind >= 0 && ind < info_list.size()) info_list.remove(ind);
info_list.remove(ind);
removeRow(ind); removeRow(ind);
} }
CDDirectK::CDDirectK(QWidget * parent): QWidget(parent), Ui::CDDirectK() {
CDDirectK::CDDirectK(QWidget * parent) : QWidget(parent), Ui::CDDirectK() {
setupUi(this); setupUi(this);
da = new QMainWindow(); da = new QMainWindow();
da->setWindowFlags(frame->windowFlags()); da->setWindowFlags(frame->windowFlags());
@@ -229,8 +234,7 @@ CDDirectK::CDDirectK(QWidget * parent) : QWidget(parent), Ui::CDDirectK() {
} }
CDDirectK::~CDDirectK() { CDDirectK::~CDDirectK() {}
}
void CDDirectK::reset() { void CDDirectK::reset() {
@@ -242,12 +246,10 @@ void CDDirectK::reset() {
QByteArray CDDirectK::save() const { QByteArray CDDirectK::save() const {
ChunkStream cs; ChunkStream cs;
QVector<QByteArray> dstates; QVector<QByteArray> dstates;
foreach (KDockWidget * d, docks) { foreach(KDockWidget * d, docks) {
dstates << d->save(); dstates << d->save();
} }
cs.add(1, docks.size()) cs.add(1, docks.size()).add(2, dstates).add(3, da->saveState());
.add(2, dstates)
.add(3, da->saveState());
return cs.data(); return cs.data();
} }
@@ -260,14 +262,13 @@ void CDDirectK::load(QByteArray ba) {
switch (cs.read()) { switch (cs.read()) {
case 1: { case 1: {
int s = cs.getData<int>(); int s = cs.getData<int>();
piForTimes (s) piForTimes(s) addArea();
addArea(); } break;
} break;
case 2: { case 2: {
QVector<QByteArray> dstates = cs.getData<QVector<QByteArray> >(); QVector<QByteArray> dstates = cs.getData<QVector<QByteArray>>();
for (int i = 0; i < piMini(dstates.size(), docks.size()); ++i) for (int i = 0; i < piMini(dstates.size(), docks.size()); ++i)
docks[i]->load(dstates[i]); docks[i]->load(dstates[i]);
} break; } break;
case 3: da->restoreState(cs.getData<QByteArray>()); break; case 3: da->restoreState(cs.getData<QByteArray>()); break;
default: break; default: break;
} }
@@ -286,13 +287,13 @@ void CDDirectK::addArea() {
void CDDirectK::changedGlobal() { void CDDirectK::changedGlobal() {
foreach (KDockWidget * d, docks) foreach(KDockWidget * d, docks)
d->changedGlobal(); d->changedGlobal();
} }
void CDDirectK::removeArea() { void CDDirectK::removeArea() {
KDockWidget * d = qobject_cast<KDockWidget * >(sender()); KDockWidget * d = qobject_cast<KDockWidget *>(sender());
if (!d) return; if (!d) return;
docks.removeAll(d); docks.removeAll(d);
d->deleteLater(); d->deleteLater();

View File

@@ -1,15 +1,16 @@
#ifndef CDDIRECTK_H #ifndef CDDIRECTK_H
#define CDDIRECTK_H #define CDDIRECTK_H
#include "cddirectk_type_dialog.h"
#include "cdgraphics.h" #include "cdgraphics.h"
#include "ui_cddirectk.h" #include "ui_cddirectk.h"
#include "cddirectk_type_dialog.h"
class QFormLayout; class QFormLayout;
class KDockWidget: public QDockWidget { class KDockWidget: public QDockWidget {
Q_OBJECT Q_OBJECT
public: public:
KDockWidget(QString title = QString(), QMainWindow * p = 0); KDockWidget(QString title = QString(), QMainWindow * p = 0);
@@ -26,11 +27,11 @@ private:
void contextMenuEvent(QContextMenuEvent * e); void contextMenuEvent(QContextMenuEvent * e);
void removeRow(int r); void removeRow(int r);
QMenu * menu, * menu_k; QMenu *menu, *menu_k;
QList<QAction*> dactions; QList<QAction *> dactions;
QMainWindow * da; QMainWindow * da;
CDDirectKTypeDialog * type_dialog; CDDirectKTypeDialog * type_dialog;
PIVector<PIDeque<int> > k_list; PIVector<PIDeque<int>> k_list;
QVector<CDDirectKTypeDialog::TypeInfo> info_list; QVector<CDDirectKTypeDialog::TypeInfo> info_list;
private slots: private slots:
@@ -39,17 +40,16 @@ private slots:
signals: signals:
void removeRequest(); void removeRequest();
}; };
class CDDirectK
: public QWidget
class CDDirectK: public QWidget, public Ui::CDDirectK , public Ui::CDDirectK {
{
Q_OBJECT Q_OBJECT
public: public:
explicit CDDirectK(QWidget *parent = 0); explicit CDDirectK(QWidget * parent = 0);
~CDDirectK(); ~CDDirectK();
void reset(); void reset();
@@ -59,7 +59,7 @@ public:
private: private:
void addArea(); void addArea();
QList<KDockWidget * > docks; QList<KDockWidget *> docks;
QMainWindow * da; QMainWindow * da;
public slots: public slots:
@@ -71,7 +71,6 @@ private slots:
void on_buttonRemoveAll_clicked(); void on_buttonRemoveAll_clicked();
signals: signals:
}; };
#endif // CDDIRECTK_H #endif // CDDIRECTK_H

View File

@@ -1,25 +1,25 @@
#include "cddirectk_type_dialog.h" #include "cddirectk_type_dialog.h"
#include "cdutils_core.h" #include "cdutils_core.h"
#include "piqt.h"
#include "qcd_core.h" #include "qcd_core.h"
#include "qcd_model.h" #include "qcd_model.h"
#include "piqt.h"
#include "spinslider.h"
#include "qvariantedit.h" #include "qvariantedit.h"
#include "spinslider.h"
CDDirectKTypeDialog::CDDirectKTypeDialog(QWidget * parent) : QDialog(parent), Ui::CDDirectKTypeDialog() { CDDirectKTypeDialog::CDDirectKTypeDialog(QWidget * parent): QDialog(parent), Ui::CDDirectKTypeDialog() {
setupUi(this); setupUi(this);
} }
CDDirectKTypeDialog::~CDDirectKTypeDialog() { CDDirectKTypeDialog::~CDDirectKTypeDialog() {}
}
CDDirectKTypeDialog::TypeInfo CDDirectKTypeDialog::getType() const { CDDirectKTypeDialog::TypeInfo CDDirectKTypeDialog::getType() const {
if (!groupBox->isChecked()) return TypeInfo(); if (!groupBox->isChecked()) return TypeInfo();
TypeInfo ret; TypeInfo ret;
ret.type = comboType->currentIndex(); ret.type = comboType->currentIndex();
ret.params_d[0] = evalMin->value(); ret.params_d[0] = evalMin->value();
ret.params_d[1] = evalMax->value(); ret.params_d[1] = evalMax->value();
ret.params_d[2] = spinDecimals->value(); ret.params_d[2] = spinDecimals->value();
@@ -30,8 +30,6 @@ CDDirectKTypeDialog::TypeInfo CDDirectKTypeDialog::getType() const {
} }
CDDirectKTypeDialog::TypeInfo::TypeInfo(int type_) { CDDirectKTypeDialog::TypeInfo::TypeInfo(int type_) {
type = type_; type = type_;
params_d.resize(4); params_d.resize(4);
@@ -52,14 +50,14 @@ QWidget * CDDirectKTypeDialog::TypeInfo::create() {
ret->setPrefix(params_s[0]); ret->setPrefix(params_s[0]);
ret->setSuffix(params_s[1]); ret->setSuffix(params_s[1]);
return ret; return ret;
} break; } break;
case 1: { case 1: {
QSlider * ret = new QSlider(Qt::Horizontal); QSlider * ret = new QSlider(Qt::Horizontal);
ret->setMinimum(params_d[0]); ret->setMinimum(params_d[0]);
ret->setMaximum(params_d[1]); ret->setMaximum(params_d[1]);
ret->setSingleStep(params_d[3]); ret->setSingleStep(params_d[3]);
return ret; return ret;
} break; } break;
case 2: { case 2: {
SpinSlider * ret = new SpinSlider(); SpinSlider * ret = new SpinSlider();
ret->setMinimum(params_d[0]); ret->setMinimum(params_d[0]);
@@ -69,7 +67,7 @@ QWidget * CDDirectKTypeDialog::TypeInfo::create() {
ret->setPrefix(params_s[0]); ret->setPrefix(params_s[0]);
ret->setSuffix(params_s[1]); ret->setSuffix(params_s[1]);
return ret; return ret;
} break; } break;
default: break; default: break;
} }
return new QVariantEdit(); return new QVariantEdit();

View File

@@ -1,13 +1,16 @@
#ifndef CDDIRECTK_TYPE_DIALOG_H #ifndef CDDIRECTK_TYPE_DIALOG_H
#define CDDIRECTK_TYPE_DIALOG_H #define CDDIRECTK_TYPE_DIALOG_H
#include <QDialog>
#include "ui_cddirectk_type_dialog.h" #include "ui_cddirectk_type_dialog.h"
#include <QDialog>
class CDDirectKTypeDialog: public QDialog, public Ui::CDDirectKTypeDialog
{ class CDDirectKTypeDialog
: public QDialog
, public Ui::CDDirectKTypeDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit CDDirectKTypeDialog(QWidget * parent = 0); explicit CDDirectKTypeDialog(QWidget * parent = 0);
~CDDirectKTypeDialog(); ~CDDirectKTypeDialog();
@@ -23,20 +26,18 @@ public:
TypeInfo getType() const; TypeInfo getType() const;
private: private:
public slots: public slots:
private slots: private slots:
signals: signals:
}; };
inline QDataStream & operator <<(QDataStream & s, const CDDirectKTypeDialog::TypeInfo & v) { inline QDataStream & operator<<(QDataStream & s, const CDDirectKTypeDialog::TypeInfo & v) {
s << v.type << v.params_d << v.params_s; s << v.type << v.params_d << v.params_s;
return s; return s;
} }
inline QDataStream & operator >>(QDataStream & s, CDDirectKTypeDialog::TypeInfo & v) { inline QDataStream & operator>>(QDataStream & s, CDDirectKTypeDialog::TypeInfo & v) {
s >> v.type >> v.params_d >> v.params_s; s >> v.type >> v.params_d >> v.params_s;
return s; return s;
} }

View File

@@ -1,44 +1,43 @@
#include "cdgraphics.h" #include "cdgraphics.h"
//#include "ui_qcd_graphic.h" // #include "ui_qcd_graphic.h"
#include "cdutils_core.h" #include "cdutils_core.h"
#include "cdutils_x.h" #include "cdutils_x.h"
#include "qcd_core.h"
#include "qcd_model.h"
#include "qcd_graphic.h"
#include "graphic.h" #include "graphic.h"
#include "piqt.h" #include "piqt.h"
#include <QMimeData> #include "qcd_core.h"
#include "qcd_graphic.h"
#include "qcd_model.h"
#include <QDockWidget>
#include <QDragEnterEvent> #include <QDragEnterEvent>
#include <QDragMoveEvent> #include <QDragMoveEvent>
#include <QDropEvent> #include <QDropEvent>
#include <QMainWindow>
#include <QDockWidget>
#include <QInputDialog> #include <QInputDialog>
#include <QMainWindow>
#include <QMimeData>
using namespace CDUtils; using namespace CDUtils;
QStringList CDUtils::getList(const PIVector<PIDeque<int> > & x_list) { QStringList CDUtils::getList(const PIVector<PIDeque<int>> & x_list) {
QStringList ret; QStringList ret;
piForeachC (PIDeque<int> & p, x_list) piForeachC(PIDeque<int> & p, x_list)
ret << PI2QString(CDCore::pathToString(p)); ret << PI2QString(CDCore::pathToString(p));
return ret; return ret;
} }
PIVector<PIDeque<int> > CDUtils::setList(const QStringList & l) { PIVector<PIDeque<int>> CDUtils::setList(const QStringList & l) {
PIVector<PIDeque<int> > ret; PIVector<PIDeque<int>> ret;
foreach (QString s, l) foreach(QString s, l)
ret << CDCore::stringToPath(Q2PIString(s)); ret << CDCore::stringToPath(Q2PIString(s));
return ret; return ret;
} }
GDockWidget::GDockWidget(QString title, QMainWindow * p): QDockWidget(title, p) { GDockWidget::GDockWidget(QString title, QMainWindow * p): QDockWidget(title, p) {
da = p; da = p;
menu = new QMenu(this); menu = new QMenu(this);
QAction * a = new QAction(QIcon(":/icons/document-edit.png"), "Rename ...", this); QAction * a = new QAction(QIcon(":/icons/document-edit.png"), "Rename ...", this);
connect(a, SIGNAL(triggered(bool)), this, SLOT(rename())); connect(a, SIGNAL(triggered(bool)), this, SLOT(rename()));
dactions << a; dactions << a;
@@ -65,7 +64,7 @@ void GDockWidget::addX(const CDType & t) {
} }
void GDockWidget::drawX(const PIMap<PIString, PIVector<double> > & data) { void GDockWidget::drawX(const PIMap<PIString, PIVector<double>> & data) {
for (int i = 0; i < x_list.size_s(); ++i) { for (int i = 0; i < x_list.size_s(); ++i) {
PIString sp = CDCore::pathToString(x_list[i]); PIString sp = CDCore::pathToString(x_list[i]);
PIVector<double> ch(data.at(sp)); PIVector<double> ch(data.at(sp));
@@ -79,10 +78,10 @@ void GDockWidget::drawX(const PIMap<PIString, PIVector<double> > & data) {
QByteArray GDockWidget::save() const { QByteArray GDockWidget::save() const {
ChunkStream cs; ChunkStream cs;
cs.add(1, windowTitle()) cs.add(1, windowTitle())
.add(2, getList(x_list)) .add(2, getList(x_list))
.add(3, graphic->graphic()->save()) .add(3, graphic->graphic()->save())
.add(4, graphic->evalSpinBoxHistory()->expression()) .add(4, graphic->evalSpinBoxHistory()->expression())
.add(5, graphic->evalSpinBoxVisible()->expression()); .add(5, graphic->evalSpinBoxVisible()->expression());
return cs.data(); return cs.data();
} }
@@ -117,40 +116,40 @@ void GDockWidget::changedGlobal() {
bool GDockWidget::eventFilter(QObject * o, QEvent * e) { bool GDockWidget::eventFilter(QObject * o, QEvent * e) {
//if (o == graphic->viewport()) { // if (o == graphic->viewport()) {
switch (e->type()) { switch (e->type()) {
case QEvent::DragMove: { case QEvent::DragMove: {
QDragMoveEvent * de = (QDragMoveEvent*)e; QDragMoveEvent * de = (QDragMoveEvent *)e;
const QMimeData * mime = de->mimeData(); const QMimeData * mime = de->mimeData();
//qDebug() << "enter" << mime; // qDebug() << "enter" << mime;
if (!mime) break; if (!mime) break;
if (!mime->text().startsWith("x")) break; if (!mime->text().startsWith("x")) break;
de->setDropAction(Qt::CopyAction); de->setDropAction(Qt::CopyAction);
de->accept(); de->accept();
return true; return true;
} break; } break;
case QEvent::DragEnter: { case QEvent::DragEnter: {
QDragEnterEvent * de = (QDragEnterEvent*)e; QDragEnterEvent * de = (QDragEnterEvent *)e;
const QMimeData * mime = de->mimeData(); const QMimeData * mime = de->mimeData();
//qDebug() << "enter" << mime; // qDebug() << "enter" << mime;
if (!mime) break; if (!mime) break;
if (!mime->text().startsWith("x")) break; if (!mime->text().startsWith("x")) break;
de->setDropAction(Qt::CopyAction); de->setDropAction(Qt::CopyAction);
de->accept(); de->accept();
return true; return true;
} break; } break;
case QEvent::Drop: { case QEvent::Drop: {
QDropEvent * de = (QDropEvent*)e; QDropEvent * de = (QDropEvent *)e;
const QMimeData * mime = de->mimeData(); const QMimeData * mime = de->mimeData();
if (!mime) break; if (!mime) break;
//qDebug() << "drop" << mime->text(); // qDebug() << "drop" << mime->text();
if (!mime->text().startsWith("x")) break; if (!mime->text().startsWith("x")) break;
addX(X[CDCore::stringToPath(Q2PIString(mime->text().mid(1)))]); addX(X[CDCore::stringToPath(Q2PIString(mime->text().mid(1)))]);
de->accept(); de->accept();
return true; return true;
} break; } break;
default: break; default: break;
} }
//} //}
return QWidget::eventFilter(o, e); return QWidget::eventFilter(o, e);
} }
@@ -181,22 +180,21 @@ void GDockWidget::contextMenuEvent(QContextMenuEvent * e) {
CDGraphicWidget * GDockWidget::viewportGraphic(QObject * o) const { CDGraphicWidget * GDockWidget::viewportGraphic(QObject * o) const {
if (!o) return 0; if (!o) return 0;
while (!qobject_cast<CDGraphicWidget*>(o) && o) while (!qobject_cast<CDGraphicWidget *>(o) && o)
o = o->parent(); o = o->parent();
return qobject_cast<CDGraphicWidget*>(o); return qobject_cast<CDGraphicWidget *>(o);
} }
void GDockWidget::rename() { void GDockWidget::rename() {
QString nn = QInputDialog::getText(this, tr("Rename area"), tr("New area name:"), QString nn = QInputDialog::getText(this, tr("Rename area"), tr("New area name:"), QLineEdit::Normal, windowTitle());
QLineEdit::Normal, windowTitle());
if (nn.isEmpty()) return; if (nn.isEmpty()) return;
setWindowTitle(nn); setWindowTitle(nn);
} }
void GDockWidget::removeX() { void GDockWidget::removeX() {
QAction * a = qobject_cast<QAction * >(sender()); QAction * a = qobject_cast<QAction *>(sender());
if (!a) return; if (!a) return;
int ind = a->data().toInt(); int ind = a->data().toInt();
if (ind < 0 || ind >= x_list.size_s()) return; if (ind < 0 || ind >= x_list.size_s()) return;
@@ -205,9 +203,7 @@ void GDockWidget::removeX() {
} }
CDGraphics::CDGraphics(QWidget * parent): QWidget(parent), Ui::CDGraphics() {
CDGraphics::CDGraphics(QWidget * parent) : QWidget(parent), Ui::CDGraphics() {
setupUi(this); setupUi(this);
da = new QMainWindow(); da = new QMainWindow();
da->setWindowFlags(frame->windowFlags()); da->setWindowFlags(frame->windowFlags());
@@ -216,8 +212,7 @@ CDGraphics::CDGraphics(QWidget * parent) : QWidget(parent), Ui::CDGraphics() {
} }
CDGraphics::~CDGraphics() { CDGraphics::~CDGraphics() {}
}
void CDGraphics::reset() { void CDGraphics::reset() {
@@ -229,12 +224,10 @@ void CDGraphics::reset() {
QByteArray CDGraphics::save() const { QByteArray CDGraphics::save() const {
ChunkStream cs; ChunkStream cs;
QVector<QByteArray> dstates; QVector<QByteArray> dstates;
foreach (GDockWidget * d, docks) { foreach(GDockWidget * d, docks) {
dstates << d->save(); dstates << d->save();
} }
cs.add(1, docks.size()) cs.add(1, docks.size()).add(2, dstates).add(3, da->saveState());
.add(2, dstates)
.add(3, da->saveState());
X.lock(); X.lock();
cs.add(4, getList(X.enabledList())); cs.add(4, getList(X.enabledList()));
X.unlock(); X.unlock();
@@ -251,23 +244,20 @@ void CDGraphics::load(QByteArray ba) {
switch (cs.read()) { switch (cs.read()) {
case 1: { case 1: {
int s = cs.getData<int>(); int s = cs.getData<int>();
piForTimes (s) piForTimes(s) addGraphic();
addGraphic(); } break;
} break;
case 2: { case 2: {
QVector<QByteArray> dstates = cs.getData<QVector<QByteArray> >(); QVector<QByteArray> dstates = cs.getData<QVector<QByteArray>>();
for (int i = 0; i < piMini(dstates.size(), docks.size()); ++i) for (int i = 0; i < piMini(dstates.size(), docks.size()); ++i)
docks[i]->load(dstates[i]); docks[i]->load(dstates[i]);
} break; } break;
case 3: da->restoreState(cs.getData<QByteArray>()); break; case 3: da->restoreState(cs.getData<QByteArray>()); break;
case 4: case 4:
X.lock(); X.lock();
X.setEnabledList(setList(cs.getData<QStringList>())); X.setEnabledList(setList(cs.getData<QStringList>()));
X.unlock(); X.unlock();
break; break;
case 5: case 5: buttonConfigVisible->setChecked(cs.getData<bool>()); break;
buttonConfigVisible->setChecked(cs.getData<bool>());
break;
default: break; default: break;
} }
} }
@@ -276,9 +266,8 @@ void CDGraphics::load(QByteArray ba) {
GDockWidget * CDGraphics::graphicDock(Graphic * o) const { GDockWidget * CDGraphics::graphicDock(Graphic * o) const {
if (!o) return 0; if (!o) return 0;
foreach (GDockWidget * d, docks) foreach(GDockWidget * d, docks)
if (d->widget() == o) if (d->widget() == o) return d;
return d;
return 0; return 0;
} }
@@ -301,11 +290,11 @@ void CDGraphics::addGraphic() {
void CDGraphics::receivedX() { void CDGraphics::receivedX() {
PIMap<PIString, PIVector<double> > data; PIMap<PIString, PIVector<double>> data;
X.lock(); X.lock();
PIVector<PIDeque<int> > x_list = X.enabledList(); PIVector<PIDeque<int>> x_list = X.enabledList();
PIVector<double> ch; PIVector<double> ch;
piForeachC (PIDeque<int> & p, x_list) { piForeachC(PIDeque<int> & p, x_list) {
CDType & t(X[p]); CDType & t(X[p]);
if (t.xmode_rec() == CDType::X_Current) if (t.xmode_rec() == CDType::X_Current)
ch.resize(1).fill(t.toDouble()); ch.resize(1).fill(t.toDouble());
@@ -314,21 +303,21 @@ void CDGraphics::receivedX() {
t.history.clear(); t.history.clear();
data[CDCore::pathToString(t.path())] = ch; data[CDCore::pathToString(t.path())] = ch;
} }
//piCout << data; // piCout << data;
X.unlock(); X.unlock();
foreach (GDockWidget * d, docks) foreach(GDockWidget * d, docks)
d->drawX(data); d->drawX(data);
} }
void CDGraphics::changedGlobal() { void CDGraphics::changedGlobal() {
foreach (GDockWidget * d, docks) foreach(GDockWidget * d, docks)
d->changedGlobal(); d->changedGlobal();
} }
void CDGraphics::removeGraphic() { void CDGraphics::removeGraphic() {
GDockWidget * d = qobject_cast<GDockWidget * >(sender()); GDockWidget * d = qobject_cast<GDockWidget *>(sender());
if (!d) return; if (!d) return;
docks.removeAll(d); docks.removeAll(d);
d->deleteLater(); d->deleteLater();
@@ -343,7 +332,7 @@ void CDGraphics::on_buttonAdd_clicked() {
void CDGraphics::on_buttonClear_clicked() { void CDGraphics::on_buttonClear_clicked() {
foreach (GDockWidget * d, docks) foreach(GDockWidget * d, docks)
d->graphic->graphic()->clear(); d->graphic->graphic()->clear();
} }

View File

@@ -1,33 +1,33 @@
#ifndef CDGRAPHICS_H #ifndef CDGRAPHICS_H
#define CDGRAPHICS_H #define CDGRAPHICS_H
#include <QWidget> #include "qcd_graphic.h"
#include "ui_cdgraphics.h"
#include <QDockWidget> #include <QDockWidget>
#include <QMenu> #include <QMenu>
#include "ui_cdgraphics.h" #include <QWidget>
#include "qcd_graphic.h"
#include <pistring.h> #include <pistring.h>
namespace CDUtils { namespace CDUtils {
class CDType; class CDType;
class CDSection; class CDSection;
QStringList getList(const PIVector<PIDeque<int> > & x_list); QStringList getList(const PIVector<PIDeque<int>> & x_list);
PIVector<PIDeque<int> > setList(const QStringList & l); PIVector<PIDeque<int>> setList(const QStringList & l);
} } // namespace CDUtils
class QMainWindow; class QMainWindow;
class Graphic; class Graphic;
class GDockWidget: public QDockWidget { class GDockWidget: public QDockWidget {
Q_OBJECT Q_OBJECT
public: public:
GDockWidget(QString title = QString(), QMainWindow * p = 0); GDockWidget(QString title = QString(), QMainWindow * p = 0);
void addX(const CDUtils::CDType & t); void addX(const CDUtils::CDType & t);
void drawX(const PIMap<PIString, PIVector<double> > & data); void drawX(const PIMap<PIString, PIVector<double>> & data);
QByteArray save() const; QByteArray save() const;
void load(QByteArray ba); void load(QByteArray ba);
void changedGlobal(); void changedGlobal();
@@ -39,10 +39,10 @@ private:
void contextMenuEvent(QContextMenuEvent * e); void contextMenuEvent(QContextMenuEvent * e);
CDGraphicWidget * viewportGraphic(QObject * o) const; CDGraphicWidget * viewportGraphic(QObject * o) const;
QMenu * menu, * menu_x; QMenu *menu, *menu_x;
QList<QAction*> dactions; QList<QAction *> dactions;
QMainWindow * da; QMainWindow * da;
PIVector<PIDeque<int> > x_list; PIVector<PIDeque<int>> x_list;
private slots: private slots:
void rename(); void rename();
@@ -50,17 +50,16 @@ private slots:
signals: signals:
void removeRequest(); void removeRequest();
}; };
class CDGraphics
: public QWidget
class CDGraphics : public QWidget, public Ui::CDGraphics , public Ui::CDGraphics {
{
Q_OBJECT Q_OBJECT
public: public:
explicit CDGraphics(QWidget *parent = 0); explicit CDGraphics(QWidget * parent = 0);
~CDGraphics(); ~CDGraphics();
void reset(); void reset();
@@ -72,7 +71,7 @@ private:
void addXToGraphic(const QString & xp, Graphic * g); void addXToGraphic(const QString & xp, Graphic * g);
void addGraphic(); void addGraphic();
QList<GDockWidget * > docks; QList<GDockWidget *> docks;
QMainWindow * da; QMainWindow * da;
public slots: public slots:
@@ -86,7 +85,6 @@ private slots:
void on_buttonRemoveAll_clicked(); void on_buttonRemoveAll_clicked();
signals: signals:
}; };
#endif // CDGRAPHICS_H #endif // CDGRAPHICS_H

View File

@@ -1,27 +1,29 @@
#include "edockwidget.h"
#include "cdpultwindow.h" #include "cdpultwindow.h"
#include "cdutils_core.h" #include "cdutils_core.h"
#include "cdutils_k.h" #include "cdutils_k.h"
#include "cdutils_x.h"
#include "cdutils_m.h" #include "cdutils_m.h"
#include "qcd_core.h" #include "cdutils_x.h"
#include "qcd_view.h"
#include "qcd_model.h"
#include "qcd_modedialog.h"
#include "chunkstream.h" #include "chunkstream.h"
#include "qvariantedit.h" #include "edockwidget.h"
#include "piqt.h" #include "piqt.h"
#include "piqt_highlighter.h" #include "piqt_highlighter.h"
#include "qcd_core.h"
#include "qcd_modedialog.h"
#include "qcd_model.h"
#include "qcd_view.h"
#include "qcodeedit.h" #include "qcodeedit.h"
#include "qvariantedit.h"
#include <QFileDialog> #include <QFileDialog>
#include <QScrollBar>
#include <QImageReader> #include <QImageReader>
#include <QMessageBox> #include <QMessageBox>
#include <QScrollBar>
using namespace CDUtils; using namespace CDUtils;
CDPultWindow::CDPultWindow(QWidget *parent) : EMainWindow(parent), Ui::CDPultWindow() { CDPultWindow::CDPultWindow(QWidget * parent): EMainWindow(parent), Ui::CDPultWindow() {
setupUi(this); setupUi(this);
centralWidget()->hide(); centralWidget()->hide();
setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North); setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
@@ -48,24 +50,22 @@ CDPultWindow::CDPultWindow(QWidget *parent) : EMainWindow(parent), Ui::CDPultWin
session.addEntry(ribbon->tabWidget()); session.addEntry(ribbon->tabWidget());
session.load(); session.load();
reset(); reset();
connect(widgetK, SIGNAL(addToLog(CDViewWidget::LogIcon,QString)), this, SLOT(addToLog(CDViewWidget::LogIcon,QString))); connect(widgetK, SIGNAL(addToLog(CDViewWidget::LogIcon, QString)), this, SLOT(addToLog(CDViewWidget::LogIcon, QString)));
connect(widgetX, SIGNAL(addToLog(CDViewWidget::LogIcon,QString)), this, SLOT(addToLog(CDViewWidget::LogIcon,QString))); connect(widgetX, SIGNAL(addToLog(CDViewWidget::LogIcon, QString)), this, SLOT(addToLog(CDViewWidget::LogIcon, QString)));
connect(widgetC, SIGNAL(addToLog(CDViewWidget::LogIcon,QString)), this, SLOT(addToLog(CDViewWidget::LogIcon,QString))); connect(widgetC, SIGNAL(addToLog(CDViewWidget::LogIcon, QString)), this, SLOT(addToLog(CDViewWidget::LogIcon, QString)));
connect(widgetM, SIGNAL(addToLog(CDViewWidget::LogIcon,QString)), this, SLOT(addToLog(CDViewWidget::LogIcon,QString))); connect(widgetM, SIGNAL(addToLog(CDViewWidget::LogIcon, QString)), this, SLOT(addToLog(CDViewWidget::LogIcon, QString)));
connect(widgetK->view, SIGNAL(changedGlobal()), widgetDirectK, SLOT(changedGlobal())); connect(widgetK->view, SIGNAL(changedGlobal()), widgetDirectK, SLOT(changedGlobal()));
connect(widgetX->view, SIGNAL(changedGlobal()), widgetGraphics, SLOT(changedGlobal())); connect(widgetX->view, SIGNAL(changedGlobal()), widgetGraphics, SLOT(changedGlobal()));
connect(widgetX->view, SIGNAL(receivedX()), widgetGraphics, SLOT(receivedX())); connect(widgetX->view, SIGNAL(receivedX()), widgetGraphics, SLOT(receivedX()));
connect(widgetM->view, SIGNAL(messageReceived(QString,int,QString)), this, SLOT(messageReceived(QString,int,QString))); connect(widgetM->view, SIGNAL(messageReceived(QString, int, QString)), this, SLOT(messageReceived(QString, int, QString)));
QCDCore::instance()->bindWidget(widgetK->view); QCDCore::instance()->bindWidget(widgetK->view);
QCDCore::instance()->setDirectKEnabled(true); QCDCore::instance()->setDirectKEnabled(true);
X.start(); X.start();
if (windowState() == Qt::WindowMinimized) if (windowState() == Qt::WindowMinimized) setWindowState(Qt::WindowNoState);
setWindowState(Qt::WindowNoState);
} }
CDPultWindow::~CDPultWindow() { CDPultWindow::~CDPultWindow() {}
}
void CDPultWindow::loadFile(const QString & fp) { void CDPultWindow::loadFile(const QString & fp) {
@@ -87,14 +87,13 @@ void CDPultWindow::apply(bool sessions) {
if (sessions) { if (sessions) {
widgetGraphics->load(session_gr); widgetGraphics->load(session_gr);
widgetDirectK->load(session_dk); widgetDirectK->load(session_dk);
if (!session_mw.isEmpty()) if (!session_mw.isEmpty()) restoreState(session_mw);
restoreState(session_mw);
X.lock(); X.lock();
PIVector<PIDeque<int> > x_list = X.enabledList(); PIVector<PIDeque<int>> x_list = X.enabledList();
X.unlock(); X.unlock();
piForeachC (PIDeque<int> & p, x_list) piForeachC(PIDeque<int> & p, x_list)
X.enable(X[p]); X.enable(X[p]);
((CDItemModel*)widgetX->view->model())->updateModel(); ((CDItemModel *)widgetX->view->model())->updateModel();
widgetX->view->expandAll(); widgetX->view->expandAll();
} }
dockCDKView->setVisible(checkHasK->isChecked()); dockCDKView->setVisible(checkHasK->isChecked());
@@ -105,10 +104,9 @@ void CDPultWindow::apply(bool sessions) {
} }
void CDPultWindow::closeEvent(QCloseEvent *e) { void CDPultWindow::closeEvent(QCloseEvent * e) {
EMainWindow::closeEvent(e); EMainWindow::closeEvent(e);
if (!e->isAccepted()) if (!e->isAccepted()) return;
return;
QApplication::closeAllWindows(); QApplication::closeAllWindows();
session.save(); session.save();
session.setFile(QString()); session.setFile(QString());
@@ -141,8 +139,7 @@ bool CDPultWindow::load(const QString & path) {
checkHasM->setChecked(conf.getValue("has_m").toBool()); checkHasM->setChecked(conf.getValue("has_m").toBool());
checkDefaultConfig->setChecked(conf.getValue("default_config").toBool()); checkDefaultConfig->setChecked(conf.getValue("default_config").toBool());
codeConfig->setText(QByteArray2QString(conf.getValue("config").toByteArray())); codeConfig->setText(QByteArray2QString(conf.getValue("config").toByteArray()));
if (codeConfig->text().isEmpty()) if (codeConfig->text().isEmpty()) codeConfig->setText(def_config);
codeConfig->setText(def_config);
session_gr = conf.getValue("session_gr").toByteArray(); session_gr = conf.getValue("session_gr").toByteArray();
session_dk = conf.getValue("session_dk").toByteArray(); session_dk = conf.getValue("session_dk").toByteArray();
session_mw = conf.getValue("session_mw").toByteArray(); session_mw = conf.getValue("session_mw").toByteArray();
@@ -180,8 +177,8 @@ bool CDPultWindow::save(const QString & path) {
file_name = path; file_name = path;
return true; return true;
//widgetK->setFile(path); // widgetK->setFile(path);
//widgetK->save(); // widgetK->save();
} }
@@ -201,7 +198,7 @@ QByteArray CDPultWindow::appIcon() const {
QBuffer buff(&ret); QBuffer buff(&ret);
buff.open(QIODevice::WriteOnly); buff.open(QIODevice::WriteOnly);
icon.save(&buff, "png"); icon.save(&buff, "png");
//qDebug() << "s" << ret.size(); // qDebug() << "s" << ret.size();
return ret; return ret;
} }
@@ -212,16 +209,16 @@ void CDPultWindow::setAppIcon(QByteArray ba) {
setWindowIcon(QIcon()); setWindowIcon(QIcon());
return; return;
} }
//qDebug() << "l" << ba.size(); // qDebug() << "l" << ba.size();
icon = QImage::fromData(ba); icon = QImage::fromData(ba);
setWindowIcon(QIcon(QPixmap::fromImage(icon))); setWindowIcon(QIcon(QPixmap::fromImage(icon)));
//qDebug() << QApplication::windowIcon().availableSizes(); // qDebug() << QApplication::windowIcon().availableSizes();
} }
void CDPultWindow::addToLog(CDViewWidget::LogIcon icon, const QString & msg) { void CDPultWindow::addToLog(CDViewWidget::LogIcon icon, const QString & msg) {
QListWidgetItem * ni = new QListWidgetItem(log_icons[icon], "(" + QTime::currentTime().toString() + ") " + msg); QListWidgetItem * ni = new QListWidgetItem(log_icons[icon], "(" + QTime::currentTime().toString() + ") " + msg);
bool s = listLog->verticalScrollBar()->value() == listLog->verticalScrollBar()->maximum(); bool s = listLog->verticalScrollBar()->value() == listLog->verticalScrollBar()->maximum();
listLog->addItem(ni); listLog->addItem(ni);
if (s) listLog->scrollToBottom(); if (s) listLog->scrollToBottom();
} }
@@ -231,8 +228,7 @@ void CDPultWindow::messageReceived(QString path, int type, QString msg) {
MessageType mt = (MessageType)type; MessageType mt = (MessageType)type;
const CDType & t(M.root()[CDCore::stringToPath(Q2PIString(path))]); const CDType & t(M.root()[CDCore::stringToPath(Q2PIString(path))]);
if (t.cd_type() != CDType::cdM) return; if (t.cd_type() != CDType::cdM) return;
if (mt == MessageBox) if (mt == MessageBox) QMessageBox::information(this, windowTitle(), QString("[%1]\n%2").arg(PI2QString(t.name()), msg));
QMessageBox::information(this, windowTitle(), QString("[%1]\n%2").arg(PI2QString(t.name()), msg));
} }
@@ -262,13 +258,15 @@ void CDPultWindow::on_editFileK_valueChanged(const QVariant & p) {
} }
if (!fi.path().isEmpty() && fi.path() != ".") { if (!fi.path().isEmpty() && fi.path() != ".") {
dir = fi.path(); dir = fi.path();
if (!dir.endsWith("/")) if (!dir.endsWith("/")) dir += "/";
dir += "/";
} }
QAD::File f = editFileK->value().value<QAD::File>(); QAD::File f = editFileK->value().value<QAD::File>();
f.file = dir + xn + dot + ext; editFileX->setValue(QVariant::fromValue(f)); f.file = dir + xn + dot + ext;
f.file = dir + cn + dot + ext; editFileC->setValue(QVariant::fromValue(f)); editFileX->setValue(QVariant::fromValue(f));
f.file = dir + mn + dot + ext; editFileM->setValue(QVariant::fromValue(f)); f.file = dir + cn + dot + ext;
editFileC->setValue(QVariant::fromValue(f));
f.file = dir + mn + dot + ext;
editFileM->setValue(QVariant::fromValue(f));
} }
@@ -284,10 +282,12 @@ void CDPultWindow::on_lineSessionName_textChanged(const QString & t) {
void CDPultWindow::on_buttonIcon_clicked() { void CDPultWindow::on_buttonIcon_clicked() {
QList<QByteArray> ifl = QImageReader::supportedImageFormats(); QList<QByteArray> ifl = QImageReader::supportedImageFormats();
QStringList sfl; foreach (QByteArray s, ifl) sfl << ("*." + QString(s).toLower()); QStringList sfl;
foreach(QByteArray s, ifl)
sfl << ("*." + QString(s).toLower());
QString f = QFileDialog::getOpenFileName(this, tr("Select icon"), last_icon, tr("Images") + " (" + sfl.join(" ") + ")"); QString f = QFileDialog::getOpenFileName(this, tr("Select icon"), last_icon, tr("Images") + " (" + sfl.join(" ") + ")");
if (f.isEmpty()) return; if (f.isEmpty()) return;
last_icon = f; last_icon = f;
icon = QImage(last_icon); icon = QImage(last_icon);
setWindowIcon(QIcon(QPixmap::fromImage(icon))); setWindowIcon(QIcon(QPixmap::fromImage(icon)));
} }

View File

@@ -1,32 +1,32 @@
#ifndef CDPULTWINDOW_H #ifndef CDPULTWINDOW_H
#define CDPULTWINDOW_H #define CDPULTWINDOW_H
#include "emainwindow.h"
#include "ui_cdpultwindow.h"
#include "cdviewwidget.h" #include "cdviewwidget.h"
#include "ribbon.h" #include "emainwindow.h"
#include "piobject.h" #include "piobject.h"
#include "ribbon.h"
#include "ui_cdpultwindow.h"
class CDPultWindow : public EMainWindow, public Ui::CDPultWindow class CDPultWindow
{ : public EMainWindow
, public Ui::CDPultWindow {
Q_OBJECT Q_OBJECT
Q_ENUMS(LogIcon) Q_ENUMS(LogIcon)
public:
explicit CDPultWindow(QWidget *parent = 0); public:
explicit CDPultWindow(QWidget * parent = 0);
~CDPultWindow(); ~CDPultWindow();
void loadFile(const QString & fp); void loadFile(const QString & fp);
void apply(bool sessions); void apply(bool sessions);
private: private:
void closeEvent(QCloseEvent *); void closeEvent(QCloseEvent *);
void reset(bool full = false); void reset(bool full = false);
bool load(const QString & path); bool load(const QString & path);
bool save(const QString & path); bool save(const QString & path);
QString loadFilter() {return "Pult session(*.conf)";} QString loadFilter() { return "Pult session(*.conf)"; }
QString saveFilter() {return loadFilter();} QString saveFilter() { return loadFilter(); }
void loadingSession(QPIConfig & conf); void loadingSession(QPIConfig & conf);
void savingSession(QPIConfig & conf); void savingSession(QPIConfig & conf);

View File

@@ -1,24 +1,25 @@
#include "cdviewwidget.h" #include "cdviewwidget.h"
#include "cdutils_core.h" #include "cdutils_core.h"
#include "qcd_core.h" #include "qcd_core.h"
#include "qcd_model.h"
#include "qcd_modedialog.h" #include "qcd_modedialog.h"
#include "qcd_model.h"
#include "qvariantedit.h" #include "qvariantedit.h"
#include <QFileDialog> #include <QFileDialog>
CDViewWidget::CDViewWidget(QWidget * parent) : QWidget(parent), Ui::CDViewWidget() { CDViewWidget::CDViewWidget(QWidget * parent): QWidget(parent), Ui::CDViewWidget() {
qRegisterMetaType<CDViewWidget::LogIcon>("CDViewWidget::LogIcon"); qRegisterMetaType<CDViewWidget::LogIcon>("CDViewWidget::LogIcon");
setupUi(this); setupUi(this);
connect(view, SIGNAL(sendSucceed()), this, SLOT(sended())); connect(view, SIGNAL(sendSucceed()), this, SLOT(sended()));
connect(view, SIGNAL(receiveSucceed()), this, SLOT(received())); connect(view, SIGNAL(receiveSucceed()), this, SLOT(received()));
connect(view, SIGNAL(sendFailed()), this, SLOT(sendFailed())); connect(view, SIGNAL(sendFailed()), this, SLOT(sendFailed()));
connect(view, SIGNAL(receiveFailed()), this, SLOT(receiveFailed())); connect(view, SIGNAL(receiveFailed()), this, SLOT(receiveFailed()));
} }
CDViewWidget::~CDViewWidget() { CDViewWidget::~CDViewWidget() {}
}
void CDViewWidget::reset() { void CDViewWidget::reset() {
@@ -41,14 +42,20 @@ void CDViewWidget::setFile(const QString & f) {
void CDViewWidget::on_buttonSend_clicked() { void CDViewWidget::on_buttonSend_clicked() {
if (view->inProgress()) {addToLog(WaitIcon, "processing..."); return;} if (view->inProgress()) {
addToLog(WaitIcon, "processing...");
return;
}
addToLog(WaitIcon, "Sending " + tl_u + "..."); addToLog(WaitIcon, "Sending " + tl_u + "...");
view->send(); view->send();
} }
void CDViewWidget::on_buttonReceive_clicked() { void CDViewWidget::on_buttonReceive_clicked() {
if (view->inProgress()) {addToLog(WaitIcon, "processing..."); return;} if (view->inProgress()) {
addToLog(WaitIcon, "processing...");
return;
}
addToLog(WaitIcon, "Receiving " + tl_u + "..."); addToLog(WaitIcon, "Receiving " + tl_u + "...");
view->receive(); view->receive();
} }
@@ -65,8 +72,10 @@ void CDViewWidget::on_buttonSave_clicked() {
void CDViewWidget::on_buttonParse_clicked() { void CDViewWidget::on_buttonParse_clicked() {
QString path = QFileDialog::getOpenFileName(this, "Select header file", "", QString path = QFileDialog::getOpenFileName(this,
QString("%1 Description(%2_description.h);;Headers(*.h)").arg(tl_u, tl_l)); "Select header file",
"",
QString("%1 Description(%2_description.h);;Headers(*.h)").arg(tl_u, tl_l));
if (path.isEmpty()) return; if (path.isEmpty()) return;
CDUtils::UpdateModeFlags mode = CDUtils::SaveByName; CDUtils::UpdateModeFlags mode = CDUtils::SaveByName;
if (!view->root()->isEmpty()) { if (!view->root()->isEmpty()) {

View File

@@ -1,18 +1,26 @@
#ifndef CDVIEWWIDGET_H #ifndef CDVIEWWIDGET_H
#define CDVIEWWIDGET_H #define CDVIEWWIDGET_H
#include <QWidget>
#include "ui_cdviewwidget.h" #include "ui_cdviewwidget.h"
#include <QWidget>
class CDViewWidget : public QWidget, public Ui::CDViewWidget
{ class CDViewWidget
: public QWidget
, public Ui::CDViewWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit CDViewWidget(QWidget *parent = 0); explicit CDViewWidget(QWidget * parent = 0);
~CDViewWidget(); ~CDViewWidget();
enum LogIcon {NoIcon, OKIcon, FailIcon, WaitIcon}; enum LogIcon {
NoIcon,
OKIcon,
FailIcon,
WaitIcon
};
void reset(); void reset();
void setType(int t); void setType(int t);
@@ -22,20 +30,19 @@ private:
QString tl_u, tl_l; QString tl_u, tl_l;
private slots: private slots:
void sended() {addToLog(OKIcon, tl_u + " " + tr("sended succesfull"));} void sended() { addToLog(OKIcon, tl_u + " " + tr("sended succesfull")); }
void received() {addToLog(OKIcon, tl_u + " " + tr("received succesfull"));} void received() { addToLog(OKIcon, tl_u + " " + tr("received succesfull")); }
void sendFailed() {addToLog(FailIcon, tl_u + " " + tr("NOT sended"));} void sendFailed() { addToLog(FailIcon, tl_u + " " + tr("NOT sended")); }
void receiveFailed() {addToLog(FailIcon, tl_u + " " + tr("NOT received"));} void receiveFailed() { addToLog(FailIcon, tl_u + " " + tr("NOT received")); }
void on_buttonSend_clicked(); void on_buttonSend_clicked();
void on_buttonReceive_clicked(); void on_buttonReceive_clicked();
void on_buttonLoad_clicked(); void on_buttonLoad_clicked();
void on_buttonSave_clicked(); void on_buttonSave_clicked();
void on_buttonParse_clicked(); void on_buttonParse_clicked();
//void on_buttonCalculate_clicked(); // void on_buttonCalculate_clicked();
signals: signals:
void addToLog(CDViewWidget::LogIcon icon, const QString & msg); void addToLog(CDViewWidget::LogIcon icon, const QString & msg);
}; };
#endif // CDVIEWWIDGET_H #endif // CDVIEWWIDGET_H

View File

@@ -1,12 +1,12 @@
#include <QApplication>
#include "cdpultwindow.h" #include "cdpultwindow.h"
int main(int argc, char *argv[]) { #include <QApplication>
int main(int argc, char * argv[]) {
QApplication a(argc, argv); QApplication a(argc, argv);
enableHighDPI(); enableHighDPI();
CDPultWindow w; CDPultWindow w;
w.show(); w.show();
if (a.arguments().size() > 1) if (a.arguments().size() > 1) w.loadFile(a.arguments()[1]);
w.loadFile(a.arguments()[1]);
return a.exec(); return a.exec();
} }