r16863 by craig - Tables: Add fix cell area saving, and now load tables and cell areas. Some hacks in saxx

scribus-commit scribus-commit at lists.scribus.net
Fri Sep 30 15:53:22 UTC 2011


Author: craig
Date: Fri Sep 30 15:53:22 2011
New Revision: 16863

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=16863
Log:
Tables: Add fix cell area saving, and now load tables and cell areas. Some hacks in saxx

Modified:
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
    trunk/Scribus/scribus/styles/charstyle.h
    trunk/Scribus/scribus/styles/paragraphstyle.h
    trunk/Scribus/scribus/styles/tablestyle.cpp
    trunk/Scribus/scribus/styles/tablestyle.h

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16863&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp Fri Sep 30 15:53:22 2011
@@ -31,6 +31,7 @@
 #ifdef HAVE_OSG
 	#include "pageitem_osgframe.h"
 #endif
+#include "pageitem_table.h"
 #include "pageitem_regularpolygon.h"
 #include "pageitem_arc.h"
 #include "pageitem_spiral.h"
@@ -3399,13 +3400,6 @@
 		if (pagenr > -2) 
 			currItem->OwnPage = pagenr;
 		break;
-	case PageItem::Table:
-		// TODO: Actually handle pasting of tables properly.
-		z = doc->itemAdd(PageItem::Table, PageItem::Unspecified, x, y, w, h, 0.0, CommonStrings::None, CommonStrings::None, true);
-		currItem = doc->Items->at(z);
-		if (pagenr > -2)
-			currItem->OwnPage = pagenr;
-		break;
 	case PageItem::Line:
 		z = doc->itemAdd(PageItem::Line, PageItem::Unspecified, x, y, w, h, pw, CommonStrings::None, Pcolor2, true);
 		currItem = doc->Items->at(z);
@@ -3456,6 +3450,13 @@
 		z = doc->itemAdd(PageItem::Spiral, PageItem::Unspecified, x, y, w, h, pw, Pcolor, Pcolor2, true);
 		currItem = doc->Items->at(z);
 		if (pagenr > -2) 
+			currItem->OwnPage = pagenr;
+		break;
+	case PageItem::Table:
+		// TODO: Actually handle pasting of tables properly.
+		z = doc->itemAdd(PageItem::Table, PageItem::Unspecified, x, y, w, h, 0.0, CommonStrings::None, CommonStrings::None, true);
+		currItem = doc->Items->at(z);
+		if (pagenr > -2)
 			currItem->OwnPage = pagenr;
 		break;
 	case PageItem::Multiple:
@@ -3661,6 +3662,57 @@
 		UndoManager::instance()->setUndoEnabled(true);
 	}
 
+	if (currItem->asTable())
+	{
+		PageItem_Table *tableitem = currItem->asTable();
+		int rows=attrs.valueAsInt("Rows",1);
+		int cols=attrs.valueAsInt("Columns",1);
+		tableitem->insertRows(1,rows-1);
+		tableitem->insertColumns(1,cols-1);
+		tableitem->setStyle(attrs.valueAsString("TableStyle"));
+//		QString rowPositions(attrs.valueAsString("RowPositions"));
+//		QStringList slRowPositions=rowPositions.split(" ");
+//		qDebug()<<"RowCount"<<rows<<"row positions"<<slRowPositions.count();
+
+		QString rowHeights(attrs.valueAsString("RowHeights",""));
+		if(!rowHeights.isEmpty())
+		{
+			QStringList slRowHeights=rowHeights.split(" ");
+			int i=0;
+			foreach(QString pos, slRowHeights)
+			{
+				tableitem->resizeRow(i++, pos.toDouble());
+			}
+		}
+//		QString colPositions(attrs.valueAsString("ColumnPositions"));
+//		QStringList slColPositions=colPositions.split(" ");
+		QString colWidths(attrs.valueAsString("ColumnWidths",""));
+		if(!colWidths.isEmpty())
+		{
+			QStringList slColWidths=colWidths.split(" ");
+			int j=0;
+			foreach(QString pos, slColWidths)
+			{
+				tableitem->resizeColumn(j++, pos.toDouble());
+			}
+		}
+		QString cellAreas(attrs.valueAsString("CellAreas"));
+		if(!cellAreas.isEmpty())
+		{
+			QStringList slCellAreas=cellAreas.split(" ");
+			if (slCellAreas.count()%4!=0)
+				qDebug()<<"Cell Area Count on load ! % 4";
+			for (int i = 0; i < slCellAreas.size(); i+=4)
+			{
+				int rows=slCellAreas.at(i).toInt();
+				int columns=slCellAreas.at(i+1).toInt();
+				int height=slCellAreas.at(i+2).toInt();
+				int width=slCellAreas.at(i+3).toInt();
+				tableitem->mergeCells(rows,columns,height,width);
+			}
+		}
+	}
+
 	currItem->TopLine      = attrs.valueAsBool("TopLine", false);
 	currItem->LeftLine     = attrs.valueAsBool("LeftLine", false);
 	currItem->RightLine    = attrs.valueAsBool("RightLine", false);

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16863&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp Fri Sep 30 15:53:22 2011
@@ -2092,7 +2092,6 @@
 			outputData += tmp.setNum(value) + " ";
 		docu.writeAttribute("RowPositions", outputData.simplified());
 		outputData.clear();
-
 		//Row Heights
 		foreach(qreal value, tableItem->rowHeights())
 			outputData += tmp.setNum(value) + " ";
@@ -2109,10 +2108,14 @@
 		docu.writeAttribute("ColumnWidths", outputData.simplified());
 		outputData.clear();
 		//Cell Areas
