QElectroTech  0.70
templatelocation.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "templatelocation.h"
19 #include "templatescollection.h"
20 #include "qetapp.h"
21 
22 // make this class usable with QVariant
23 int TitleBlockTemplateLocation::MetaTypeId = qRegisterMetaType<TitleBlockTemplateLocation>("TitleBlockTemplateLocation");
24 
31  collection_(collection),
32  name_(name)
33 {
34 }
35 
40 }
41 
47  loc.fromString(loc_str);
48  return(loc);
49 }
50 
55  return(collection_);
56 }
57 
63  collection_ = collection;
64 }
65 
70  return(name_);
71 }
72 
76 void TitleBlockTemplateLocation::setName(const QString &name) {
77  name_ = name;
78 }
79 
84  return(!name_.isEmpty());
85 }
86 
90 void TitleBlockTemplateLocation::fromString(const QString &loc_str) {
91  collection_ = QETApp::titleBlockTemplatesCollection(QUrl(loc_str).scheme());
92 
93  QRegExp name_from_url("^[^:]*:\\/\\/(.*)$");
94  if (name_from_url.exactMatch(loc_str)) {
95  name_ = name_from_url.capturedTexts().at(1);
96  } else {
97  name_ = QString();
98  }
99 }
100 
105  return(protocol() + QString("://") + name_);
106 }
107 
113  if (collection_) {
114  return(collection_ -> parentProject());
115  }
116  return(nullptr);
117 }
118 
124  if (collection_) {
125  return(collection_ -> protocol());
126  }
127  return("unknown");
128 }
129 
135  if (!collection_ || name_.isEmpty()) return(QDomElement());
137 }
138 
144  if (!collection_ || name_.isEmpty()) return(nullptr);
145  return(collection_ -> getTemplate(name_));
146 }
147 
153  if (!collection_) return(false);
154  return(collection_ -> isReadOnly(name_));
155 }
156 
162  return(location.collection_ == collection_ && location.name_ == name_);
163 }
164 
169 uint qHash(const TitleBlockTemplateLocation &location) {
170  return(qHash(location.toString()));
171 }
TitleBlockTemplatesCollection * collection_
Collection the template belongs to.
void setName(const QString &)
QDomElement getTemplateXmlDescription() const
QString name_
Name of the template.
void fromString(const QString &)
TitleBlockTemplateLocation locationFromString(const QString &)
QETProject * parentProject() const
static TitleBlockTemplatesCollection * titleBlockTemplatesCollection(const QString &)
Definition: qetapp.cpp:493
void setParentCollection(TitleBlockTemplatesCollection *)
TitleBlockTemplatesCollection * parentCollection() const
static int MetaTypeId
Id of the corresponding Qt meta type.
TitleBlockTemplate * getTemplate() const
uint qHash(const TitleBlockTemplateLocation &location)
bool operator==(const TitleBlockTemplateLocation &) const
TitleBlockTemplateLocation(const QString &=QString(), TitleBlockTemplatesCollection *=nullptr)