TransformChain TransformsGui::getCurrentTransformChain() { // this->setEnabled(false); TransformChain list; for (int i = 0; i < transformWidgetList.size() - 1; i++) { if (transformWidgetList.at(i)->getTransform() != 0 ) list.append(transformWidgetList.at(i)->getTransform()); } list.setName(name); // this->setEnabled(true); return list; }
void GenericTabStateObj::run() { GenericTab * gTab = dynamic_cast<GenericTab *> (tab); TabStateObj::run(); if (flags & GuiConst::STATE_SAVE_REQUEST) { writer->writeAttribute(GuiConst::STATE_SEARCH_WIDGET, write(gTab->getSearchWidget()->text(),true)); writer->writeAttribute(GuiConst::STATE_GOTOOFFSET_WIDGET, write(gTab->getGotoWidget()->text())); writer->writeAttribute(GuiConst::STATE_MESSAGE_PANEL, write(gTab->getMessagePanel()->toHTML(),true)); writer->writeAttribute(GuiConst::STATE_MESSAGE_PANEL_VISIBLE, write(gTab->getMessagePanel()->isVisible())); writer->writeAttribute(GuiConst::STATE_SCROLL_INDEX, write(gTab->hexView->getHexTableView()->verticalScrollBar()->value())); writer->writeAttribute(GuiConst::STATE_CURRENT_INDEX, write(gTab->ui->tabWidget->currentIndex())); QList<GenericTab::ViewTab> tabs = gTab->tabData; int size = tabs.size(); writer->writeStartElement(GuiConst::STATE_TABVIEWLIST); writer->writeAttribute(GuiConst::STATE_SIZE, write(tabs.size())); for (int i = 0; i < size ; i++) { writer->writeStartElement(GuiConst::STATE_TABVIEW); writer->writeAttribute(GuiConst::STATE_TYPE, write((int)tabs.at(i).type)); // saving configuration QString conf; TransformChain list; if (tabs.at(i).transform != nullptr) { list.append(tabs.at(i).transform); } list.setName(tabs.at(i).tabName); QXmlStreamWriter streamin(&conf); tab->getHelper()->getTransformFactory()->saveConfToXML(list, &streamin); writer->writeAttribute(GuiConst::STATE_CONF, write(conf)); writer->writeEndElement(); list.clear(); // the transforms are not own by us, don't delete them } writer->writeEndElement(); // STATE_TABVIEWLIST } else { QXmlStreamAttributes attrList = reader->attributes(); if (attrList.hasAttribute(GuiConst::STATE_SEARCH_WIDGET)) { gTab->getSearchWidget()->setText(readString(attrList.value(GuiConst::STATE_SEARCH_WIDGET))); } if (attrList.hasAttribute(GuiConst::STATE_GOTOOFFSET_WIDGET)) { gTab->getGotoWidget()->setText(readString(attrList.value(GuiConst::STATE_GOTOOFFSET_WIDGET))); } if (attrList.hasAttribute(GuiConst::STATE_MESSAGE_PANEL)) { gTab->getMessagePanel()->setHTML(readString(attrList.value(GuiConst::STATE_MESSAGE_PANEL))); } if (attrList.hasAttribute(GuiConst::STATE_MESSAGE_PANEL_VISIBLE)) { gTab->getMessagePanel()->setVisible(readBool(attrList.value(GuiConst::STATE_MESSAGE_PANEL_VISIBLE))); } bool ok = false; int index = -1; GenericTabClosingStateObj *tempState = nullptr; if (attrList.hasAttribute(GuiConst::STATE_SCROLL_INDEX)) { index = readInt(attrList.value(GuiConst::STATE_SCROLL_INDEX), &ok); if (ok) { tempState = new(std::nothrow) GenericTabClosingStateObj(gTab); if (tempState == nullptr) { qFatal("Cannot allocate memory for GenericTabClosingStateObj X{"); } tempState->setScrollIndex(index); } } if (attrList.hasAttribute(GuiConst::STATE_CURRENT_INDEX)) { index = readInt(attrList.value(GuiConst::STATE_CURRENT_INDEX), &ok); if (ok) { if (tempState == nullptr) { tempState = new(std::nothrow) GenericTabClosingStateObj(gTab); if (tempState == nullptr) { qFatal("Cannot allocate memory for GenericTabClosingStateObj X{"); } } tempState->setCurrentIndex(index); } } if (tempState != nullptr) emit addNewState(tempState); // restoring view tabs if (readNextStart(GuiConst::STATE_TABVIEWLIST)) { attrList = reader->attributes(); if (attrList.hasAttribute(GuiConst::STATE_SIZE)) { ok = false; int size = readInt(attrList.value(GuiConst::STATE_SIZE),&ok); if (ok) { for (int i = 0; i < size ; i++) { GenericTab::ViewTab vt; vt.transform = nullptr; // just initialising in case of screw up if (readNextStart(GuiConst::STATE_TABVIEW)) { attrList = reader->attributes(); readEndElement(GuiConst::STATE_TABVIEW); // closing now, because there is no child defined anyway if (attrList.hasAttribute(GuiConst::STATE_TYPE)) { int type = readInt(attrList.value(GuiConst::STATE_TYPE),&ok); if (ok && (type == 0 || type == 1 || type == 2 || type == 3)) { vt.type = (GenericTab::ViewType) type; } else { qWarning() << "Invalid state type for this view, skipping"; continue; } } else { qWarning() << "no state type for this view, skipping"; continue; } if (vt.type != GenericTab::DEFAULTTEXT) { if (attrList.hasAttribute(GuiConst::STATE_CONF)) { QString conf = readString(attrList.value(GuiConst::STATE_CONF)); if (!conf.isEmpty()) { TransformChain list = tab->getHelper()->getTransformFactory()->loadConfFromXML(conf); if (!list.isEmpty()) { vt.transform = list.at(0); vt.tabName = list.getName(); } else { qWarning() << "Resulting transform list empty for this view, skipping"; continue; } } else { qWarning() << "Empty conf for this view, skipping"; continue; } } else { qWarning() << "no conf for this view, skipping"; continue; } } else { vt.tabName = GenericTab::TEXT_TEXT; } gTab->addViewTab(vt); // no deleting vt.transform here, the pointer is now owned by the tab. } } } else { qCritical() << "Size value is not a number, giving up"; } } else { qCritical() << "No size value for the view size, giving up"; } } readEndElement(GuiConst::STATE_TABVIEWLIST); } BaseStateAbstract *state = gTab->getSource(0)->getStateMngtObj(); emit addNewState(state); }