[qet] [1474] Improved isReadOnly() methods for templates collections.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1474
Author:   xavier
Date:     2012-01-23 08:20:07 +0100 (Mon, 23 Jan 2012)
Log Message:
-----------
Improved isReadOnly() methods for templates collections.

Modified Paths:
--------------
    branches/0.3/sources/titleblock/templatelocation.cpp
    branches/0.3/sources/titleblock/templatelocation.h
    branches/0.3/sources/titleblock/templatescollection.cpp
    branches/0.3/sources/titleblock/templatescollection.h

Modified: branches/0.3/sources/titleblock/templatelocation.cpp
===================================================================
--- branches/0.3/sources/titleblock/templatelocation.cpp	2012-01-22 14:35:57 UTC (rev 1473)
+++ branches/0.3/sources/titleblock/templatelocation.cpp	2012-01-23 07:20:07 UTC (rev 1474)
@@ -144,3 +144,12 @@
 	if (!collection_ || name_.isEmpty()) return(0);
 	return(collection_ -> getTemplate(name_));
 }
+
+/**
+	This is a convenience method equivalent to
+	parentCollection() -> isReadOnly(name())
+*/
+bool TitleBlockTemplateLocation::isReadOnly() const {
+	if (!collection_) return(false);
+	return(collection_ -> isReadOnly(name_));
+}

Modified: branches/0.3/sources/titleblock/templatelocation.h
===================================================================
--- branches/0.3/sources/titleblock/templatelocation.h	2012-01-22 14:35:57 UTC (rev 1473)
+++ branches/0.3/sources/titleblock/templatelocation.h	2012-01-23 07:20:07 UTC (rev 1474)
@@ -49,6 +49,7 @@
 	QString protocol() const;
 	QDomElement getTemplateXmlDescription() const;
 	TitleBlockTemplate *getTemplate() const;
+	bool isReadOnly() const;
 	
 	// attributes
 	private:

Modified: branches/0.3/sources/titleblock/templatescollection.cpp
===================================================================
--- branches/0.3/sources/titleblock/templatescollection.cpp	2012-01-22 14:35:57 UTC (rev 1473)
+++ branches/0.3/sources/titleblock/templatescollection.cpp	2012-01-23 07:20:07 UTC (rev 1474)
@@ -257,9 +257,12 @@
 }
 
 /**
-	@return true if this collection is read only
+	@param template_name Either an empty QString to know whether the collection
+	itself is read only, or a specific template name.
+	@return true if the specified template is read only, false otherwise
 */
-bool TitleBlockTemplatesProjectCollection::isReadOnly() const {
+bool TitleBlockTemplatesProjectCollection::isReadOnly(const QString &template_name) const {
+	Q_UNUSED(template_name)
 	if (project_) {
 		return(project_ -> isReadOnly());
 	}
@@ -431,11 +434,18 @@
 }
 
 /**
-	@return true if this collection is read only, false otherwise
+	@param template_name Either an empty QString to know whether the collection
+	itself is read only, or a specific template name.
+	@return true if the specified template is read only, false otherwise
 */
-bool TitleBlockTemplatesFilesCollection::isReadOnly() const {
-	QFileInfo info(dir_.canonicalPath());
-	return(!info.isWritable());
+bool TitleBlockTemplatesFilesCollection::isReadOnly(const QString &template_name) const {
+	if (template_name.isEmpty()) {
+		QFileInfo info(dir_.canonicalPath());
+		return(!info.isWritable());
+	} else {
+		QFileInfo info(dir_.absoluteFilePath(toFileName(template_name)));
+		return(!info.isWritable());
+	}
 }
 
 /**

Modified: branches/0.3/sources/titleblock/templatescollection.h
===================================================================
--- branches/0.3/sources/titleblock/templatescollection.h	2012-01-22 14:35:57 UTC (rev 1473)
+++ branches/0.3/sources/titleblock/templatescollection.h	2012-01-23 07:20:07 UTC (rev 1474)
@@ -48,7 +48,7 @@
 	virtual bool setTemplateXmlDescription(const QString &, const QDomElement &) = 0;
 	virtual void removeTemplate(const QString &) = 0;
 	virtual TitleBlockTemplateLocation location(const QString & = QString()) = 0;
-	virtual bool isReadOnly() const = 0;
+	virtual bool isReadOnly(const QString & = QString()) const = 0;
 	virtual QString title() const;
 	virtual void setTitle(const QString &);
 	virtual QString protocol() const;
@@ -94,7 +94,7 @@
 	virtual bool setTemplateXmlDescription(const QString &, const QDomElement &);
 	virtual void removeTemplate(const QString &);
 	virtual TitleBlockTemplateLocation location(const QString & = QString());
-	virtual bool isReadOnly() const;
+	virtual bool isReadOnly(const QString & = QString()) const;
 	virtual void fromXml(const QDomElement &);
 	
 	// attributes
@@ -130,7 +130,7 @@
 	virtual bool setTemplateXmlDescription(const QString &, const QDomElement &);
 	virtual void removeTemplate(const QString &);
 	virtual TitleBlockTemplateLocation location(const QString & = QString());
-	virtual bool isReadOnly() const;
+	virtual bool isReadOnly(const QString & = QString()) const;
 	
 	static QString toTemplateName(const QString &);
 	static QString toFileName(const QString &);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/