diff --git a/cd_utils/cdutils_types.cpp b/cd_utils/cdutils_types.cpp index 050f0c4..1f60a51 100644 --- a/cd_utils/cdutils_types.cpp +++ b/cd_utils/cdutils_types.cpp @@ -18,7 +18,7 @@ CDType::CDType() { cd_type_ = cdNull; parent = 0; avg_size = 1; - mode_ = X_Current; + mode_ = rmode_ = X_Current; // debug_cnt = cdtype_debug_cnt; // cdtype_debug_cnt++; // piCout << "[CDType]" << "create Null" << debug_cnt; @@ -41,7 +41,7 @@ CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v calculated = x_enabled = false; parent = 0; avg_size = 1; - mode_ = X_Current; + mode_ = rmode_ = X_Current; if (type_ == "e") { enum_values = parseEnumComment(comment_); // piCout << enum_values.size() << enum_values; @@ -122,7 +122,8 @@ PIStringList CDType::pathString() const { void CDType::readX(PIByteArray & ba) { if (ba.size() < 5) return; uchar t(0); ba >> t; - switch ((XMode)t) { + rmode_ = (XMode)t; + switch (rmode_) { case X_Current: ba >> value_d; break; diff --git a/cd_utils/cdutils_types.h b/cd_utils/cdutils_types.h index a1997a2..cc37044 100644 --- a/cd_utils/cdutils_types.h +++ b/cd_utils/cdutils_types.h @@ -59,6 +59,7 @@ public: void setXMode(XMode mode) {mode_ = mode;} void setAvg(int avg) {avg_size = avg;} XMode xmode() const {return mode_;} + XMode xmode_rec() const {return rmode_;} int avg() const {return avg_size;} bool isSelectedX() const {return x_enabled;} void readX(PIByteArray & ba); @@ -81,7 +82,7 @@ protected: bool value_b, calculated, x_enabled; PIVector avg_h; int avg_size; - XMode mode_; + XMode mode_, rmode_; }; diff --git a/cd_utils/cdutils_x.cpp b/cd_utils/cdutils_x.cpp index 8d87e0f..03d063c 100644 --- a/cd_utils/cdutils_x.cpp +++ b/cd_utils/cdutils_x.cpp @@ -44,6 +44,11 @@ PIVector > XInterface::enabledList() const { } +void XInterface::setEnabledList(const PIVector > & l) { + CDCore::instance()->x_selected = l; +} + + void XInterface::lock() { CDCore::instance()->x_mutex.lock(); } diff --git a/cd_utils/cdutils_x.h b/cd_utils/cdutils_x.h index b501d16..cff188a 100644 --- a/cd_utils/cdutils_x.h +++ b/cd_utils/cdutils_x.h @@ -27,6 +27,7 @@ public: void setEnabled(const CDType & x, bool en); void setDisabled(const CDType & x, bool dis) {setEnabled(x, !dis);} PIVector > enabledList() const; + void setEnabledList(const PIVector > & l); void lock(); void unlock(); diff --git a/qcd_utils/pult/cdgraphics.cpp b/qcd_utils/pult/cdgraphics.cpp index fe93f85..6dccc54 100644 --- a/qcd_utils/pult/cdgraphics.cpp +++ b/qcd_utils/pult/cdgraphics.cpp @@ -16,6 +16,24 @@ using namespace CDUtils; +QStringList CDUtils::getList(const PIVector > & x_list) { + QStringList ret; + piForeachC (PIDeque & p, x_list) + ret << PI2QString(CDCore::pathToString(p)); + return ret; +} + + +PIVector > CDUtils::setList(const QStringList & l) { + PIVector > ret; + foreach (QString s, l) + ret << CDCore::stringToPath(Q2PIString(s)); + return ret; +} + + + + GDockWidget::GDockWidget(QString title, QMainWindow * p): QDockWidget(title, p) { da = p; menu = new QMenu(this); @@ -56,6 +74,33 @@ void GDockWidget::drawX(const PIMap > & data) { } +QByteArray GDockWidget::save() const { + ChunkStream cs; + cs.add(1, windowTitle()) + .add(2, getList(x_list)) + .add(3, graphic->graphic->save()) + .add(4, graphic->evalHistory->expression()) + .add(5, graphic->evalVisible->expression()); + return cs.data(); +} + + +void GDockWidget::load(QByteArray ba) { + if (ba.isEmpty()) return; + ChunkStream cs(ba); + while (!cs.atEnd()) { + switch (cs.read()) { + case 1: setWindowTitle(cs.getData()); break; + case 2: x_list = setList(cs.getData()); break; + case 3: graphic->graphic->load(cs.getData()); break; + case 4: graphic->evalHistory->setExpression(cs.getData()); break; + case 5: graphic->evalVisible->setExpression(cs.getData()); break; + default: break; + } + } +} + + bool GDockWidget::eventFilter(QObject * o, QEvent * e) { //if (o == graphic->viewport()) { switch (e->type()) { @@ -151,6 +196,52 @@ CDGraphics::~CDGraphics() { void CDGraphics::reset() { + qDeleteAll(docks); + docks.clear(); +} + + +QByteArray CDGraphics::save() const { + ChunkStream cs; + QVector dstates; + foreach (GDockWidget * d, docks) { + dstates << d->save(); + } + cs.add(1, docks.size()) + .add(2, dstates) + .add(3, da->saveState()); + X.lock(); + cs.add(4, getList(X.enabledList())); + X.unlock(); + return cs.data(); +} + + +void CDGraphics::load(QByteArray ba) { + reset(); + if (ba.isEmpty()) return; + ChunkStream cs(ba); + while (!cs.atEnd()) { + switch (cs.read()) { + case 1: { + int s = cs.getData(); + piForTimes (s) + addGraphic(); + } break; + case 2: { + QVector dstates = cs.getData >(); + for (int i = 0; i < piMini(dstates.size(), docks.size()); ++i) + docks[i]->load(dstates[i]); + } break; + case 3: da->restoreState(cs.getData()); break; + case 4: + X.lock(); + X.setEnabledList(setList(cs.getData())); + X.unlock(); + break; + default: break; + } + } } @@ -168,6 +259,8 @@ void CDGraphics::addGraphic() { connect(dw, SIGNAL(removeRequest()), this, SLOT(removeGraphic())); da->addDockWidget(Qt::RightDockWidgetArea, dw); docks << dw; + for (int i = 0; i < docks.size(); ++i) + docks[i]->setObjectName(QString("dock_%1").arg(i)); } @@ -178,13 +271,14 @@ void CDGraphics::receivedX() { PIVector ch; piForeachC (PIDeque & p, x_list) { CDType & t(X[p]); - if (t.xmode() == CDType::X_Current) - ch.resize(1, t.toDouble()); + if (t.xmode_rec() == CDType::X_Current) + ch.resize(1).fill(t.toDouble()); else ch = t.history; t.history.clear(); data[CDCore::pathToString(t.path())] = ch; } + //piCout << data; X.unlock(); foreach (GDockWidget * d, docks) d->drawX(data); @@ -196,6 +290,8 @@ void CDGraphics::removeGraphic() { if (!d) return; docks.removeAll(d); d->deleteLater(); + for (int i = 0; i < docks.size(); ++i) + docks[i]->setObjectName(QString("dock_%1").arg(i)); } diff --git a/qcd_utils/pult/cdgraphics.h b/qcd_utils/pult/cdgraphics.h index c0dbdaf..0d4ff6a 100644 --- a/qcd_utils/pult/cdgraphics.h +++ b/qcd_utils/pult/cdgraphics.h @@ -11,6 +11,8 @@ namespace CDUtils { class CDType; class CDSection; + QStringList getList(const PIVector > & x_list); + PIVector > setList(const QStringList & l); } class QMainWindow; @@ -26,6 +28,8 @@ public: void addX(const CDUtils::CDType & t); void drawX(const PIMap > & data); + QByteArray save() const; + void load(QByteArray ba); CDGraphicWidget * graphic; @@ -59,6 +63,8 @@ public: ~CDGraphics(); void reset(); + QByteArray save() const; + void load(QByteArray ba); private: GDockWidget * graphicDock(Graphic * o) const; diff --git a/qcd_utils/pult/cdpultwindow.cpp b/qcd_utils/pult/cdpultwindow.cpp index 5360013..baa0a9e 100644 --- a/qcd_utils/pult/cdpultwindow.cpp +++ b/qcd_utils/pult/cdpultwindow.cpp @@ -1,7 +1,8 @@ #include "edockwidget.h" #include "cdpultwindow.h" -#include "cdutils_k.h" #include "cdutils_core.h" +#include "cdutils_k.h" +#include "cdutils_x.h" #include "qcd_core.h" #include "qcd_view.h" #include "qcd_model.h" @@ -79,6 +80,7 @@ bool CDPultWindow::load(const QString & path) { checkHasK->setChecked(conf.getValue("has_k")); checkHasX->setChecked(conf.getValue("has_x")); checkHasC->setChecked(conf.getValue("has_c")); + session_gr = conf.getValue("session_gr", QByteArray()); setChanged(false); file_name = path; return true; @@ -86,6 +88,7 @@ bool CDPultWindow::load(const QString & path) { bool CDPultWindow::save(const QString & path) { + session_gr = widgetGraphics->save(); QPIConfig conf(path, QIODevice::ReadWrite); conf.clear(); conf.setValue("file_k", editFileK->value().value().file); @@ -96,6 +99,7 @@ bool CDPultWindow::save(const QString & path) { conf.setValue("has_k", checkHasK->isChecked()); conf.setValue("has_x", checkHasX->isChecked()); conf.setValue("has_c", checkHasC->isChecked()); + conf.setValue("session_gr", session_gr); file_name = path; return true; @@ -156,6 +160,7 @@ void CDPultWindow::on_editFileK_valueChanged(const QVariant & p) { void CDPultWindow::on_buttonSessionApply_clicked() { + // with session or not widgetK->setFile(editFileK->value().value().file); widgetX->setFile(editFileX->value().value().file); widgetC->setFile(editFileC->value().value().file); @@ -163,6 +168,14 @@ void CDPultWindow::on_buttonSessionApply_clicked() { dockCDXView->setVisible(checkHasX->isChecked()); dockCDCView->setVisible(checkHasC->isChecked()); widgetX->view->startX(); + widgetGraphics->load(session_gr); + X.lock(); + PIVector > x_list = X.enabledList(); + X.unlock(); + piForeachC (PIDeque & p, x_list) + X.enable(X[p]); + ((CDItemModel*)widgetX->view->model())->updateModel(); + widgetX->view->expandAll(); } diff --git a/qcd_utils/pult/cdpultwindow.h b/qcd_utils/pult/cdpultwindow.h index 69850ab..2345f06 100644 --- a/qcd_utils/pult/cdpultwindow.h +++ b/qcd_utils/pult/cdpultwindow.h @@ -31,6 +31,7 @@ private: Ribbon * ribbon; QMap log_icons; + QByteArray session_gr; private slots: void addToLog(CDViewWidget::LogIcon icon, const QString & msg); diff --git a/qcd_utils/qcd_view.cpp b/qcd_utils/qcd_view.cpp index 6a06422..b24ef70 100644 --- a/qcd_utils/qcd_view.cpp +++ b/qcd_utils/qcd_view.cpp @@ -300,6 +300,7 @@ void CDView::cd_receivedX() { //piCout << t.path(); if (t.cd_type() != CDType::cdX) continue; update(model_->indexByPath(t.path(), cValue)); + //piCout << CDCore::pathToString(t.path()) << t.toDouble() << "model"; //qDebug() << "val" << model_->data(model_->indexByPath(t.path(), cValue), Qt::DisplayRole).toDouble(); } X.unlock();