MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
#ifdef WITH_QUICKWIDGET
view = new QQuickWidget();
ui->verticalLayout->addWidget(view);
#else
view = new QQuickView();
ui->verticalLayout->addWidget(container);
#endif
mapApiKey
= QString::fromLatin1("AIzaSyAOeIxkqfAs9HQrz_PY7QPz7ZzKiML7hDE");
loadHtml();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::loadHtml()
{
QString htmlData
= loadFileData
(QString::fromLatin1(":/web/map.html"));
htmlData.
replace(QLatin1String("$$WEB_DIR"),
QUrl::fromLocalFile(m_webDir
).
toString());
m_filePath = saveFile( htmlData, htmlfname);
QObject *object
= view
->rootObject
();
QQmlProperty
::write(object,
QString::fromLatin1("url"),
QUrl::fromLocalFile(m_filePath
).
toString());
}
{
data = txt.readAll();
readfile.close();
}
return data;
}
{
txt << htmldata;
writefile.close();
}
return mpath;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
#ifdef WITH_QUICKWIDGET
view = new QQuickWidget();
ui->verticalLayout->addWidget(view);
#else
view = new QQuickView();
QWidget* container = QWidget::createWindowContainer(view);
ui->verticalLayout->addWidget(container);
#endif
view->setSource(QUrl::fromLocalFile(QLatin1String(":/web/weblink.qml")));
mapApiKey = QString::fromLatin1("AIzaSyAOeIxkqfAs9HQrz_PY7QPz7ZzKiML7hDE");
m_webDir = QDir::homePath()+QString::fromLatin1("/") ;
loadHtml();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::loadHtml()
{
QString htmlData = loadFileData(QString::fromLatin1(":/web/map.html"));
htmlData.replace(QLatin1String("$$API_KEY"),mapApiKey);
htmlData.replace(QLatin1String("$$PORT"),QLatin1String("1000"));
htmlData.replace(QLatin1String("$$WEB_DIR"),QUrl::fromLocalFile(m_webDir).toString());
QString htmlfname = QString::fromLatin1("map_%1.html").arg(QDateTime::currentMSecsSinceEpoch());
htmlData.replace(QLatin1String("$$MAP_HTML"),htmlfname);
m_filePath = saveFile( htmlData, htmlfname);
if(!QFileInfo::exists(m_webDir + QString::fromLatin1("jquery.min.js")))
QFile::copy(QLatin1String(":/web/jquery.min.js") , m_webDir+QLatin1String("jquery.min.js"));
if(!QFileInfo::exists(m_webDir + QString::fromLatin1("label.js")))
QFile::copy(QLatin1String(":/web/label.js") , m_webDir+QLatin1String("label.js"));
QObject *object = view->rootObject();
QQmlProperty::write(object, QString::fromLatin1("url"), QUrl::fromLocalFile(m_filePath).toString());
}
QString MainWindow::loadFileData(QString path)
{
QString data;
QFile readfile(path);
if(readfile.open(QIODevice::ReadOnly)){
QTextStream txt(&readfile);
data = txt.readAll();
readfile.close();
}
return data;
}
QString MainWindow::saveFile(QString htmldata, QString fname)
{
QString mpath= m_webDir+fname;
QFile writefile(mpath);
if(writefile.open(QIODevice::WriteOnly)){
QTextStream txt(&writefile);
txt << htmldata;
writefile.close();
}
return mpath;
}
To copy to clipboard, switch view to plain text mode
Bookmarks