2011-12-26 05:42:48 +00:00
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
2011-12-26 05:42:48 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "templatelocation.h"
|
2012-01-08 17:04:34 +00:00
|
|
|
#include "templatescollection.h"
|
|
|
|
#include "qetapp.h"
|
2011-12-26 05:42:48 +00:00
|
|
|
|
2012-01-18 19:53:27 +00:00
|
|
|
// make this class usable with QVariant
|
2012-02-05 19:24:42 +00:00
|
|
|
int TitleBlockTemplateLocation::MetaTypeId = qRegisterMetaType<TitleBlockTemplateLocation>("TitleBlockTemplateLocation");
|
2012-01-18 19:53:27 +00:00
|
|
|
|
2011-12-26 05:42:48 +00:00
|
|
|
/**
|
|
|
|
Constructor
|
2012-01-08 17:04:34 +00:00
|
|
|
@param collection Parent collection of the title block template
|
2011-12-26 05:42:48 +00:00
|
|
|
@param name Name of the title block template within its parent project or collection
|
|
|
|
*/
|
2012-01-08 17:04:34 +00:00
|
|
|
TitleBlockTemplateLocation::TitleBlockTemplateLocation(const QString &name, TitleBlockTemplatesCollection *collection) :
|
|
|
|
collection_(collection),
|
2011-12-26 05:42:48 +00:00
|
|
|
name_(name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor
|
|
|
|
*/
|
|
|
|
TitleBlockTemplateLocation::~TitleBlockTemplateLocation() {
|
|
|
|
}
|
|
|
|
|
2012-01-15 19:26:40 +00:00
|
|
|
/**
|
|
|
|
@param loc_str String describing the location of a title block template.
|
|
|
|
*/
|
|
|
|
TitleBlockTemplateLocation TitleBlockTemplateLocation::locationFromString(const QString &loc_str) {
|
|
|
|
TitleBlockTemplateLocation loc;
|
|
|
|
loc.fromString(loc_str);
|
|
|
|
return(loc);
|
|
|
|
}
|
|
|
|
|
2011-12-26 05:42:48 +00:00
|
|
|
/**
|
2012-01-08 17:04:34 +00:00
|
|
|
@return the parent collection of the template, or 0 if none was defined
|
2011-12-26 05:42:48 +00:00
|
|
|
*/
|
2012-01-08 17:04:34 +00:00
|
|
|
TitleBlockTemplatesCollection *TitleBlockTemplateLocation::parentCollection() const {
|
|
|
|
return(collection_);
|
2011-12-26 05:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-08 17:04:34 +00:00
|
|
|
@param project The new parent collection of the template, or 0 if none
|
2011-12-26 05:42:48 +00:00
|
|
|
applies.
|
|
|
|
*/
|
2012-01-08 17:04:34 +00:00
|
|
|
void TitleBlockTemplateLocation::setParentCollection(TitleBlockTemplatesCollection *collection) {
|
|
|
|
collection_ = collection;
|
2011-12-26 05:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return the name of this template within its parent project or collection.
|
|
|
|
*/
|
|
|
|
QString TitleBlockTemplateLocation::name() const {
|
|
|
|
return(name_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param name The new name of this template.
|
|
|
|
*/
|
|
|
|
void TitleBlockTemplateLocation::setName(const QString &name) {
|
|
|
|
name_ = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return true if this location is null, false otherwise
|
|
|
|
*/
|
|
|
|
bool TitleBlockTemplateLocation::isValid() const {
|
2012-01-08 17:04:34 +00:00
|
|
|
return(!name_.isEmpty());
|
|
|
|
}
|
|
|
|
|
2012-01-15 19:26:40 +00:00
|
|
|
/**
|
|
|
|
@param loc_str String describing the location of a title block template.
|
|
|
|
*/
|
|
|
|
void TitleBlockTemplateLocation::fromString(const QString &loc_str) {
|
|
|
|
collection_ = QETApp::titleBlockTemplatesCollection(QUrl(loc_str).scheme());
|
|
|
|
|
|
|
|
QRegExp name_from_url("^[^:]*:\\/\\/(.*)$");
|
|
|
|
if (name_from_url.exactMatch(loc_str)) {
|
|
|
|
name_ = name_from_url.capturedTexts().at(1);
|
|
|
|
} else {
|
|
|
|
name_ = QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-08 17:04:34 +00:00
|
|
|
/**
|
|
|
|
@return A string representation of the location
|
|
|
|
*/
|
|
|
|
QString TitleBlockTemplateLocation::toString() const {
|
|
|
|
return(protocol() + QString("://") + name_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
This is a convenience method equivalent to
|
|
|
|
parentCollection() -> parentProject().
|
|
|
|
*/
|
|
|
|
QETProject *TitleBlockTemplateLocation::parentProject() const {
|
|
|
|
if (collection_) {
|
|
|
|
return(collection_ -> parentProject());
|
|
|
|
}
|
2017-08-05 02:06:59 +00:00
|
|
|
return(nullptr);
|
2012-01-08 17:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
This is a convenience method equivalent to
|
|
|
|
parentCollection() -> protocol().
|
|
|
|
*/
|
|
|
|
QString TitleBlockTemplateLocation::protocol() const {
|
|
|
|
if (collection_) {
|
|
|
|
return(collection_ -> protocol());
|
|
|
|
}
|
|
|
|
return("unknown");
|
|
|
|
}
|
|
|
|
|
2012-01-18 19:53:27 +00:00
|
|
|
/**
|
|
|
|
This is a convenience method equivalent to
|
|
|
|
parentCollection() -> getTemplateXmlDescription
|
|
|
|
*/
|
|
|
|
QDomElement TitleBlockTemplateLocation::getTemplateXmlDescription() const {
|
|
|
|
if (!collection_ || name_.isEmpty()) return(QDomElement());
|
|
|
|
return(collection_ -> getTemplateXmlDescription(name_));
|
|
|
|
}
|
|
|
|
|
2012-01-08 17:04:34 +00:00
|
|
|
/**
|
|
|
|
This is a convenience method equivalent to
|
|
|
|
parentCollection() -> getTemplate(...).
|
|
|
|
*/
|
|
|
|
TitleBlockTemplate *TitleBlockTemplateLocation::getTemplate() const {
|
2017-08-05 02:06:59 +00:00
|
|
|
if (!collection_ || name_.isEmpty()) return(nullptr);
|
2012-01-08 17:04:34 +00:00
|
|
|
return(collection_ -> getTemplate(name_));
|
2011-12-26 05:42:48 +00:00
|
|
|
}
|
2012-01-23 07:20:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
This is a convenience method equivalent to
|
|
|
|
parentCollection() -> isReadOnly(name())
|
|
|
|
*/
|
|
|
|
bool TitleBlockTemplateLocation::isReadOnly() const {
|
|
|
|
if (!collection_) return(false);
|
|
|
|
return(collection_ -> isReadOnly(name_));
|
|
|
|
}
|
2012-01-23 20:36:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
@param location other location that should be compared to this one
|
|
|
|
@return true if locations are equal, false otherwise
|
|
|
|
*/
|
|
|
|
bool TitleBlockTemplateLocation::operator==(const TitleBlockTemplateLocation &location) const {
|
|
|
|
return(location.collection_ == collection_ && location.name_ == name_);
|
|
|
|
}
|
|
|
|
|
2012-02-05 19:24:42 +00:00
|
|
|
/**
|
|
|
|
@param location A standard title block template location
|
|
|
|
@return a hash identifying this location
|
|
|
|
*/
|
|
|
|
uint qHash(const TitleBlockTemplateLocation &location) {
|
|
|
|
return(qHash(location.toString()));
|
|
|
|
}
|