Beispiel #1
0
bool Template::execSwitchTemplateFileDialog(QWidget* dialog_parent)
{
	QString new_path = QFileDialog::getOpenFileName(dialog_parent,
	                                                tr("Find the moved template file"),
												    QString(),
	                                                tr("All files (*.*)") );
	new_path = QFileInfo(new_path).canonicalFilePath();
	if (new_path.isEmpty())
		return false;
	
	const State   old_state = getTemplateState();
	const QString old_path  = getTemplatePath();
	
	switchTemplateFile(new_path, true);
	if (getTemplateState() != Loaded)
	{
		QString error_template = QCoreApplication::translate("TemplateWidget", "Cannot open template\n%1:\n%2").arg(new_path);
		QString error = errorString();
		Q_ASSERT(!error.isEmpty());
		QMessageBox::warning(dialog_parent,
		                     tr("Error"),
		                     error_template.arg(error));
		
		// Revert change
		switchTemplateFile(old_path, old_state == Loaded);
		if (old_state == Invalid)
		{
			template_state = Invalid;
		}
		return false;
	}
	
	return true;
}
Beispiel #2
0
void MainWidget::on_RSMV_buildFrom_PsBtn_clicked()
{
    QString strPath=getTemplatePath();
    QFile   file(strPath);

   //qDebug()<<strPath;

    if (!file.exists())
    {
        show_MsBox(QString::fromUtf8("找不到报表模板路径"),3000);
    }

#if 1
    QAxWidget* temp_AxWidget = new QAxWidget("Word.Application");
    temp_AxWidget->setProperty("Visible", true);                       //新建一个word应用程序,并设置为可见

    QAxObject* documents = temp_AxWidget->querySubObject("Documents");  //获取所有的工作文档
    documents->dynamicCall("Open(QVariant)",strPath );                  //路径不对打开奔溃

    QAxObject *selection = temp_AxWidget->querySubObject("Selection");
    QAxObject *find = selection->querySubObject("Find");


    QList<QVariant> list2;                                               //*****Find Word http://technet.microsoft.com/zh-cn/library/ff193977
    list2.append("{cUserName}");                                         //find text
    list2.append(QVariant());//2
    list2.append(QVariant());//3
    list2.append(QVariant());//4
    list2.append(QVariant());//5
    list2.append(QVariant());//6
    list2.append(QVariant());//7
    list2.append(QVariant());//8
    list2.append(QVariant());//9
    list2.append(QString::fromUtf8("深圳市星龙科技"));                     //replace text
    list2.append(2);//replace all:2
    list2.append(QVariant());//12
    list2.append(QVariant());//13
    list2.append(QVariant());//14
    list2.append(QVariant());//15

    replaceDocTypeList replaceDocTypeList_Data;                            //装载搜索内容和替换内容的列表
    fillReplaceDocTypeList(ui->from_information_TbWidget,&replaceDocTypeList_Data);

    for (int i = 0; i < replaceDocTypeList_Data.count(); i++)
    {
        list2.replace(0, replaceDocTypeList_Data.at(i).searchStr);
        list2.replace(9, replaceDocTypeList_Data.at(i).replaceStr);
        find->dynamicCall("Execute (QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant& ,QVariant& ,QVariant& , QVariant&, QVariant&, QVariant&, QVariant&)", list2);
      //qDebug()<<replaceDocTypeList_Data.at(i).replaceStr;
    }
#endif
//  documents->dynamicCall("Save()");//保存
//  documents->dynamicCall("Close(boolean)", true);//关闭文本窗口
//  temp_AxWidget->dynamicCall("Quit(void)");//退出word
}
void HtmlTemplateProcessor::processCommand(const wxString& cmdName,
    const TemplateCmdParams& cmdParams, ProcessableObject* object,
    wxString& processedText)
{
    TemplateProcessor::processCommand(cmdName, cmdParams, object,
        processedText);

    MetadataItem* metadataItem = dynamic_cast<MetadataItem*>(object);
    if (!metadataItem)
        return;

    if (cmdName == "header" && !cmdParams.empty())  // include another file
    {
        std::vector<wxString> pages;
        HtmlHeaderMetadataItemVisitor v(pages);
        metadataItem->acceptVisitor(&v);

        wxString page = loadEntireFile(getTemplatePath() + "header.html");
        bool first = true;
        while (!page.Strip().IsEmpty())
        {
            wxString::size_type p2 = page.find('|');
            wxString part(page);
            if (p2 != wxString::npos)
            {
                part = page.substr(0, p2);
                page.Remove(0, p2+1);
            }
            else
                page.Clear();
            for (std::vector<wxString>::iterator it = pages.begin(); it !=
                pages.end(); ++it)
            {
                if (part.Find(">"+(*it)+"<") == -1)
                    continue;
                if (first)
                    first = false;
                else
                    processedText += " | ";
                wxString allParams = cmdParams.all();
                if (part.Find(">" + allParams + "<") != -1)
                    processedText += allParams;
                else
                    internalProcessTemplateText(processedText, part, object);
            }
        }
    }
}
Beispiel #4
0
void Template::saveTemplateConfiguration(QXmlStreamWriter& xml, bool open)
{
	xml.writeStartElement("template");
	xml.writeAttribute("open", open ? "true" : "false");
	xml.writeAttribute("name", getTemplateFilename());
	xml.writeAttribute("path", getTemplatePath());
	xml.writeAttribute("relpath", getTemplateRelativePath());
	if (is_georeferenced)
		xml.writeAttribute("georef", "true");
	else
	{
		xml.writeAttribute("group", QString::number(template_group));
		
		xml.writeStartElement("transformations");
		if (adjusted)
			xml.writeAttribute("adjusted", "true");
		if (adjustment_dirty)
			xml.writeAttribute("adjustment_dirty", "true");
		int num_passpoints = (int)passpoints.size();
		xml.writeAttribute("passpoints", QString::number(num_passpoints));
		
		transform.save(xml, "active");
		other_transform.save(xml, "other");
		
		for (int i = 0; i < num_passpoints; ++i)
			passpoints[i].save(xml);
		
		map_to_template.save(xml, "map_to_template");
		template_to_map.save(xml, "template_to_map");
		template_to_map_other.save(xml, "template_to_map_other");
		
		xml.writeEndElement(/*transformations*/);
	}
	
	saveTypeSpecificTemplateConfiguration(xml);
	
	if (open && hasUnsavedChanges())
	{
		// Save the template itself (e.g. image, gpx file, etc.)
		saveTemplateFile();
		setHasUnsavedChanges(false); // TODO: Error handling?
	}
	xml.writeEndElement(/*template*/);
}
Beispiel #5
0
bool Template::tryToFindAndReloadTemplateFile(QString map_directory, bool* out_loaded_from_map_dir)
{
	if (!map_directory.isEmpty() && !map_directory.endsWith('/'))
		map_directory.append('/');
	if (out_loaded_from_map_dir)
		*out_loaded_from_map_dir = false;
	
	const QString old_absolute_path = getTemplatePath();
	
	// First try relative path (if this information is available)
	if (!getTemplateRelativePath().isEmpty() && !map_directory.isEmpty())
	{
		setTemplatePath(map_directory + getTemplateRelativePath());
		loadTemplateFile(false);
		if (getTemplateState() == Template::Loaded)
			return true;
	}
	
	// Then try absolute path
	loadTemplateFile(false);
	if (getTemplateState() == Template::Loaded)
		return true;
	
	// Then try the template filename in the map's directory
	if (!map_directory.isEmpty())
	{
		setTemplatePath(map_directory + getTemplateFilename());
		loadTemplateFile(false);
		if (getTemplateState() == Template::Loaded)
		{
			if (out_loaded_from_map_dir)
				*out_loaded_from_map_dir = true;
			return true;
		}
	}
	
	setTemplatePath(old_absolute_path);
	return false;
}