git-svn-id: svn://db.shs.com.ru/libs@123 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
#include "cdutils_core.h"
|
||||
#include "cdutils_parser.h"
|
||||
#include "piconfig.h"
|
||||
#include "cdutils_protocol.h"
|
||||
#include "piiodevice.h"
|
||||
#include "piiobytearray.h"
|
||||
#include "piiostring.h"
|
||||
#include "pifile.h"
|
||||
|
||||
@@ -74,15 +73,20 @@ __Core_Initializer__::~__Core_Initializer__() {
|
||||
|
||||
|
||||
|
||||
CDCore::CDCore(const char * conf) {
|
||||
CDCore::CDCore() {
|
||||
setName("CDCore");
|
||||
CONNECTU(&connection, dataReceivedEvent, this, dataReceived);
|
||||
PIString s(conf);
|
||||
PIString s(app_config);
|
||||
connection.configureFromString(&s);
|
||||
datatr.setPacketSize(960);
|
||||
connection.start();
|
||||
k_.name = "__root__";
|
||||
k_.alias = "root";
|
||||
|
||||
CONNECTU(&datatr, sendRequest, this, dtSendRequest)
|
||||
CONNECTU(&datatr, receiveFinished, this, dtReceiveFinished)
|
||||
CONNECTU(&sendt, started, this, sendThread)
|
||||
|
||||
/*k_[1] = KType(1, "123", "120+3", "comment");
|
||||
k_[2] = KType(2, "1", "2", "comm");
|
||||
k_[4] = KType(4, "-0.6", "-6/10", "mment");
|
||||
@@ -118,11 +122,18 @@ void CDCore::k_write(PIIODevice * d) {
|
||||
void CDCore::k_read(PIIODevice * d) {
|
||||
PIConfig conf(d, PIIODevice::ReadOnly);
|
||||
k_.read(&(conf.rootEntry()));
|
||||
PIVector<PIIODevice * > ds = connection.allDevices();
|
||||
// piForeach(PIIODevice * d, ds) {
|
||||
// if (d)
|
||||
// piCoutObj << d->constructFullPath() << d->isOpened();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
void CDCore::k_parse(PIIODevice * d) {
|
||||
k_ = CDParser::parse(d, CDType::cdK);
|
||||
k_.name = "__root__";
|
||||
k_.alias = "root";
|
||||
}
|
||||
|
||||
|
||||
@@ -140,25 +151,47 @@ void CDCore::k_update(PIIODevice * d) {
|
||||
k_ = uk;
|
||||
}
|
||||
|
||||
void CDCore::reinitConnection(const PIString &configuration) {
|
||||
PIString c = configuration;
|
||||
connection.stop();
|
||||
connection.removeAllDevices();
|
||||
connection.configureFromString(&c);
|
||||
connection.start();
|
||||
}
|
||||
|
||||
|
||||
void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
piCout << from << data.size();
|
||||
if (from == "cd") {
|
||||
// piCoutObj << "dataReceived" << from << data.size();
|
||||
PIIODevice * d = connection.deviceByName("cd");
|
||||
if (d && d == connection.deviceByFullPath(from)) {
|
||||
datatr.received(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CDCore::K_Send() {
|
||||
piCoutObj << "K_Send";
|
||||
PIString s;
|
||||
PIIOString ios(&s);
|
||||
k_write(&ios);
|
||||
PIByteArray ba;
|
||||
PIIOByteArray iob(&ba, PIIODevice::ReadWrite);
|
||||
// PIIOByteArray iob;
|
||||
// iob.open(&ba, PIIODevice::ReadWrite);
|
||||
k_write(&iob);
|
||||
piCoutObj << PIString(ba);
|
||||
if (sendt.isRunning()) {
|
||||
piCoutObj << "send in process...";
|
||||
return;
|
||||
}
|
||||
wheader.session_id = 0;
|
||||
wheader.type = CD_KSend;
|
||||
send_data.clear();
|
||||
send_data << wheader << ba;
|
||||
sendt.startOnce();
|
||||
// ios.close();
|
||||
piCout << s;
|
||||
// piCout << s;
|
||||
//PIByteArray ba = PIByteArray::fromString(s);
|
||||
PIFile pf("k.txt", PIIODevice::ReadWrite);
|
||||
pf.resize(0);
|
||||
pf.write(s.toUTF8());
|
||||
// PIFile pf("k.txt", PIIODevice::ReadWrite);
|
||||
// pf.resize(0);
|
||||
// pf.write(s.toUTF8());
|
||||
//k_write(&pf);
|
||||
//piCout << pf.readLine();
|
||||
}
|
||||
@@ -166,5 +199,62 @@ void CDCore::K_Send() {
|
||||
|
||||
void CDCore::K_Request() {
|
||||
piCoutObj << "K_Request";
|
||||
|
||||
if (sendt.isRunning()) {
|
||||
piCoutObj << "send in process...";
|
||||
return;
|
||||
}
|
||||
wheader.session_id = 0;
|
||||
wheader.type = CD_KQuery;
|
||||
send_data.clear();
|
||||
send_data << wheader;
|
||||
sendt.startOnce();
|
||||
}
|
||||
|
||||
|
||||
void CDCore::sendThread() {
|
||||
bool ok = datatr.send(send_data);
|
||||
CDPacketType pt = (CDPacketType)wheader.type;
|
||||
switch (pt) {
|
||||
case CD_KSend:
|
||||
if (ok) K_Sended();
|
||||
else K_SendFail();
|
||||
break;
|
||||
case CD_KQuery:
|
||||
if (!ok) K_ReceiveFail();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CDCore::dtSendRequest(PIByteArray &data) {
|
||||
connection.writeByName("cd", data);
|
||||
// piCoutObj << "send" << data.size() << ret;
|
||||
}
|
||||
|
||||
|
||||
void CDCore::dtReceiveFinished(bool ok) {
|
||||
if (ok) {
|
||||
PIByteArray ba = datatr.data();
|
||||
PacketHeader p;
|
||||
ba >> p;
|
||||
CDPacketType pt = (CDPacketType)p.type;
|
||||
switch (pt) {
|
||||
case CD_KQuery:
|
||||
K_Send();
|
||||
break;
|
||||
case CD_KSend: {
|
||||
piCoutObj << "K received";
|
||||
PIByteArray k;
|
||||
ba >> k;
|
||||
k << uchar(0);
|
||||
PIString s = PIString::fromUTF8((const char *)k.data());
|
||||
PIIOString ios(&s);
|
||||
k_read(&ios);
|
||||
K_Received();
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define CDUTILS_CORE_H
|
||||
|
||||
#include "cdutils_types.h"
|
||||
#include "cdutils_protocol.h"
|
||||
#include "piconnection.h"
|
||||
#include "pidatatransfer.h"
|
||||
|
||||
@@ -28,7 +29,9 @@ public:
|
||||
static CDCore * instance() {return __Core_Initializer__::__instance__;}
|
||||
|
||||
EVENT(K_Sended)
|
||||
EVENT(K_SendFail)
|
||||
EVENT(K_Received)
|
||||
EVENT(K_ReceiveFail)
|
||||
EVENT1(K_KeepNamesRequest, bool*, kn)
|
||||
EVENT_HANDLER(void, K_Send);
|
||||
EVENT_HANDLER(void, K_Request);
|
||||
@@ -39,16 +42,17 @@ public:
|
||||
void k_read(PIIODevice * d);
|
||||
void k_parse(PIIODevice * d);
|
||||
void k_update(PIIODevice * d);
|
||||
PIString pultConfig() {return PIString(pult_config);}
|
||||
PIString appConfig() {return PIString(app_config);}
|
||||
void reinitConnection(const PIString & configuration);
|
||||
bool inProgress() {return sendt.isRunning();}
|
||||
|
||||
private:
|
||||
CDCore(const char * conf =
|
||||
#ifdef CDPULT
|
||||
pult_config
|
||||
#else
|
||||
app_config
|
||||
#endif
|
||||
);
|
||||
CDCore();
|
||||
EVENT_HANDLER2(void, dataReceived, const PIString &, from, const PIByteArray &, data);
|
||||
EVENT_HANDLER1(void, dtSendRequest, PIByteArray &, data);
|
||||
EVENT_HANDLER1(void, dtReceiveFinished, bool, ok);
|
||||
EVENT_HANDLER(void, sendThread);
|
||||
void k_rec(const PIByteArray & data);
|
||||
void x_rec(const PIByteArray & data);
|
||||
void c_rec(const PIByteArray & data);
|
||||
@@ -56,7 +60,9 @@ private:
|
||||
static const char app_config[], pult_config[];
|
||||
PIConnection connection;
|
||||
PIDataTransfer datatr;
|
||||
|
||||
PacketHeader wheader;
|
||||
PIByteArray send_data;
|
||||
PIThread sendt;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,9 @@ KInterface::KInterface() {
|
||||
k_file = PIStringAscii("k.dat");
|
||||
k_file_size = 0;
|
||||
CONNECTU(core, K_Sended, this, sended);
|
||||
CONNECTU(core, K_SendFail, this, sendFailed);
|
||||
CONNECTU(core, K_Received, this, received);
|
||||
CONNECTU(core, K_ReceiveFail, this, receiveFailed);
|
||||
CONNECTU(core, K_KeepNamesRequest, this, keepNamesRequest);
|
||||
}
|
||||
|
||||
@@ -86,6 +88,11 @@ bool KInterface::configure(const PIString & config, const PIString & sect) {
|
||||
}
|
||||
|
||||
|
||||
void KInterface::reinitConnection(const PIString &configuration) {
|
||||
core->reinitConnection(configuration);
|
||||
}
|
||||
|
||||
|
||||
void KInterface::write(PIIODevice * d) {
|
||||
core->k_write(d);
|
||||
}
|
||||
@@ -106,6 +113,16 @@ void KInterface::update(PIIODevice * d) {
|
||||
}
|
||||
|
||||
|
||||
PIString KInterface::appConfig() {
|
||||
return core->appConfig();
|
||||
}
|
||||
|
||||
|
||||
PIString KInterface::pultConfig() {
|
||||
return core->pultConfig();
|
||||
}
|
||||
|
||||
|
||||
void KInterface::readFile() {
|
||||
if (k_file.isEmpty()) return;
|
||||
PIFile f(k_file, PIIODevice::ReadOnly);
|
||||
@@ -121,3 +138,8 @@ void KInterface::writeFile() {
|
||||
write(&f);
|
||||
k_file_size = f.size();
|
||||
}
|
||||
|
||||
|
||||
bool KInterface::inProgress() {
|
||||
return core->inProgress();
|
||||
}
|
||||
|
||||
@@ -30,18 +30,26 @@ public:
|
||||
int fileSize() const {return k_file_size;}
|
||||
|
||||
EVENT(sended)
|
||||
EVENT(sendFailed)
|
||||
EVENT(received)
|
||||
EVENT(receiveFailed)
|
||||
EVENT1(keepNamesRequest, bool*, kn)
|
||||
EVENT_HANDLER(void, send);
|
||||
EVENT_HANDLER(void, request);
|
||||
void setFileName(const PIString & file) {k_file = file;}
|
||||
bool configure(const PIString & config, const PIString & sect = PIStringAscii("k"));
|
||||
void reinitConnection(const PIString & configuration);
|
||||
void write(PIIODevice * d);
|
||||
void read(PIIODevice * d);
|
||||
void parse(PIIODevice * d);
|
||||
void update(PIIODevice * d);
|
||||
|
||||
PIString appConfig();
|
||||
PIString pultConfig();
|
||||
|
||||
void readFile();
|
||||
void writeFile();
|
||||
bool inProgress();
|
||||
|
||||
private:
|
||||
CDCore * core;
|
||||
|
||||
@@ -13,12 +13,12 @@ enum CDPacketType {CD_Ping, CD_Pong, CD_KQuery, CD_KSend, CD_Command, CD_XData,
|
||||
int type; // CDPacketType
|
||||
};
|
||||
|
||||
struct PacketKSend : PacketHeader {
|
||||
PIByteArray kdata; // file k.dat
|
||||
};
|
||||
|
||||
# pragma pack(pop)
|
||||
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PacketHeader & v) {s << v.session_id << v.type; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PacketHeader & v) {s >> v.session_id >> v.type; return s;}
|
||||
|
||||
}
|
||||
|
||||
#endif // CDUTILS_PROTOCOL_H
|
||||
|
||||
@@ -53,7 +53,8 @@ PIString CDType::type() const {
|
||||
|
||||
|
||||
PIString CDType::value() const {
|
||||
return PIString::fromBool(value_b);
|
||||
if (type_ == "b") return PIString::fromBool(value_b);
|
||||
return value_s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
CDSection() {}
|
||||
|
||||
bool test(int v) {return k.value(v).toBool();}
|
||||
// CDType & operator [](int v) {if (!k.contains(v)) k[v].index_ = v; return k[v];}
|
||||
CDType & operator [](int v) {return k[v];}
|
||||
const CDType operator [](int v) const {return k[v];}
|
||||
CDSection & section(int v) {return s[v];}
|
||||
|
||||
@@ -11,7 +11,8 @@ class Core : public PIObject
|
||||
public:
|
||||
Core() {
|
||||
// piCout << "testCore";
|
||||
|
||||
CONNECTU(&t, tickEvent, this, timerDone);
|
||||
t.start(1000);
|
||||
}
|
||||
|
||||
void load() {
|
||||
@@ -42,23 +43,24 @@ class Core : public PIObject
|
||||
}
|
||||
|
||||
void test() {
|
||||
piCoutObj << "count" << K.count();
|
||||
piCoutObj << "First" << (int)First << K[First];
|
||||
piCoutObj << "Second" << (int)Second << K[Second];
|
||||
piCoutObj << "test Second" << K.test(Second);
|
||||
piCout << "count" << K.count();
|
||||
piCout << K[First];
|
||||
piCout << K[Second];
|
||||
}
|
||||
|
||||
EVENT_HANDLER(void, ksend) {piCoutObj << "sended k";}
|
||||
EVENT_HANDLER(void, krecv) {piCoutObj << "received k";}
|
||||
EVENT_HANDLER(void, ksend) {piCout << "sended k";}
|
||||
EVENT_HANDLER(void, krecv) {piCout << "received k";}
|
||||
EVENT_HANDLER(void, timerDone) {test();}
|
||||
|
||||
private:
|
||||
PIFile rf;
|
||||
PITimer t;
|
||||
};
|
||||
|
||||
|
||||
#include "piscreen.h"
|
||||
#include "piscreentiles.h"
|
||||
//PIScreen screen;
|
||||
PIScreen screen(false);
|
||||
int main(int argc, char *argv[]) {
|
||||
// PIString s;
|
||||
// s = "df a)))(a(ttt){a(b(c)})d)e( d dws ) sds(()fads(fdas()))fda))))fdasf((((jhvw";
|
||||
@@ -80,7 +82,7 @@ int main(int argc, char *argv[]) {
|
||||
// ba = s.toByteArray();
|
||||
// piCout << PIString(ba);
|
||||
// piCout << PIString(ba.convertFromBase64());
|
||||
return 0;
|
||||
// return 0;
|
||||
// int i = 0;
|
||||
// piCout << i++ << "!" << s << "!";
|
||||
// piCout << i << "!" << s.trimmed() << "!";
|
||||
@@ -158,18 +160,18 @@ int main(int argc, char *argv[]) {
|
||||
//CDUtils::Core::instance()->test();
|
||||
//return 0;
|
||||
// piCout << "init";
|
||||
// screen.rootTile()->addTile(new TilePICout());
|
||||
// screen.enableExitCapture('q');
|
||||
// screen.start();
|
||||
screen.rootTile()->addTile(new TilePICout());
|
||||
screen.enableExitCapture('q');
|
||||
// piMSleep(3000);
|
||||
screen.start();
|
||||
piCout << "start";
|
||||
Core core;
|
||||
core.load();
|
||||
core.test();
|
||||
core.save();
|
||||
K.send();
|
||||
// core.save();
|
||||
// K.send();
|
||||
|
||||
|
||||
// screen.waitForFinish();
|
||||
screen.waitForFinish();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ endif()
|
||||
find_package(Qt4 REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PIP_INCLUDES} ${QT_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}/../)
|
||||
add_definitions(-DCDPULT)
|
||||
file(GLOB CPPS "*.cpp")
|
||||
file(GLOB MOCS "*.h")
|
||||
file(GLOB UIS "*.ui")
|
||||
|
||||
@@ -56,6 +56,10 @@ config(piqt(config_), QIODevice::ReadWrite) {
|
||||
ui->treeCDK->setModel(kmodel);
|
||||
delegate = new CDKDelegate();
|
||||
ui->treeCDK->setItemDelegateForColumn(4, delegate);
|
||||
CONNECTU(&K, sended, this, pip_sendSucceed);
|
||||
CONNECTU(&K, sendFailed, this, pip_sendFailed);
|
||||
CONNECTU(&K, received, this, pip_receiveSucceed);
|
||||
CONNECTU(&K, receiveFailed, this, pip_receiveFailed);
|
||||
connect(this, SIGNAL(q_k_sendFailed()), this, SLOT(k_sendFailed()), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(q_k_sendSucceed()), this, SLOT(k_sendSucceed()), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(q_k_receiveFailed()), this, SLOT(k_receiveFailed()), Qt::QueuedConnection);
|
||||
@@ -68,6 +72,7 @@ config(piqt(config_), QIODevice::ReadWrite) {
|
||||
connect(ui->lineKSearch, SIGNAL(textChanged(QString)), this, SLOT(filterTree()));
|
||||
session.load();
|
||||
on_spinBuffer_editingFinished();
|
||||
K.reinitConnection(K.pultConfig());
|
||||
K.configure(config_);
|
||||
K.readFile();
|
||||
updateKDesc();
|
||||
@@ -234,11 +239,6 @@ void CD_Pult::makeTreeSection(CDSection & ks, QTreeWidgetItem * pi) {
|
||||
}
|
||||
|
||||
|
||||
void CD_Pult::received(bool ok) {
|
||||
if (!ok) return;
|
||||
}
|
||||
|
||||
|
||||
void CD_Pult::on_treeK_itemClicked(QTreeWidgetItem * item, int column) {
|
||||
Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
if (column == 2) f |= Qt::ItemIsEditable;
|
||||
@@ -256,7 +256,8 @@ void CD_Pult::on_treeK_itemChanged(QTreeWidgetItem * item, int column) {
|
||||
|
||||
|
||||
void CD_Pult::on_buttonSendK_clicked() {
|
||||
on_buttonWrite_clicked();
|
||||
// on_buttonWrite_clicked();
|
||||
K.send();
|
||||
//coeffs.sendCoeffs();
|
||||
if (timer != 0) killTimer(timer);
|
||||
timer = startTimer(100);
|
||||
@@ -264,6 +265,8 @@ void CD_Pult::on_buttonSendK_clicked() {
|
||||
|
||||
|
||||
void CD_Pult::on_buttonReceiveK_clicked() {
|
||||
K.request();
|
||||
// K.se
|
||||
//coeffs.receiveCoeffs();
|
||||
if (timer != 0) killTimer(timer);
|
||||
timer = startTimer(100);
|
||||
@@ -319,30 +322,27 @@ void CD_Pult::on_buttonSetCDesc_clicked() {
|
||||
|
||||
|
||||
void CD_Pult::k_sendFailed() {
|
||||
stopWait();
|
||||
addToList(trUtf8("K not sended"), Qt::darkRed);
|
||||
if (timer != 0) killTimer(timer);
|
||||
}
|
||||
|
||||
|
||||
void CD_Pult::k_sendSucceed() {
|
||||
stopWait();
|
||||
addToList(trUtf8("K sended"), Qt::darkGreen);
|
||||
addToList(trUtf8("K sended"), Qt::darkGreen);;
|
||||
if (timer != 0) killTimer(timer);
|
||||
}
|
||||
|
||||
|
||||
void CD_Pult::k_receiveFailed() {
|
||||
stopWait();
|
||||
addToList(trUtf8("K not received"), Qt::darkRed);
|
||||
if (timer != 0) killTimer(timer);
|
||||
}
|
||||
|
||||
|
||||
void CD_Pult::k_receiveSucceed() {
|
||||
stopWait();
|
||||
addToList(trUtf8("K received"), Qt::darkGreen);
|
||||
//addToList(trUtf8("Write K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(coeffs.fileName())).arg(K.size_s()).arg(coeffs.k_content.size_s()), Qt::darkMagenta);
|
||||
//ui->spinSize->setValue(K.size_s());
|
||||
if (timer != 0) killTimer(timer);
|
||||
updateTree();
|
||||
//ui->table->setK(coeffsK.k()->data(), coeffsK.count());
|
||||
}
|
||||
|
||||
|
||||
@@ -351,13 +351,6 @@ void CD_Pult::on_spinBuffer_editingFinished() {
|
||||
}
|
||||
|
||||
|
||||
void CD_Pult::stopWait() {
|
||||
killTimer(timer);
|
||||
timer = 0;
|
||||
ui->labelWait->setText(" ");
|
||||
}
|
||||
|
||||
|
||||
void CD_Pult::updateGraph() {
|
||||
ui->graphic->updateGraphics();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "piqt.h"
|
||||
#include "session_manager.h"
|
||||
#include "qpievaluator.h"
|
||||
#include "cdutils_core.h"
|
||||
#include "cdutils_k.h"
|
||||
#include "cd_kmodel.h"
|
||||
|
||||
@@ -52,7 +53,6 @@ private:
|
||||
QString typeName(const QString & n) const;
|
||||
void makeTreeSection(CDUtils::CDSection & ks, QTreeWidgetItem * pi);
|
||||
|
||||
EVENT_HANDLER1(void, received, bool, ok);
|
||||
EVENT_HANDLER(void, pip_sendFailed) {emit q_k_sendFailed();}
|
||||
EVENT_HANDLER(void, pip_sendSucceed) {emit q_k_sendSucceed();}
|
||||
EVENT_HANDLER(void, pip_receiveFailed) {emit q_k_receiveFailed();}
|
||||
|
||||
112
cd_utils/pult/cdkview.cpp
Normal file
112
cd_utils/pult/cdkview.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
#include <QDir>
|
||||
#include "cdutils_k.h"
|
||||
#include "cdkview.h"
|
||||
#include "cd_kmodel.h"
|
||||
#include "piqt.h"
|
||||
#include "pifile.h"
|
||||
|
||||
using namespace CDUtils;
|
||||
|
||||
|
||||
CDKView::CDKView(QWidget *parent) : QTreeView(parent) {
|
||||
kmodel = 0;
|
||||
CONNECTU(&K, sended, this, cdk_sendSucceed);
|
||||
CONNECTU(&K, sendFailed, this, cdk_sendFailed);
|
||||
CONNECTU(&K, received, this, cdk_receiveSucceed);
|
||||
CONNECTU(&K, receiveFailed, this, cdk_receiveFailed);
|
||||
connect(this, SIGNAL(_qcdk_sendFailed()), this, SLOT(k_sendFailed()), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(_qcdk_sendSucceed()), this, SLOT(k_sendSucceed()), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(_qcdk_receiveFailed()), this, SLOT(k_receiveFailed()), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(_qcdk_receiveSucceed()), this, SLOT(k_receiveSucceed()), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
|
||||
CDKView::~CDKView() {
|
||||
delete kmodel;
|
||||
}
|
||||
|
||||
|
||||
void CDKView::refresh() {
|
||||
if (!kmodel) {
|
||||
K.reinitConnection(K.pultConfig());
|
||||
kmodel = new CDKItemModel();
|
||||
setModel(kmodel);
|
||||
setItemDelegateForColumn(4, new CDKDelegate());
|
||||
}
|
||||
kmodel->rebuildModel();
|
||||
expandAll();
|
||||
for (int i=0; i<6; i++) resizeColumnToContents(i);
|
||||
}
|
||||
|
||||
|
||||
void CDKView::setKFile(const QString &filename) {
|
||||
K.setFileName(Q2PIString(filename));
|
||||
}
|
||||
|
||||
|
||||
void CDKView::sendK() {
|
||||
bisyStatusChanged(true);
|
||||
K.send();
|
||||
}
|
||||
|
||||
|
||||
void CDKView::receiveK() {
|
||||
bisyStatusChanged(true);
|
||||
K.request();
|
||||
}
|
||||
|
||||
|
||||
void CDKView::saveK() {
|
||||
K.writeFile();
|
||||
}
|
||||
|
||||
|
||||
void CDKView::loadK() {
|
||||
K.readFile();
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
void CDKView::clearK() {
|
||||
K.root() = CDSection();
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
void CDKView::buildFromHeader(const QString &kdescription) {
|
||||
if (kdescription.isEmpty()) return;
|
||||
PIString kdesc_file = Q2PIString(QDir::current().relativeFilePath(kdescription));
|
||||
PIFile f(kdesc_file, PIIODevice::ReadOnly);
|
||||
K.update(&f);
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
void CDKView::k_sendFailed() {
|
||||
bisyStatusChanged(false);
|
||||
emit messageStatus("send failed");
|
||||
emit KSendFailed();
|
||||
}
|
||||
|
||||
|
||||
void CDKView::k_sendSucceed() {
|
||||
bisyStatusChanged(false);
|
||||
emit messageStatus("send success");
|
||||
emit KSendSucceed();
|
||||
}
|
||||
|
||||
|
||||
void CDKView::k_receiveFailed() {
|
||||
bisyStatusChanged(false);
|
||||
emit messageStatus("receive failed");
|
||||
emit KReceiveFailed();
|
||||
}
|
||||
|
||||
|
||||
void CDKView::k_receiveSucceed() {
|
||||
bisyStatusChanged(false);
|
||||
emit messageStatus("receive success");
|
||||
refresh();
|
||||
emit KReceiveSucceed();
|
||||
}
|
||||
|
||||
58
cd_utils/pult/cdkview.h
Normal file
58
cd_utils/pult/cdkview.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef CDKVIEW_H
|
||||
#define CDKVIEW_H
|
||||
|
||||
#include "piobject.h"
|
||||
#include <QTreeView>
|
||||
|
||||
class CDKItemModel;
|
||||
|
||||
class CDKView : public QTreeView, public PIObject
|
||||
{
|
||||
Q_OBJECT
|
||||
PIOBJECT(CDKView)
|
||||
public:
|
||||
explicit CDKView(QWidget *parent = 0);
|
||||
~CDKView();
|
||||
void refresh();
|
||||
void setKFile(const QString & filename);
|
||||
|
||||
CDKItemModel * CDKModel() {return kmodel;}
|
||||
|
||||
public slots:
|
||||
void sendK();
|
||||
void receiveK();
|
||||
void saveK();
|
||||
void loadK();
|
||||
void clearK();
|
||||
void buildFromHeader(const QString & kdescription);
|
||||
|
||||
private slots:
|
||||
void k_sendFailed();
|
||||
void k_sendSucceed();
|
||||
void k_receiveFailed();
|
||||
void k_receiveSucceed();
|
||||
|
||||
private:
|
||||
EVENT_HANDLER(void, cdk_sendFailed) {emit _qcdk_sendFailed();}
|
||||
EVENT_HANDLER(void, cdk_sendSucceed) {emit _qcdk_sendSucceed();}
|
||||
EVENT_HANDLER(void, cdk_receiveFailed) {emit _qcdk_receiveFailed();}
|
||||
EVENT_HANDLER(void, cdk_receiveSucceed) {emit _qcdk_receiveSucceed();}
|
||||
|
||||
CDKItemModel * kmodel;
|
||||
|
||||
signals:
|
||||
void KSendFailed();
|
||||
void KSendSucceed();
|
||||
void KReceiveFailed();
|
||||
void KReceiveSucceed();
|
||||
void messageStatus(QString msg);
|
||||
void bisyStatusChanged(bool bisy);
|
||||
|
||||
void _qcdk_sendFailed(); // PRIVATE
|
||||
void _qcdk_sendSucceed(); // PRIVATE
|
||||
void _qcdk_receiveFailed(); // PRIVATE
|
||||
void _qcdk_receiveSucceed(); // PRIVATE
|
||||
|
||||
};
|
||||
|
||||
#endif // CDKVIEW_H
|
||||
33
cd_utils/pult/form.cpp
Normal file
33
cd_utils/pult/form.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "form.h"
|
||||
#include "ui_form.h"
|
||||
#include "QFileDialog"
|
||||
|
||||
Form::Form(QWidget *parent) : QWidget(parent), ui(new Ui::Form) {
|
||||
ui->setupUi(this);
|
||||
ui->treeView->setKFile("");
|
||||
ui->treeView->refresh();
|
||||
}
|
||||
|
||||
|
||||
Form::~Form() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void Form::on_pushButton_3_clicked() {
|
||||
ui->treeView->setKFile(QFileDialog::getSaveFileName(this, "Save"));
|
||||
ui->treeView->saveK();
|
||||
ui->treeView->setKFile("");
|
||||
}
|
||||
|
||||
|
||||
void Form::on_pushButton_4_clicked() {
|
||||
ui->treeView->setKFile(QFileDialog::getOpenFileName(this, "Open"));
|
||||
ui->treeView->loadK();
|
||||
ui->treeView->setKFile("");
|
||||
}
|
||||
|
||||
|
||||
void Form::on_pushButton_6_clicked() {
|
||||
ui->treeView->buildFromHeader(QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with K description"), "k_description.h", "C/C++ header files(*.h *.hpp);;All files(*)"));
|
||||
}
|
||||
29
cd_utils/pult/form.h
Normal file
29
cd_utils/pult/form.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef FORM_H
|
||||
#define FORM_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class Form;
|
||||
}
|
||||
|
||||
class Form : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Form(QWidget *parent = 0);
|
||||
~Form();
|
||||
|
||||
private slots:
|
||||
void on_pushButton_3_clicked();
|
||||
|
||||
void on_pushButton_4_clicked();
|
||||
|
||||
void on_pushButton_6_clicked();
|
||||
|
||||
private:
|
||||
Ui::Form *ui;
|
||||
};
|
||||
|
||||
#endif // FORM_H
|
||||
163
cd_utils/pult/form.ui
Normal file
163
cd_utils/pult/form.ui
Normal file
@@ -0,0 +1,163 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>581</width>
|
||||
<height>432</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="CDKView" name="treeView"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Send</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
<string>Receive</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="pushButton_4">
|
||||
<property name="text">
|
||||
<string>Load</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="pushButton_5">
|
||||
<property name="text">
|
||||
<string>Clear</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="pushButton_6">
|
||||
<property name="text">
|
||||
<string>update from KDescription</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>CDKView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header location="global">cdkview.h</header>
|
||||
<slots>
|
||||
<signal>bisyStatusChanged(bool)</signal>
|
||||
<slot>sendK()</slot>
|
||||
<slot>receiveK()</slot>
|
||||
<slot>saveK()</slot>
|
||||
<slot>loadK()</slot>
|
||||
<slot>clear()</slot>
|
||||
<slot>clearK()</slot>
|
||||
</slots>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>pushButton_2</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>treeView</receiver>
|
||||
<slot>receiveK()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>569</x>
|
||||
<y>69</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>410</x>
|
||||
<y>152</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>treeView</sender>
|
||||
<signal>bisyStatusChanged(bool)</signal>
|
||||
<receiver>pushButton_2</receiver>
|
||||
<slot>setDisabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>309</x>
|
||||
<y>174</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>569</x>
|
||||
<y>66</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>pushButton_5</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>treeView</receiver>
|
||||
<slot>clearK()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>463</x>
|
||||
<y>104</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>468</x>
|
||||
<y>188</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>pushButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>treeView</receiver>
|
||||
<slot>sendK()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>190</x>
|
||||
<y>65</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>198</x>
|
||||
<y>152</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>treeView</sender>
|
||||
<signal>bisyStatusChanged(bool)</signal>
|
||||
<receiver>pushButton</receiver>
|
||||
<slot>setDisabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>177</x>
|
||||
<y>246</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>98</x>
|
||||
<y>46</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <QtGui/QApplication>
|
||||
#include "cd_pult.h"
|
||||
#include "form.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
CD_Pult w;
|
||||
Form w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user