+		//TODO Is this the best format to write these out?
+		QString tmp1,tmp2,tmp3,tmp4;
 		foreach(CellArea ca, tableItem->cellAreas())
-			outputData += tmp.setNum(ca.row()) + " " + tmp.setNum(ca.column()) + " " + tmp.setNum(ca.height()) + " " + tmp.setNum(ca.width()) + " ";
+			outputData += tmp1.setNum(ca.row()) + " " + tmp2.setNum(ca.column()) + " " + tmp3.setNum(ca.height()) + " " + tmp4.setNum(ca.width()) + " ";
 		docu.writeAttribute("CellAreas", outputData.simplified());
 		outputData.clear();
+
+		docu.writeAttribute("TableStyle",tableItem->style());
 	}
 
 	if (item->isGroup())

Modified: trunk/Scribus/scribus/styles/charstyle.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16863&path=/trunk/Scribus/scribus/styles/charstyle.h
==============================================================================
--- trunk/Scribus/scribus/styles/charstyle.h (original)
+++ trunk/Scribus/scribus/styles/charstyle.h Fri Sep 30 15:53:22 2011
@@ -118,7 +118,7 @@
 	static void  desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag = saxxDefaultElem);
 	
 	virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
-	virtual void saxx(SaxHandler& handler)                     const { saxx(handler, saxxDefaultElem); }
+	virtual void saxx(SaxHandler& handler) const { saxx(handler, saxxDefaultElem); }
 	
 
 	void getNamedResources(ResourceCollection& lists) const;

Modified: trunk/Scribus/scribus/styles/paragraphstyle.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16863&path=/trunk/Scribus/scribus/styles/paragraphstyle.h
==============================================================================
--- trunk/Scribus/scribus/styles/paragraphstyle.h (original)
+++ trunk/Scribus/scribus/styles/paragraphstyle.h Fri Sep 30 15:53:22 2011
@@ -73,7 +73,7 @@
 	static void  desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag = saxxDefaultElem);
 	
 	virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
-	virtual void saxx(SaxHandler& handler)                     const { saxx(handler, saxxDefaultElem); }
+	virtual void saxx(SaxHandler& handler) const { saxx(handler, saxxDefaultElem); }
 	
 
 	void getNamedResources(ResourceCollection& lists) const;

Modified: trunk/Scribus/scribus/styles/tablestyle.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16863&path=/trunk/Scribus/scribus/styles/tablestyle.cpp
==============================================================================
--- trunk/Scribus/scribus/styles/tablestyle.cpp (original)
+++ trunk/Scribus/scribus/styles/tablestyle.cpp Fri Sep 30 15:53:22 2011
@@ -8,6 +8,7 @@
  */
 
 #include "commonstrings.h"
+#include "desaxe/saxiohelper.h"
 #include "util_math.h"
 #include "tableborder.h"
 #include "tablestyle.h"
@@ -77,3 +78,41 @@
 
 	// TODO: Do we need to do something else? E.g. CharStyle calls its updateFeatures().
 }
+
+void TableStyle::saxx(SaxHandler& handler, const Xml_string& elemtag) const
+{
+	/*
+	Xml_attr att;
+	Style::saxxAttributes(att);
+#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
+	if (!inh_##attr_NAME) \
+		att.insert(# attr_NAME, toXMLString(m_##attr_NAME));
+#include "tablestyle.attrdefs.cxx"
+#undef ATTRDEF
+	if (!name().isEmpty())
+		att["id"] = mkXMLName(elemtag + name());
+	handler.begin(elemtag, att);
+//	if (hasParent() && parentStyle())
+//		parentStyle()->saxx(handler);
+	handler.end(elemtag);
+	*/
+}
+
+using namespace desaxe;
+
+const Xml_string TableStyle::saxxDefaultElem("tablestyle");
+
+void TableStyle::desaxeRules(const Xml_string& prefixPattern, Digester& ruleset, Xml_string elemtag)
+{
+	/*
+	Xml_string stylePrefix(Digester::concat(prefixPattern, elemtag));
+	ruleset.addRule(stylePrefix, Factory<TableStyle>());
+	ruleset.addRule(stylePrefix, IdRef<TableStyle>());
+	Style::desaxeRules<TableStyle>(prefixPattern, ruleset, elemtag);
+#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
+	ruleset.addRule(stylePrefix, SetAttributeWithConversion<TableStyle, attr_TYPE> ( & TableStyle::set##attr_NAME,  # attr_NAME, &parse<attr_TYPE> ));
+#include "tablestyle.attrdefs.cxx"
+#undef ATTRDEF
+*/
+}
+

Modified: trunk/Scribus/scribus/styles/tablestyle.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16863&path=/trunk/Scribus/scribus/styles/tablestyle.h
==============================================================================
--- trunk/Scribus/scribus/styles/tablestyle.h (original)
+++ trunk/Scribus/scribus/styles/tablestyle.h Fri Sep 30 15:53:22 2011
@@ -57,11 +57,11 @@
 	 */
 	TableStyle& operator=(const TableStyle& other);
 
-	/// Not implemented.
-	virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const {};
+	static const Xml_string saxxDefaultElem;
+	static void  desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag = saxxDefaultElem);
 
-	/// Not implemented.
-	virtual void saxx(SaxHandler& handler) const {};
+	virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
+	virtual void saxx(SaxHandler& handler) const { saxx(handler, saxxDefaultElem); };
 
 	/**
 	 * Returns the display name of the table style.




More information about the scribus-commit mailing list