mirror of https://github.com/KLayout/klayout.git
WIP: documentation URL's of packages can be relative
If the documentation URL is relative it's either taken relative to the package installation path or to the download URL. This means that documentation can be inside the package now.
This commit is contained in:
parent
0b7beee12d
commit
1a9b5ead09
|
|
@ -29,6 +29,7 @@
|
|||
#include <QFileInfo>
|
||||
#include <QBuffer>
|
||||
#include <QResource>
|
||||
#include <QUrl>
|
||||
|
||||
namespace lay
|
||||
{
|
||||
|
|
@ -109,6 +110,38 @@ SaltGrain::set_doc_url (const std::string &u)
|
|||
m_doc_url = u;
|
||||
}
|
||||
|
||||
std::string
|
||||
SaltGrain::eff_doc_url () const
|
||||
{
|
||||
if (m_doc_url.empty ()) {
|
||||
return std::string ();
|
||||
}
|
||||
|
||||
QUrl url (tl::to_qstring (m_doc_url));
|
||||
if (! url.scheme ().isEmpty ()) {
|
||||
return m_doc_url;
|
||||
}
|
||||
|
||||
if (! path ().empty ()) {
|
||||
|
||||
// if the URL is a relative URL, make it absolute relative to the grain's installation directory
|
||||
QFileInfo fi (url.toLocalFile ());
|
||||
if (! fi.isAbsolute ()) {
|
||||
url = QUrl::fromLocalFile (QDir (tl::to_qstring (path ())).absoluteFilePath (fi.filePath ()));
|
||||
}
|
||||
url.setScheme (tl::to_qstring ("file"));
|
||||
return tl::to_string (url.toString ());
|
||||
|
||||
} else {
|
||||
|
||||
// base the documentation URL on the download URL
|
||||
QUrl eff_url = QUrl (tl::to_qstring (m_url));
|
||||
eff_url.setPath (eff_url.path () + QString::fromUtf8 ("/") + url.path ());
|
||||
return tl::to_string (eff_url.toString ());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SaltGrain::set_author (const std::string &a)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -145,6 +145,14 @@ public:
|
|||
*/
|
||||
void set_doc_url (const std::string &u);
|
||||
|
||||
/**
|
||||
* @brief Gets the effective documentation URL
|
||||
*
|
||||
* The effective documentation URL is formed from the installation path
|
||||
* and the documentation URL if the latter is a relative one.
|
||||
*/
|
||||
std::string eff_doc_url () const;
|
||||
|
||||
/**
|
||||
* @brief Gets the version of the grain
|
||||
*
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
#include <QPainter>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QDesktopServices>
|
||||
|
||||
namespace lay
|
||||
{
|
||||
|
|
@ -37,7 +38,9 @@ namespace lay
|
|||
SaltGrainDetailsTextWidget::SaltGrainDetailsTextWidget (QWidget *w)
|
||||
: QTextBrowser (w), mp_grain (0)
|
||||
{
|
||||
// .. nothing yet ..
|
||||
setOpenLinks (false);
|
||||
setOpenExternalLinks (false);
|
||||
connect (this, SIGNAL (anchorClicked (const QUrl &)), this, SLOT (open_link (const QUrl &)));
|
||||
}
|
||||
|
||||
void SaltGrainDetailsTextWidget::set_grain (SaltGrain *g)
|
||||
|
|
@ -46,6 +49,12 @@ void SaltGrainDetailsTextWidget::set_grain (SaltGrain *g)
|
|||
setHtml (details_text ());
|
||||
}
|
||||
|
||||
void
|
||||
SaltGrainDetailsTextWidget::open_link (const QUrl &url)
|
||||
{
|
||||
QDesktopServices::openUrl (url);
|
||||
}
|
||||
|
||||
QVariant
|
||||
SaltGrainDetailsTextWidget::loadResource (int type, const QUrl &url)
|
||||
{
|
||||
|
|
@ -237,7 +246,7 @@ SaltGrainDetailsTextWidget::details_text ()
|
|||
|
||||
stream << "<p>";
|
||||
if (! g->doc_url ().empty ()) {
|
||||
stream << "<b>" << QObject::tr ("Documentation link") << ":</b> <a href=\"" << tl::to_qstring (g->doc_url ()) << "\">" << tl::to_qstring (tl::escaped_to_html (g->doc_url ())) << "</a>";
|
||||
stream << "<b>" << QObject::tr ("Documentation link") << ":</b> <a href=\"" << tl::to_qstring (g->eff_doc_url ()) << "\">" << tl::to_qstring (tl::escaped_to_html (g->eff_doc_url ())) << "</a>";
|
||||
} else {
|
||||
stream << "<i><font color='gray'>";
|
||||
stream << QObject::tr ("This package does not have a documentation link. "
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ class SaltGrain;
|
|||
class SaltGrainDetailsTextWidget
|
||||
: public QTextBrowser
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
|
|
@ -50,6 +52,9 @@ public:
|
|||
protected:
|
||||
virtual QVariant loadResource (int type, const QUrl &url);
|
||||
|
||||
private slots:
|
||||
void open_link (const QUrl &url);
|
||||
|
||||
private:
|
||||
lay::SaltGrain *mp_grain;
|
||||
|
||||
|
|
|
|||
|
|
@ -327,7 +327,8 @@ void
|
|||
SaltGrainPropertiesDialog::url_changed (const QString &url)
|
||||
{
|
||||
// inserts the URL into the label
|
||||
open_label->setText (m_open_label.arg (url));
|
||||
m_grain.set_doc_url (tl::to_string (url));
|
||||
open_label->setText (m_open_label.arg (tl::to_qstring (m_grain.eff_doc_url ())));
|
||||
open_label->setEnabled (! url.isEmpty ());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue