void TransformsGui::onLoadState() { MessageDialog errorDialog(guiHelper); connect(transformFactory, SIGNAL(error(QString,QString)), &errorDialog, SLOT(logError(QString))); QString fileName = QFileDialog::getOpenFileName(this,tr("Choose state file to load from"),"",tr("XML documents (*.xml);; All (*)")); if (fileName.isEmpty()) return; TransformChain talist = transformFactory->loadConfFromFile(fileName); if (talist.isEmpty()) QMessageBox::critical(this,tr("Error"),tr("The loaded chain is empty. Check the logs."),QMessageBox::Ok); else { if (errorDialog.hasMessages()) { errorDialog.setWindowTitle(tr("Error(s) while loading the state file")); if (errorDialog.exec() == QDialog::Rejected) { while (!talist.isEmpty()) delete talist.takeLast(); return; } } else { logger->logStatus(tr("File %1 loaded").arg(fileName)); } setCurrentTransformChain(talist); // not really efficient QString conf; QXmlStreamWriter writer(&conf); transformFactory->saveConfToXML(talist, &writer); emit chainChanged(conf); } }
void TransformsGui::setCurrentChainConf(const QString &conf) { if (conf.isEmpty()) return; MessageDialog errorDialog(guiHelper); connect(transformFactory, SIGNAL(error(QString,QString)), &errorDialog, SLOT(logError(QString))); QXmlStreamReader reader(conf); TransformChain talist = transformFactory->loadConfFromXML(&reader); if (talist.isEmpty()) QMessageBox::critical(this,tr("Error"),tr("The loaded chain is empty. Check the logs."),QMessageBox::Ok); else { if (errorDialog.hasMessages()) { errorDialog.setWindowTitle(tr("Error(s) while loading the configuration")); if (errorDialog.exec() == QDialog::Rejected) { while (!talist.isEmpty()) delete talist.takeLast(); return; } } setCurrentTransformChain(talist); emit chainChanged(conf); } }
bool Processor::configureFromName(const QString &name, TransformAbstract::Way way) { TransformChain chain; TransformAbstract * t = transformFactory->getTransform(name); if (t != nullptr) { t->setWay(way); chain.append(t); } else return false; return setTransformsChain(chain); }
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 TransformsGui::onSavedSelected(QString name) { if (name.isEmpty()) { QMessageBox::critical(this,tr("Error"),tr("The selected name is empty T_T"),QMessageBox::Ok); qWarning() << tr("[TransformsGui] The selected name is empty T_T"); return; } TransformChain tc = transformFactory->loadChainFromSaved(name); if (tc.isEmpty()) { QMessageBox::critical(this,tr("Error"),tr("The returned chain is empty. Check the logs."),QMessageBox::Ok); } else { resetAll(); setCurrentTransformChain(tc); emit chainChanged(transformFactory->getSavedConfs().value(name)); } }
int QgsImageWarper::GeoToPixelTransform( void *pTransformerArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess ) { TransformChain *chain = static_cast<TransformChain*>( pTransformerArg ); if ( !chain ) { return false; } if ( !bDstToSrc ) { // Transform to georeferenced coordinates if ( !chain->GDALTransformer( chain->GDALTransformerArg, bDstToSrc, nPointCount, x, y, z, panSuccess ) ) { return false; } // Transform from georeferenced to pixel/line for ( int i = 0; i < nPointCount; ++i ) { if ( !panSuccess[i] ) continue; double xP = x[i]; double yP = y[i]; x[i] = chain->adfInvGeotransform[0] + xP * chain->adfInvGeotransform[1] + yP * chain->adfInvGeotransform[2]; y[i] = chain->adfInvGeotransform[3] + xP * chain->adfInvGeotransform[4] + yP * chain->adfInvGeotransform[5]; } } else { // Transform from pixel/line to georeferenced coordinates for ( int i = 0; i < nPointCount; ++i ) { double P = x[i]; double L = y[i]; x[i] = chain->adfGeotransform[0] + P * chain->adfGeotransform[1] + L * chain->adfGeotransform[2]; y[i] = chain->adfGeotransform[3] + P * chain->adfGeotransform[4] + L * chain->adfGeotransform[5]; } // Transform from georeferenced coordinates to source pixel/line if ( !chain->GDALTransformer( chain->GDALTransformerArg, bDstToSrc, nPointCount, x, y, z, panSuccess ) ) { return false; } } return true; }
void TransformsGui::setCurrentTransformChain(TransformChain talist) { name = talist.getName(); emit nameChanged(); // At this point nothing should go wrong, we can clean. while (transformWidgetList.size() > 0) { delete transformWidgetList.takeLast(); } QList<TransformWidget *> widgetList; TransformWidget *twa = NULL; for (int i = 0; i < talist.size(); i++) { twa = new(std::nothrow) TransformWidget(guiHelper, this); if (twa == NULL) { qFatal("Cannot allocate memory for TransformWidget X{"); return; } else { twa->setTransform(talist.at(i)); widgetList.append(twa); } } twa = new(std::nothrow) TransformWidget(guiHelper, this); if (twa == NULL) { qFatal("Cannot allocate memory for TransformWidget X{"); return; } widgetList.append(twa); // setting the first transform widget firstTransformWidget = widgetList.at(0); // adding the rest for (int i = 0; i < widgetList.size(); i++) { addWidget(widgetList.at(i)); } }
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); }