提交 ac3511ed 编写于 作者: 丁劲犇's avatar 丁劲犇 😸

add save and load icon function.

上级 2b33ba4d
......@@ -103,6 +103,9 @@ private:
bool xml_readProps (QXmlStreamReader & reader, tag_xml_mark & mark,QString & errMsg);
QMap<QString,QString> xml_attribs_map(const QXmlStreamAttributes & ats);
bool xml_icon_save (QString xml);
bool xml_icon_load (QString xml);
//UI refreshing functions
private:
void scheduleRefreshMarks();
......@@ -180,6 +183,8 @@ protected slots:
void on_pushButton_save_clicked();
void on_pushButton_load_clicked();
void on_pushButton_import_icon_clicked();
void on_pushButton_load_icons_clicked();
void on_pushButton_save_icons_clicked();
};
template <class T>
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>505</width>
<height>426</height>
<width>446</width>
<height>444</height>
</rect>
</property>
<property name="windowTitle">
......@@ -174,7 +174,7 @@
<number>0</number>
</property>
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="page_points">
<layout class="QVBoxLayout" name="verticalLayout_2">
......@@ -461,7 +461,7 @@
<item>
<widget class="QPushButton" name="pushButton_import_icon">
<property name="text">
<string>import</string>
<string>add</string>
</property>
</widget>
</item>
......@@ -515,6 +515,37 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_load_icons">
<property name="text">
<string>load</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_save_icons">
<property name="text">
<string>save</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
......
......@@ -659,7 +659,7 @@ void qtvplugin_geomarker::on_pushButton_save_clicked()
if (true==xml_save(newfm))
{
settings.setValue("history/last_save_xml_dir",newfm);
QMessageBox::information(this,tr("succeed"),tr("Successfully saved XML file") + newfm);
//QMessageBox::information(this,tr("succeed"),tr("Successfully saved XML file") + newfm);
}
else
QMessageBox::warning(this,tr("failed"),tr("Save XML file") + newfm + tr(" Failed"));
......@@ -678,7 +678,7 @@ void qtvplugin_geomarker::on_pushButton_load_clicked()
if (true==xml_load(newfm))
{
settings.setValue("history/last_open_xml_dir",newfm);
QMessageBox::information(this,tr("succeed"),tr("Successfully load XML file") + newfm);
//QMessageBox::information(this,tr("succeed"),tr("Successfully load XML file") + newfm);
}
else
QMessageBox::warning(this,tr("failed"),tr("Load XML file") + newfm + tr(" Failed"));
......@@ -696,3 +696,41 @@ void qtvplugin_geomarker::on_pushButton_import_icon_clicked()
refreshIconModel();
}
}
void qtvplugin_geomarker::on_pushButton_load_icons_clicked()
{
QSettings settings(ini_file(),QSettings::IniFormat);
QString strLastSaveImgDir = settings.value("history/last_load_icon_xml_dir","./").toString();
QString newfm = QFileDialog::getOpenFileName(this,tr("load from xml"),strLastSaveImgDir,
"xml (*.xml);;All files(*.*)"
);
if (newfm.size()>2)
{
if (true==xml_icon_load(newfm))
{
settings.setValue("history/last_load_icon_xml_dir",newfm);
//QMessageBox::information(this,tr("succeed"),tr("Successfully load XML file") + newfm);
}
else
QMessageBox::warning(this,tr("failed"),tr("Load XML file") + newfm + tr(" Failed"));
}
this->refreshIconModel();
}
void qtvplugin_geomarker::on_pushButton_save_icons_clicked()
{
QSettings settings(ini_file(),QSettings::IniFormat);
QString strLastSaveImgDir = settings.value("history/last_save_icon_xml_dir","./").toString();
QString newfm = QFileDialog::getSaveFileName(this,tr("save to xml"),strLastSaveImgDir,
"xml (*.xml);;All files(*.*)"
);
if (newfm.size()>2)
{
if (true==xml_icon_save(newfm))
{
settings.setValue("history/last_save_icon_xml_dir",newfm);
//QMessageBox::information(this,tr("succeed"),tr("Successfully saved XML file") + newfm);
}
else
QMessageBox::warning(this,tr("failed"),tr("Save XML file") + newfm + tr(" Failed"));
}
}
......@@ -9,6 +9,7 @@
#include <QDebug>
#include <QXmlStreamAttributes>
#include <QMap>
#include <QFileInfo>
bool qtvplugin_geomarker::xml_save(QString xml)
{
QFile fp(xml);
......@@ -464,3 +465,144 @@ bool qtvplugin_geomarker::xml_update_mark(tag_xml_mark & mark)
return true;
}
bool qtvplugin_geomarker::xml_icon_save (QString xml)
{
QFile fp(xml);
QFileInfo smlinfo(xml);
if (fp.open(QIODevice::WriteOnly)==false)
return false;
QXmlStreamWriter stream(&fp);
stream.setAutoFormatting(true);
//0. Start Document
stream.writeStartDocument();
stream.writeStartElement("geomarker_icons");
stream.writeAttribute("version","1.0");
//1. for each icon, write a root element
QList<QString> keys = m_map_icons.keys();
foreach (QString keystr, keys)
{
const QTVP_GEOMARKER::tag_icon & item = m_map_icons[keystr];
//1.1. icon
stream.writeStartElement("icon");
stream.writeAttribute("name",item.name);
//1.1.1 center
stream.writeTextElement("centerx",QString("%1").arg(item.centerx));
stream.writeTextElement("centery",QString("%1").arg(item.centery));
QString fmSave = smlinfo.absoluteFilePath() + "_"+ item.name+".png";
QString fmRel = item.name+".png";
stream.writeTextElement("filename",fmRel);
item.icon.save(fmSave);
// 1.1mark
stream.writeEndElement();
}
stream.writeEndElement();
//0. End Document
stream.writeEndDocument();
fp.flush();
fp.close();
return true;
}
bool qtvplugin_geomarker::xml_icon_load (QString xmlfile)
{
bool res = true;
QString errMessage;
QFile fp(xmlfile);
QFileInfo smlinfo(xmlfile);
if (fp.open(QIODevice::ReadOnly)==false)
return false;
QXmlStreamReader xml(&fp);
if (xml.readNextStartElement())
{
if (xml.name()=="geomarker_icons")
{
QMap<QString,QString> att_geoMarker = xml_attribs_map(xml.attributes());
if (att_geoMarker["version"].toDouble()>=1)
{
while (!xml.atEnd() && res)
{
xml.readNext();
if (xml.tokenType()==QXmlStreamReader::StartElement)
{
if (xml.name()=="icon")
{
QTVP_GEOMARKER::tag_icon icon;
//icon
QMap<QString,QString > att_marker = xml_attribs_map(xml.attributes());
icon.name = att_marker["name"];
if (icon.name.size()==0)
{
errMessage = tr("icon name is null or type error .");
res = false;
}
else
{
while (xml.readNextStartElement()&& res)
{
if (xml.name()=="centerx")
{
icon.centerx = xml.readElementText().toInt();
}
else if (xml.name()=="centery")
{
icon.centery = xml.readElementText().toInt();
}
else if (xml.name()=="filename")
{
QString fm = xml.readElementText();
QString fmOpen = smlinfo.absoluteFilePath() + "_"+ fm;
if (icon.icon.load(fmOpen)==false)
res = false;
else
icon.filename = fmOpen;
}
else
;
}//end while next start element
if (res)
m_map_icons[icon.name] = icon;
}//end if name is valide
}//end if ele is "icon:"
}//end if start Doc
}//end while is not end of file
}
else
{
res = false;
errMessage = tr("Version must >=1.0.");
}
}//end if version is valid
else
{
res = false;
errMessage = tr("This XML is not a geomarker_icons format file.");
}// version is not valis
}//end if file is not empty
else
{
res = false;
errMessage = tr("Empty XML.");
}
fp.close();
if (res==false)
{
QMap<QString,QVariant> evt_error;
evt_error["source"] = get_name();
evt_error["destin"] = "ALL";
evt_error["name"] = "error";
evt_error["class"] = "QXmlStreamReader";
evt_error["file"] = xmlfile;
evt_error["detail"] = errMessage;
m_pVi->post_event(evt_error);
}
return res;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册