// Protected "real" constructor
// All paths are initialized to compile-time defaults passed in
// as preprocessor macros and set by autoconf.
ScPaths::ScPaths() :
	m_docDir(DOCDIR),
	m_iconDir(ICONDIR),
	m_libDir(LIBDIR),
	m_pluginDir(PLUGINDIR),
	m_sampleScriptDir(SAMPLESDIR),
	m_scriptDir(SCRIPTSDIR),
	m_templateDir(TEMPLATEDIR),
	m_shareDir(SHAREDIR)
{
// On MacOS/X, override the compile-time settings with a location
// obtained from the system.
#ifdef Q_WS_MAC
	QString pathPtr(bundleDir());
	qDebug() << QString("scpaths: bundle at %1").arg(pathPtr);
	m_shareDir = QString("%1/Contents/share/scribus/").arg(pathPtr);
	m_docDir = QString("%1/Contents/share/doc/scribus/").arg(pathPtr);
	m_iconDir = QString("%1/Contents/share/scribus/icons/").arg(pathPtr);
	m_sampleScriptDir = QString("%1/Contents/share/scribus/samples/").arg(pathPtr);
	m_scriptDir = QString("%1/Contents/share/scribus/scripts/").arg(pathPtr);
	m_templateDir = QString("%1/Contents/share/scribus/templates/").arg(pathPtr);
	m_libDir = QString("%1/Contents/lib/scribus/").arg(pathPtr);
	m_pluginDir = QString("%1/Contents/lib/scribus/plugins/").arg(pathPtr);
	QApplication::setLibraryPaths(QStringList(QString("%1/Contents/lib/qtplugins/").arg(pathPtr)));

	// on OSX this goes to the sys console, so user only sees it when they care -- AV
	qDebug() << QString("scpaths: doc dir=%1").arg(m_docDir);
	qDebug() << QString("scpaths: icon dir=%1").arg(m_iconDir);
	qDebug() << QString("scpaths: font dir=%1").arg(m_fontDir);
	qDebug() << QString("scpaths: sample dir=%1").arg(m_sampleScriptDir);
	qDebug() << QString("scpaths: script dir=%1").arg(m_scriptDir);
	qDebug() << QString("scpaths: template dir=%1").arg(m_templateDir);
	qDebug() << QString("scpaths: lib dir=%1").arg(m_libDir);
	qDebug() << QString("scpaths: plugin dir=%1").arg(m_pluginDir);
	qDebug() << QString("scpaths: qtplugins=%1").arg(QApplication::libraryPaths().join(":"));

#elif defined(_WIN32)
	QString appPath = qApp->applicationDirPath();
	m_shareDir = QString("%1/share/").arg(appPath);
	m_docDir = QString("%1/share/doc/").arg(appPath);
	m_fontDir = QString("%1/share/fonts/").arg(appPath);
	m_iconDir = QString("%1/share/icons/").arg(appPath);
	m_sampleScriptDir = QString("%1/share/samples/").arg(appPath);
	m_scriptDir = QString("%1/share/scripts/").arg(appPath);
	m_templateDir = QString("%1/share/templates/").arg(appPath);
	m_libDir = QString("%1/libs/").arg(appPath);
	m_pluginDir = QString("%1/plugins/").arg(appPath);
	QApplication::setLibraryPaths( QStringList(QString("%1/qtplugins/").arg(appPath)) );
#endif
	
// 	if(!m_shareDir.endsWith("/"))        m_shareDir += "/";
// 	if(!m_docDir.endsWith("/"))          m_docDir += "/";
// 	if(!m_fontDir.endsWith("/"))         m_fontDir += "/";
	if(!m_iconDir.endsWith("/"))         m_iconDir += "/";
// 	if(!m_sampleScriptDir.endsWith("/")) m_sampleScriptDir += "/";
// 	if(!m_scriptDir.endsWith("/"))       m_scriptDir += "/";
// 	if(!m_templateDir.endsWith("/"))     m_templateDir += "/";
// 	if(!m_libDir.endsWith("/"))          m_libDir += "/";
// 	if(!m_pluginDir.endsWith("/"))       m_pluginDir += "/";
}
Ejemplo n.º 2
0
void QQmlDebugProcess::start(const QStringList &arguments)
{
#ifdef Q_OS_MAC
    // make sure m_executable points to the actual binary even if it's inside an app bundle
    QFileInfo binFile(m_executable);
    if (!binFile.isExecutable()) {
        QDir bundleDir(m_executable + ".app");
        if (bundleDir.exists()) {
            m_executable = bundleDir.absoluteFilePath("Contents/MacOS/" + binFile.baseName());
            //qDebug() << Q_FUNC_INFO << "found bundled binary" << m_executable;
        }
    }
#endif
    m_mutex.lock();
    m_port = 0;
    m_process.setEnvironment(m_environment);
    m_process.start(m_executable, arguments);
    if (!m_process.waitForStarted()) {
        qWarning() << "QML Debug Client: Could not launch app " << m_executable
                   << ": " << m_process.errorString();
        m_eventLoop.quit();
    } else {
        m_timer.start();
    }
    m_mutex.unlock();
}
Ejemplo n.º 3
0
bool plotsDialog::saveChanges()
{
#ifdef Q_OS_WIN32
    QFile ofile(globalpara.caseName),file("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
    QDir dir = qApp->applicationDirPath();
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    QString bundleDir(dir.absolutePath());
    QFile ofile(globalpara.caseName),file(bundleDir+"/plotTemp.xml");
#endif
    QDomDocument odoc,doc;
    QDomElement oroot;
    QTextStream stream;
    stream.setDevice(&ofile);
    if(!ofile.open(QIODevice::ReadWrite|QIODevice::Text))
    {
        globalpara.reportError("Fail to open case file to update plot data.",this);
        return false;
    }
    else if(!odoc.setContent(&ofile))
    {
        globalpara.reportError("Fail to load xml document from case file to update plot data.",this);
        return false;
    }
    if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
    {
        globalpara.reportError("Fail to open plot temp file to update plot data.",this);
        return false;
    }
    else if(!doc.setContent(&file))
    {
        globalpara.reportError("Fail to load xml document from plot temp file to update plot data..",this);
        return false;
    }
    else
    {
        QDomElement plotData = doc.elementsByTagName("plotData").at(0).toElement();
        QDomNode copiedPlot = plotData.cloneNode(true);
        oroot = odoc.elementsByTagName("root").at(0).toElement();
        oroot.replaceChild(copiedPlot,odoc.elementsByTagName("plotData").at(0));

        ofile.resize(0);
        odoc.save(stream,4);
        file.close();
        ofile.close();
        stream.flush();
        return true;
    }
}
Ejemplo n.º 4
0
void plotsDialog::on_copyButton_clicked()
{
    QString pName = tabs->tabText(tabs->currentIndex());
    QString newName = pName+"Copy";
#ifdef Q_OS_WIN32
    QFile file("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
    QDir dir = qApp->applicationDirPath();
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    QString bundleDir(dir.absolutePath());
    QFile file(bundleDir+"/plotTemp.xml");
#endif
    QTextStream stream;
    stream.setDevice(&file);
    if(!file.open(QIODevice::ReadWrite|QIODevice::Text))
    {
        globalpara.reportError("Fail to open case file to copy plot.",this);
        return;
    }
    else
    {
        QDomDocument doc;
        if(!doc.setContent(&file))
        {
            globalpara.reportError("Fail to load xml document to copy plot.....",this);
            file.close();
            return;
        }
        else
        {
            QDomElement plotData = doc.elementsByTagName("plotData").at(0).toElement();
            if(!plotData.elementsByTagName(pName).isEmpty())
            {

                QDomNode newNode = plotData.elementsByTagName(pName).at(0).cloneNode(true);
                newNode.toElement().setTagName(newName);
                plotData.appendChild(newNode);

            }
        }
        file.resize(0);
        doc.save(stream,4);
        file.close();
        stream.flush();
    }

    setupPlots(false);
}
Ejemplo n.º 5
0
QString getPrefix()
{
#if defined(Q_OS_WIN32)
	static char inst_dir[100] = "";
	char *p;
	ULONG dwLength = 100;
	HKEY hKey;

	if (inst_dir[0] != '\0') {
		/* if we already once discovered the directory just return it */
		return QString(inst_dir);
	}
	// fallback: directory of xca.exe
	GetModuleFileName(0, inst_dir, dwLength - 1);
	p = strrchr(inst_dir, '\\');
	if (p) {
		*p = '\0';
		return QString(inst_dir);
	}
	if (portable_app())
		return QString(inst_dir);
	p = inst_dir;
	*p = '\0';
	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\xca", 0,
		KEY_WOW64_32KEY|KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		XCA_WARN("Registry Key: 'HKEY_LOCAL_MACHINE\\Software\\xca' not found");
		return QString(inst_dir);
	}
	if (RegQueryValueEx(hKey, "Install_Dir", NULL, NULL,
			(unsigned char *)inst_dir, &dwLength) != ERROR_SUCCESS)
	{
		XCA_WARN("Registry Key: 'HKEY_LOCAL_MACHINE->Software->xca->Install_Dir' not found");
	}
	RegCloseKey(hKey);
	return QString(inst_dir);

#elif defined(Q_OS_MAC)
	// since this is platform-specific anyway,
	// this is a more robust way to get the bundle directory
	QDir bundleDir(qApp->applicationDirPath());
	bundleDir.cdUp();
        return bundleDir.canonicalPath() + "/Resources";
#else
#ifndef XCA_PREFIX
#define XCA_PREFIX PREFIX "/share/xca"
#endif
	return QString(XCA_PREFIX);
#endif

}
Ejemplo n.º 6
0
Archivo: func.cpp Proyecto: jbfavre/xca
QString getPrefix()
{
#ifdef WIN32
	static char inst_dir[100] = "";
	char *p;
	ULONG dwLength = 100;
	LONG lRc;
	HKEY hKey;

	if (inst_dir[0] != '\0') {
		/* if we already once discovered the directory just return it */
		return QString(inst_dir);
	}
	// fallback: directory of xca.exe
	GetModuleFileName(0, inst_dir, dwLength - 1);
	p = strrchr(inst_dir, '\\');
	if (p) {
		*p = '\0';
		return QString(inst_dir);
	}
	p = inst_dir;
	*p = '\0';
	lRc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\xca", 0, KEY_READ, &hKey);
	if (lRc != ERROR_SUCCESS) {
		QMessageBox::warning(NULL,XCA_TITLE,
				"Registry Key: 'HKEY_LOCAL_MACHINE->Software->xca' not found");
		return QString(inst_dir);
	}
	lRc = RegQueryValueEx(hKey, "Install_Dir", NULL, NULL,
			(unsigned char *)inst_dir, &dwLength);
	if (lRc != ERROR_SUCCESS){
		QMessageBox::warning(NULL, XCA_TITLE, "Registry Key: "
				"'HKEY_LOCAL_MACHINE->Software->xca->Install_Dir' not found");
	}
	lRc = RegCloseKey(hKey);
	return QString(inst_dir);

#elif defined(Q_WS_MAC)
	// since this is platform-specific anyway,
	// this is a more robust way to get the bundle directory
	QDir bundleDir(qApp->applicationDirPath());
	bundleDir.cdUp();
        return bundleDir.canonicalPath() + "/Resources";
#else
	return QString(PREFIX) + "/share/xca";
#endif

}
Ejemplo n.º 7
0
void plotsDialog::closeEvent(QCloseEvent *)
{
    savePlotSettings();

    saveChanges();
    theScene->plotWindow = NULL;
    theMainwindow->setTPMenu();
#ifdef Q_OS_WIN32
    QFile file("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
    QDir dir = qApp->applicationDirPath();
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    QString bundleDir(dir.absolutePath());
    QFile file(bundleDir+"/plotTemp.xml");
#endif

    file.remove();
}
Ejemplo n.º 8
0
QIODevice *Bundle::openFile(enum Bundle::File file, QIODevice::OpenMode mode) const
{
    QString fileName;
    switch (file) {
    case Bundle::MANIFEST:
        fileName = "manifest.json";
        break;
    case Bundle::INFO:
        fileName = "appinfo.json";
        break;
    case Bundle::APPJS:
        fileName = "pebble-js-app.js";
        break;
    case Bundle::BINARY:
        fileName = b->manifest.value(type()).toObject().value("name").toString();
        break;
    case Bundle::RESOURCES:
        fileName = b->manifest.value("resources").toObject().value("name").toString();
        break;
    }

    QIODevice *dev = 0;
    QFileInfo bundlePath(path());
    if (bundlePath.isDir()) {
        QDir bundleDir(path());
        if (bundleDir.exists(fileName)) {
            dev = new QFile(bundleDir.absoluteFilePath(fileName));
        }
    } else if (bundlePath.isFile()) {
        dev =  new QuaZipFile(path(), fileName);
    }

    if (dev && !dev->open(QIODevice::ReadOnly | mode)) {
        delete dev;
        return 0;
    }

    return dev;
}
Ejemplo n.º 9
0
void plotsDialog::savePlotSettings()
{

#ifdef Q_OS_WIN32
    QFile file("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
    QDir dir = qApp->applicationDirPath();
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    QString bundleDir(dir.absolutePath());
    QFile ofile(globalpara.caseName),file(bundleDir+"/plotTemp.xml");
#endif
    QTextStream stream;
    stream.setDevice(&file);
    QDomDocument doc;
    QDomElement plotData, currentPlot, general, legend, grid, curve;

    if(!file.open(QIODevice::ReadWrite | QIODevice::Text))
    {
        globalpara.reportError("Failed to open and load case file for plot data.",this);
        return;
    }
    else
    {
        if(!doc.setContent(&file))
        {
            globalpara.reportError("Failed to set document for the xml file for plot data.",this);
            file.close();
            return;
        }
        else
        {
            plotData = doc.elementsByTagName("plotData").at(0).toElement();

            for(int i = 0; i < tabs->count(); i++)
            {
                Plot* set_plot = dynamic_cast<Plot*>(tabs->widget(i));
                currentPlot = plotData.elementsByTagName(tabs->tabText(i)).at(0).toElement();

                //general
                if(currentPlot.elementsByTagName("general").count()==0)
                {
                    general = doc.createElement("general");
                    currentPlot.appendChild(general);
                }
                else general = currentPlot.elementsByTagName("general").at(0).toElement();
                general.setAttribute("bgColor",set_plot->canvasBackground().color().name());
                general.setAttribute("lMargin",set_plot->contentsMargins().left());
                general.setAttribute("rMargin",set_plot->contentsMargins().right());
                general.setAttribute("tMargin",set_plot->contentsMargins().top());
                general.setAttribute("bMargin",set_plot->contentsMargins().bottom());
                general.setAttribute("plotTitle",set_plot->title().text());
                general.setAttribute("xTitle",set_plot->axisTitle(QwtPlot::xBottom).text());
                general.setAttribute("yTitle",set_plot->axisTitle(QwtPlot::yLeft).text());

                //legend
                if(currentPlot.elementsByTagName("legend").count()==0)
                {
                    legend = doc.createElement("legend");
                    currentPlot.appendChild(legend);
                }
                else legend = currentPlot.elementsByTagName("legend").at(0).toElement();
                if(set_plot->externalLegend!=NULL||set_plot->internalLegend->isVisible())
                {
                    legend.setAttribute("plotLegend","on");
                    if(set_plot->internalLegend->isVisible())
                    {
                        legend.setAttribute("extInt","int");
                        legend.setAttribute("nCol",set_plot->internalLegend->maxColumns());
                        legend.setAttribute("legendSize",set_plot->internalLegend->font().pointSize());
                    }
                    else if(set_plot->externalLegend!=NULL)
                    {
                        legend.setAttribute("extInt","ext");
                        legend.setAttribute("extPos",0);
                    }
                }
                else legend.setAttribute("plotLegend","off");

                //grid
                if(currentPlot.elementsByTagName("grid").count()==0)
                {
                    grid = doc.createElement("grid");
                    currentPlot.appendChild(grid);
                }
                else grid = currentPlot.elementsByTagName("grid").at(0).toElement();
                if(set_plot->grid->xEnabled()||set_plot->grid->yEnabled())
                {
                    if(set_plot->grid->xEnabled())
                        grid.setAttribute("xMaj","on");
                    else grid.setAttribute("xMaj","off");
                    if(set_plot->grid->yEnabled())
                        grid.setAttribute("yMaj","on");
                    else grid.setAttribute("yMaj","off");
                    grid.setAttribute("majColor",set_plot->grid->majorPen().color().name());
                    grid.setAttribute("majSize",set_plot->grid->majorPen().width());
                    int styleCode;
                    if(set_plot->grid->majorPen().style()==Qt::NoPen)
                        styleCode=0;
                    else if(set_plot->grid->majorPen().style()==Qt::SolidLine)
                        styleCode=1;
                    else if(set_plot->grid->majorPen().style()==Qt::DashLine)
                        styleCode=2;
                    else if(set_plot->grid->majorPen().style()==Qt::DotLine)
                        styleCode=3;
                    else if(set_plot->grid->majorPen().style()==Qt::DashDotLine)
                        styleCode=4;
                    else if(set_plot->grid->majorPen().style()==Qt::DashDotDotLine)
                        styleCode=5;
                    grid.setAttribute("majStyle",styleCode);
                }
                else
                {
                    grid.setAttribute("xMaj","off");
                    grid.setAttribute("yMaj","off");
                }
                if(set_plot->grid->xMinEnabled()||set_plot->grid->yMinEnabled())
                {
                    if(set_plot->grid->xMinEnabled())
                        grid.setAttribute("xMin","on");
                    else grid.setAttribute("xMin","off");
                    if(set_plot->grid->yMinEnabled())
                        grid.setAttribute("yMin","on");
                    else grid.setAttribute("yMin","off");
                    grid.setAttribute("minColor",set_plot->grid->minorPen().color().name());
                    grid.setAttribute("minSize",set_plot->grid->minorPen().width());
                    int styleCode;
                    if(set_plot->grid->minorPen().style()==Qt::NoPen)
                        styleCode=0;
                    else if(set_plot->grid->minorPen().style()==Qt::SolidLine)
                        styleCode=1;
                    else if(set_plot->grid->minorPen().style()==Qt::DashLine)
                        styleCode=2;
                    else if(set_plot->grid->minorPen().style()==Qt::DotLine)
                        styleCode=3;
                    else if(set_plot->grid->minorPen().style()==Qt::DashDotLine)
                        styleCode=4;
                    else if(set_plot->grid->minorPen().style()==Qt::DashDotDotLine)
                        styleCode=5;
                    grid.setAttribute("minStyle",styleCode);
                }
                else
                {
                    grid.setAttribute("xMin","off");
                    grid.setAttribute("yMin","off");
                }

                //curve
                QDomNode const oldCurveSettings = currentPlot.elementsByTagName("curve").at(0);
                currentPlot.removeChild(oldCurveSettings);
                curve = doc.createElement("curve");
                currentPlot.appendChild(curve);
//                if(currentPlot.elementsByTagName("curve").count()==0)
//                {
//                    curve = doc.createElement("curve");
//                    currentPlot.appendChild(curve);
//                }
//                else curve = currentPlot.elementsByTagName("curve").at(0).toElement();
//                if(curve.childNodes().count()!=set_plot->curvelist.count())
//                {
//                    QDomNode node;
//                    for(int i = 0; i < curve.childNodes().count();i++)
//                    {
//                        node = curve.childNodes().at(i);
//                        curve.removeChild(node);
//                    }
//                    QDomElement newCurve;
//                    for(int i = 0; i < set_plot->curvelist.count();i++)
//                    {
//                        newCurve = doc.createElement(set_plot->curvelist.at(i)->title().text().replace(" ",""));
//                        curve.appendChild(newCurve);
//                    }
//                }
                QDomElement currentCurve;
                QwtPlotCurve *thisCurve;
                for(int i = 0; i < set_plot->curvelist.count(); i++)
                {
                    currentCurve = doc.createElement(set_plot->curvelist.at(i)->title().text().replace(" ",""));
                    curve.appendChild(currentCurve);
                    thisCurve = set_plot->curvelist[i];
                    currentCurve = curve.elementsByTagName(set_plot->curvelist.at(i)->title().text().replace(" ","")).at(0).toElement();

                    if(thisCurve->isVisible())
                        currentCurve.setAttribute("isVisible","true");
                    else
                        currentCurve.setAttribute("isVisible","false");
                    currentCurve.setAttribute("lineColor",thisCurve->pen().color().name());
                    currentCurve.setAttribute("lineSize",thisCurve->pen().width());
                    int styleCode;
                    if(thisCurve->pen().style()==Qt::NoPen)
                        styleCode=0;
                    else if(thisCurve->pen().style()==Qt::SolidLine)
                        styleCode=1;
                    else if(thisCurve->pen().style()==Qt::DashLine)
                        styleCode=2;
                    else if(thisCurve->pen().style()==Qt::DotLine)
                        styleCode=3;
                    else if(thisCurve->pen().style()==Qt::DashDotLine)
                        styleCode=4;
                    else if(thisCurve->pen().style()==Qt::DashDotDotLine)
                        styleCode=5;
                    currentCurve.setAttribute("lineType",styleCode);
                }

            }

            file.resize(0);
            doc.save(stream,4);
            file.close();
            return;
        }
    }
}
Ejemplo n.º 10
0
void plotsDialog::on_dataSelectButton_clicked()
{
    QString pName = tabs->tabText(tabs->currentIndex());
    QString tableName;
    bool noTable = false;

    //make name-space for the new plot
#ifdef Q_OS_WIN32
    QFile file("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
    QDir dir = qApp->applicationDirPath();
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    QString bundleDir(dir.absolutePath());
    QFile file(bundleDir+"/plotTemp.xml");
#endif
    QTextStream stream;
    stream.setDevice(&file);
    if(!file.open(QIODevice::ReadWrite|QIODevice::Text))
    {
        globalpara.reportError("Fail to open case file to copy plot.",this);
        return;
    }
    else
    {
        QDomDocument doc;
        if(!doc.setContent(&file))
        {
            globalpara.reportError("Fail to load xml document to copy plot..",this);
            file.close();
            return;
        }
        else
        {
            //look for the original table that generated the plot
            QDomElement tableData = doc.elementsByTagName("TableData").at(0).toElement();
            QDomElement plotData = doc.elementsByTagName("plotData").at(0).toElement();
            tableName = plotData.elementsByTagName(pName).at(0).toElement().attribute("tableName");
            if(tableData.elementsByTagName(tableName).count()==0)
            {
                noTable = true;
                file.close();
            }
            else
            {
                noTable = false;
                QDomElement oldPlot = plotData.elementsByTagName(pName).at(0).toElement();
                oldPlot.setTagName("tempNode");
                file.resize(0);
                doc.save(stream,4);
                file.close();
                stream.flush();
            }

        }
    }

    if(noTable)
        globalpara.reportError("The original table for this plot is not available in table data.");
    else
    {
        //ask for new selection of parameters
        newParaPlotDialog *pDialog = new newParaPlotDialog(2,tableName,pName,this);
        pDialog->setWindowTitle("Re-select Parameters");
        pDialog->setModal(true);
        if(pDialog->exec()==QDialog::Accepted)
        {
            //if accepted, delete the original node under name _mod
#ifdef Q_OS_WIN32
            QFile file("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
            QFile file(bundleDir+"/plotTemp.xml");
#endif
            QTextStream stream;
            stream.setDevice(&file);
            if(!file.open(QIODevice::ReadWrite|QIODevice::Text))
            {
                globalpara.reportError("Fail to open case file to copy plot.",this);
                return;
            }
            else
            {
                QDomDocument doc;
                if(!doc.setContent(&file))
                {
                    globalpara.reportError("Fail to load xml document to copy plot...",this);
                    file.close();
                    return;
                }
                else
                {
                    QDomElement plotData = doc.elementsByTagName("plotData").at(0).toElement();
                    plotData.removeChild(plotData.elementsByTagName("tempNode").at(0));
                }
                file.resize(0);
                doc.save(stream,4);
                file.close();
                stream.flush();

                saveChanges();
                setupPlots(false);
            }

        }
        else
        {
            //if canceled, resume the original plot name
#ifdef Q_OS_WIN32
            QFile file("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
            QFile file(bundleDir+"/plotTemp.xml");
#endif

            QTextStream stream;
            stream.setDevice(&file);
            if(!file.open(QIODevice::ReadWrite|QIODevice::Text))
            {
                globalpara.reportError("Fail to open case file to copy plot.",this);
                return;
            }
            else
            {
                QDomDocument doc;
                if(!doc.setContent(&file))
                {
                    globalpara.reportError("Fail to load xml document to copy plot....",this);
                    file.close();
                    return;
                }
                else
                {
                    QDomElement plotData = doc.elementsByTagName("plotData").at(0).toElement();
                    QDomElement oldPlot = plotData.elementsByTagName("tempNode").at(0).toElement();
                    oldPlot.setTagName(pName);
                }
                file.resize(0);
                doc.save(stream,4);
                file.close();
                stream.flush();
            }

        }



    }
}
Ejemplo n.º 11
0
void plotsDialog::deleteCurrentPlot()
{
    QMessageBox * askBox = new QMessageBox(this);
    askBox->addButton("Delete",QMessageBox::YesRole);
    askBox->addButton("Cancel",QMessageBox::NoRole);
    askBox->setText("Confirm to delete the plot?");
    askBox->setWindowTitle("Warning");
    askBox->exec();
    if(askBox->buttonRole(askBox->clickedButton())==QMessageBox::YesRole)
    {
        Plot* plotToDelete = dynamic_cast<Plot*>(tabs->currentWidget());
#ifdef Q_OS_WIN32
        QFile file("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
        QDir dir = qApp->applicationDirPath();
        /*dir.cdUp();*/
        /*dir.cdUp();*/
        /*dir.cdUp();*/
        QString bundleDir(dir.absolutePath());
        QFile file(bundleDir+"/plotTemp.xml");
#endif
        if(!file.open(QIODevice::ReadWrite|QIODevice::Text))
        {
            return;
            globalpara.reportError("Fail to open xml file for plots!",this);
        }
        else
        {
            QDomDocument doc;
            QTextStream stream;
            stream.setDevice(&file);
            if(!doc.setContent(&file))
            {
                globalpara.reportError("Fail to load xml document for plots!",this);
                file.close();
                return;
            }
            else
            {
                QDomElement plotData = doc.elementsByTagName("plotData").at(0).toElement();
                plotData.removeChild(plotData.elementsByTagName(tabs->tabText(tabs->currentIndex())).at(0));
            }
            file.resize(0);
            doc.save(stream,4);
            file.close();
            stream.flush();
        }


        if(tabs->count()>1)
        {
            tabs->removeTab(tabs->currentIndex());
        }
        else if(tabs->count()==1)
        {
            this->close();
        }
    }
    else return;
}
Ejemplo n.º 12
0
bool plotsDialog::loadXml(bool init)
{
    tabs->clear();
    QFile file;
#ifdef Q_OS_WIN32
    if(init)
    {
        QFile ofile(globalpara.caseName);
        file.setFileName("plotTemp.xml");
        if(file.exists())
            file.remove();
        if(!ofile.copy("plotTemp.xml"))
        {
            globalpara.reportError("Fail to generate temporary file for plots.",this);
            return false;
        }
        else file.setFileName("plotTemp.xml");
    }
    else file.setFileName("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
    QDir dir = qApp->applicationDirPath();
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    QString bundleDir(dir.absolutePath());
    if(init)
    {
        QFile ofile(globalpara.caseName);
        file.setFileName(bundleDir+"/plotTemp.xml");
        if(file.exists())
            file.remove();
        if(!ofile.copy(bundleDir+"/plotTemp.xml"))
        {
            globalpara.reportError("Fail to generate temporary file for plots.",this);
            return false;
        }
        else file.setFileName(bundleDir+"/plotTemp.xml");
    }
    else file.setFileName(bundleDir+"/plotTemp.xml");
#endif
    QDomDocument doc;
    QDomElement plotData, currentPlot;
    int plotCount=0;
    Plot*newPlot;

    if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        globalpara.reportError("Fail to open the xml file for plots!",this);
        return false;
    }
    else
    {
        if(!doc.setContent(&file))
        {
            globalpara.reportError("Fail to set DomDoc to file content when loading xml file for plots!",this);
            file.close();
            return false;
        }
        else
        {
            if(doc.elementsByTagName("plotData").count()==0)
            {
                globalpara.reportError("Error! There is no <plotData> branch in the case xml file!",this);
                file.close();
                return false;
            }
            else
                plotData = doc.elementsByTagName("plotData").at(0).toElement();

            plotCount = plotData.childNodes().count();
            for(int i = 0; i < plotCount; i++)
            {
                currentPlot = plotData.childNodes().at(i).toElement();
                if(currentPlot.attribute("plotType")=="parametric")
                {
                    QDomElement currentRun,runInput,runOutput;
                    double currentInput;
                    int axis_info[8];
                    QStringList currentOutput, xValues, axis_name, info;
                    QMultiMap<double,double> allData;
                    axis_name.append(currentPlot.attribute("xAxisName"));
                    axis_name= axis_name + currentPlot.attribute("yAxisName").split(",");
                    info = currentPlot.attribute("scaleInfo").split(",");
                    for(int j = 0; j < 8; j++)
                        axis_info[j] = info.at(j).toInt();
                    int nRuns = currentPlot.elementsByTagName("Run").count(), nOutputs = currentPlot.attribute("outputs").toInt();
                    for(int j = 0; j < nRuns; j++)
                    {
                        currentOutput.clear();
                        currentRun = currentPlot.elementsByTagName("Run").at(j).toElement();
                        runInput = currentRun.elementsByTagName("Input").at(0).toElement();
                        currentInput = runInput.elementsByTagName("value").at(0).toElement().text().toDouble();
                        xValues.append(QString::number(currentInput));
                        for(int p = 0; p < nOutputs; p++)
                        {
                            runOutput = currentRun.elementsByTagName("Output").at(p).toElement();
                            currentOutput.append(runOutput.elementsByTagName("value").at(0).toElement().text());
                            allData.insert(currentInput,currentOutput.at(p).toDouble());
                        }
                    }


                    newPlot = new Plot(allData,xValues,nOutputs,axis_info,axis_name);


                }
                else if(currentPlot.attribute("plotType")=="property")
                {
                    QString fluid = currentPlot.attribute("fluid"),
                            subType = currentPlot.attribute("subType"),
                            unit = currentPlot.attribute("unitSystem");

                    newPlot = new Plot(fluid,subType,unit);
                    QDomElement currentCurve, currentPoint;

                    newPlot->curvePoints.clear();
                    for(int i = 0; i < currentPlot.childNodes().count(); i++)
                    {
                        if(currentPlot.childNodes().at(i).toElement().attribute("type")=="custom")
                        {
                            addvalue*value;
                            newPlot->addvaluelist.clear();
                            currentCurve = currentPlot.childNodes().at(i).toElement();
                            QString title = currentCurve.tagName();
                            for(int j = 0; j < currentCurve.childNodes().count(); j++)
                            {
                                if(currentCurve.childNodes().at(j).toElement().attribute("order")==QString::number(j))
                                {
                                    value = new addvalue;
                                    currentPoint = currentCurve.childNodes().at(j).toElement();
                                    value->index = currentPoint.attribute("index").toInt();
                                    value->add_temperature = currentPoint.attribute("t").toDouble();
                                    value->add_pressure = currentPoint.attribute("p").toDouble();
                                    value->add_concentration = currentPoint.attribute("c").toDouble();
                                    value->add_enthalpy = currentPoint.attribute("h").toDouble();
//                                    qDebug()<<"adding a new point"<<currentPoint.attribute("index")<<"t"<<currentPoint.attribute("t")<<"p"<<currentPoint.attribute("p")<<"c"<<currentPoint.attribute("c");
                                    newPlot->addvaluelist<<value;
                                }
                            }

                            if(subType == "Duhring")
                                newPlot->setupNewPropertyCurve(title,true);
                            else if(subType == "Clapeyron")
                                newPlot->setupNewPropertyCurve(title,false);
                        }
                    }


                }
                newPlot->setTitle(currentPlot.tagName());

                //load the plot settings
                QDomElement general, legend, grid, curve;

                //general
                if(currentPlot.elementsByTagName("general").count()>0)
                {
                    general = currentPlot.elementsByTagName("general").at(0).toElement();
                    QString bgColor, lMargin, rMargin, tMargin, bMargin, plotTitle, xTitle, yTitle;
                    bgColor = general.attribute("bgColor");
                    newPlot->setCanvasBackground(QColor(bgColor));
                    lMargin = general.attribute("lMargin");
                    rMargin = general.attribute("rMargin");
                    tMargin = general.attribute("tMargin");
                    bMargin = general.attribute("bMargin");
                    newPlot->setContentsMargins(lMargin.toInt(),tMargin.toInt(),rMargin.toInt(),bMargin.toInt());
                    plotTitle = general.attribute("plotTitle");
                    newPlot->setTitle(plotTitle);
                    xTitle = general.attribute("xTitle");
                    yTitle = general.attribute("yTitle");
                    newPlot->setAxisTitle(QwtPlot::xBottom,xTitle);
                    newPlot->setAxisTitle(QwtPlot::yLeft,yTitle);

                }

                //legend
                if(currentPlot.elementsByTagName("legend").count()>0)
                {
                    legend = currentPlot.elementsByTagName("legend").at(0).toElement();
                    QString plotLegend, extInt, extPos, nCol, legendSize;
                    plotLegend = legend.attribute("plotLegend");
                    if(plotLegend == "on")
                    {
                        QwtLegend* externalLegend=NULL;
                        LegendItem* internalLegend = new LegendItem();
                        newPlot->externalLegend = externalLegend;
                        newPlot->internalLegend = internalLegend;
                        internalLegend->attach(newPlot);
                        internalLegend->setBorderRadius( 4 );
                        internalLegend->setMargin( 0 );
                        internalLegend->setSpacing( 4 );
                        internalLegend->setItemMargin( 2 );
                        internalLegend->setMaxColumns(4);
                        internalLegend->setAlignment(Qt::AlignBottom|Qt::AlignRight);
                        extInt = legend.attribute("extInt");
                        if(extInt == "ext")
                        {
                            internalLegend->setVisible(false);
                            externalLegend = new QwtLegend();
                            extPos = legend.attribute("extPos");//0=L, 1=R, 2=B, 3=T
                            newPlot->insertLegend(externalLegend,QwtPlot::LegendPosition(extPos.toInt()));
                        }
                        else if(extInt == "int")
                        {
                            internalLegend->setVisible(true);
                            nCol = legend.attribute("nCol");
                            legendSize = legend.attribute("legendSize");

                            // other setting
                            newPlot->internalLegend->setMaxColumns(nCol.toInt());
                            QFont font = newPlot->internalLegend->font();
                            font.setPointSize( legendSize.toInt());
                            newPlot->internalLegend->setFont( font );
                        }
                    }
                }

                //grid
                if(currentPlot.elementsByTagName("grid").count()>0)
                {
                    grid = currentPlot.elementsByTagName("grid").at(0).toElement();
                    QString xMaj, yMaj, xMin, yMin, majColor, minColor, majSize, minSize, majStyle, minStyle;
                    xMaj = grid.attribute("xMaj");
                    yMaj = grid.attribute("yMaj");
                    xMin = grid.attribute("xMin");
                    yMin = grid.attribute("yMin");
                    majColor = grid.attribute("majColor");
                    minColor = grid.attribute("minColor");
                    majSize = grid.attribute("majSize");
                    minSize = grid.attribute("minSize");
                    majStyle = grid.attribute("majStyle");
                    minStyle = grid.attribute("minStyle");
                    newPlot->grid->enableX(xMaj=="on");
                    newPlot->grid->enableY(yMaj == "on");
                    newPlot->grid->enableXMin(xMin=="on");
                    newPlot->grid->enableYMin(yMin=="on");
                    if(newPlot->grid->xEnabled()||newPlot->grid->yEnabled())
                        newPlot->grid->setMajorPen(QColor(majColor),majSize.toInt(),Qt::PenStyle(majStyle.toInt()));
                    if(newPlot->grid->xMinEnabled()||newPlot->grid->yMinEnabled())
                        newPlot->grid->setMinorPen(QColor(minColor),minSize.toInt(),Qt::PenStyle(minStyle.toInt()));
                }

                //curve
                if(currentPlot.elementsByTagName("curve").count()>0)
                {
                    curve = currentPlot.elementsByTagName("curve").at(0).toElement();
                    if(curve.childNodes().count()==newPlot->curvelist.count())
                    {
                        QDomElement currentCurve;
                        QwtPlotCurve *thisCurve;
                        QString lineColor, lineSize, lineType, isVisible;
                        for(int i = 0; i < newPlot->curvelist.count(); i++)
                        {
                            currentCurve = curve.elementsByTagName(newPlot->curvelist[i]->title().text().replace(" ","")).at(0).toElement();
                            thisCurve = newPlot->curvelist[i];
                            lineColor = currentCurve.attribute("lineColor");
                            lineSize = currentCurve.attribute("lineSize");
                            lineType = currentCurve.attribute("lineType");
                            isVisible = currentCurve.attribute("isVisible");
                            thisCurve->setPen(QColor(lineColor),lineSize.toInt(),Qt::PenStyle(lineType.toInt()));
                            if(isVisible=="true")
                                thisCurve->setVisible(true);
                            else if(isVisible=="false")
                                thisCurve->setVisible(false);
                        }
                    }
                }


                tabs->insertTab(-1,newPlot,currentPlot.tagName());
                newPlot->replot();
            }
            file.close();
            return true;
        }
    }
}
Ejemplo n.º 13
0
// Protected "real" constructor
// All paths are initialized to compile-time defaults passed in
// as preprocessor macros and set by autoconf.
ScPaths::ScPaths() :
	m_docDir(DOCDIR),
	m_iconDir(ICONDIR),
	m_libDir(LIBDIR),
	m_pluginDir(PLUGINDIR),
	m_sampleScriptDir(SAMPLESDIR),
	m_scriptDir(SCRIPTSDIR),
	m_templateDir(TEMPLATEDIR),
	m_shareDir(SHAREDIR)
{
// On MacOS/X, override the compile-time settings with a location
// obtained from the system.
#ifdef Q_WS_MAC
	QString pathPtr(bundleDir());
	/*
	// Set up the various app paths to look inside the app bundle
	CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
	CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
	                                       kCFURLPOSIXPathStyle);
	const char *pathPtr = CFStringGetCStringPtr(macPath,
	                                       CFStringGetSystemEncoding());

	// make sure we get the Scribus.app directory, not some subdir

	// strip trailing '/':
	char *p = const_cast<char*>(pathPtr + strlen(pathPtr) - 1);
	while (*p == '/')
		--p;
	++p;
	*p = '\0';
	if (strcmp("/bin", p-4) == 0) {
		p -= 4;
		*p = '\0';
	}
	if (strcmp("/MacOS", p-6) == 0) {
		p -= 6;
		*p = '\0';
	}
	if (strcmp("/Contents", p-9) == 0) {
		p -= 9;
		*p = '\0';
	}
*/
	qDebug() << QString("scpaths: bundle at %1:").arg(pathPtr);
	m_shareDir = QString("%1/Contents/share/scribus/").arg(pathPtr);
	m_docDir = QString("%1/Contents/share/doc/scribus/").arg(pathPtr);
	m_iconDir = QString("%1/Contents/share/scribus/icons/").arg(pathPtr);
	m_sampleScriptDir = QString("%1/Contents/share/scribus/samples/").arg(pathPtr);
	m_scriptDir = QString("%1/Contents/share/scribus/scripts/").arg(pathPtr);
	m_templateDir = QString("%1/Contents/share/scribus/templates/").arg(pathPtr);
	m_libDir = QString("%1/Contents/lib/scribus/").arg(pathPtr);
	m_pluginDir = QString("%1/Contents/lib/scribus/plugins/").arg(pathPtr);
	QApplication::setLibraryPaths(QStringList(QString("%1/Contents/lib/qtplugins/").arg(pathPtr)));
//	CFRelease(pluginRef);
//	CFRelease(macPath);

	// on OSX this goes to the sys console, so user only sees it when they care -- AV
	qDebug() << QString("scpaths: doc dir=%1").arg(m_docDir);
	qDebug() << QString("scpaths: icon dir=%1").arg(m_iconDir);
	qDebug() << QString("scpaths: font dir=%1").arg(m_fontDir);
	qDebug() << QString("scpaths: sample dir=%1").arg(m_sampleScriptDir);
	qDebug() << QString("scpaths: script dir=%1").arg(m_scriptDir);
	qDebug() << QString("scpaths: template dir=%1").arg(m_templateDir);
	qDebug() << QString("scpaths: lib dir=%1").arg(m_libDir);
	qDebug() << QString("scpaths: plugin dir=%1").arg(m_pluginDir);
	qDebug() << QString("scpaths: qtplugins=%1").arg(QApplication::libraryPaths().join(":"));

#elif defined(_WIN32)
	QString appPath = qApp->applicationDirPath();
	m_shareDir = QString("%1/share/").arg(appPath);
	m_docDir = QString("%1/share/doc/").arg(appPath);
	m_fontDir = QString("%1/share/fonts/").arg(appPath);
	m_iconDir = QString("%1/share/icons/").arg(appPath);
	m_sampleScriptDir = QString("%1/share/samples/").arg(appPath);
	m_scriptDir = QString("%1/share/scripts/").arg(appPath);
	m_templateDir = QString("%1/share/templates/").arg(appPath);
	m_libDir = QString("%1/libs/").arg(appPath);
	m_pluginDir = QString("%1/plugins/").arg(appPath);
	QApplication::setLibraryPaths( QStringList(QString("%1/qtplugins/").arg(appPath)) );
#endif
	
// 	if(!m_shareDir.endsWith("/"))        m_shareDir += "/";
// 	if(!m_docDir.endsWith("/"))          m_docDir += "/";
// 	if(!m_fontDir.endsWith("/"))         m_fontDir += "/";
	if(!m_iconDir.endsWith("/"))         m_iconDir += "/";
// 	if(!m_sampleScriptDir.endsWith("/")) m_sampleScriptDir += "/";
// 	if(!m_scriptDir.endsWith("/"))       m_scriptDir += "/";
// 	if(!m_templateDir.endsWith("/"))     m_templateDir += "/";
// 	if(!m_libDir.endsWith("/"))          m_libDir += "/";
// 	if(!m_pluginDir.endsWith("/"))       m_pluginDir += "/";
}