r18282 by jghali - implement a fallback strategy when legacy tables cannot be converted to new tables without some loss
scribus-commit
scribus-commit at lists.scribus.net
Sun May 12 21:46:51 UTC 2013
Author: jghali
Date: Sun May 12 21:46:50 2013
New Revision: 18282
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=18282
Log:
implement a fallback strategy when legacy tables cannot be converted to new tables without some loss
Modified:
trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
trunk/Scribus/scribus/util.cpp
trunk/Scribus/scribus/util.h
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18282&path=/trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp Sun May 12 21:46:50 2013
@@ -642,9 +642,10 @@
}
m_Doc->DocItems.removeOne(cItem);
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -673,9 +674,10 @@
}
m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem));
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -704,9 +706,10 @@
}
m_Doc->MasterItems.removeOne(cItem);
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -2176,9 +2179,10 @@
}
m_Doc->DocItems.removeOne(cItem);
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18282&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 Sun May 12 21:46:50 2013
@@ -596,9 +596,10 @@
}
m_Doc->DocItems.removeOne(cItem);
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -627,9 +628,10 @@
}
m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem));
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -658,9 +660,10 @@
}
m_Doc->MasterItems.removeOne(cItem);
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -1113,9 +1116,10 @@
}
m_Doc->DocItems.removeOne(cItem);
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -1144,9 +1148,10 @@
}
m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem));
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -1175,9 +1180,10 @@
}
m_Doc->MasterItems.removeOne(cItem);
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -1805,9 +1811,10 @@
}
m_Doc->DocItems.removeOne(cItem);
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -1836,9 +1843,10 @@
}
m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem));
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -1867,9 +1875,10 @@
}
m_Doc->MasterItems.removeOne(cItem);
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackM, &m_Doc->MasterItems);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -4202,9 +4211,10 @@
}
m_Doc->DocItems.removeOne(cItem);
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -6088,9 +6098,10 @@
}
m_Doc->DocItems.removeOne(cItem);
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackP, &m_Doc->DocItems);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
@@ -6119,9 +6130,10 @@
}
m_Doc->FrameItems.remove(m_Doc->FrameItems.key(cItem));
}
+ bool converted = false;
if (isTableIt)
- convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
- else
+ converted = convertOldTable(m_Doc, gItem, gpL, &groupStackF, NULL);
+ if (!converted)
gItem->groupItemList = gpL;
}
}
Modified: trunk/Scribus/scribus/util.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18282&path=/trunk/Scribus/scribus/util.cpp
==============================================================================
--- trunk/Scribus/scribus/util.cpp (original)
+++ trunk/Scribus/scribus/util.cpp Sun May 12 21:46:50 2013
@@ -1016,10 +1016,32 @@
}
-void convertOldTable(ScribusDoc *m_Doc, PageItem* gItem, QList<PageItem*> &gpL, QStack<QList<PageItem *> > *groupStackT, QList<PageItem *> *target)
+bool convertOldTable(ScribusDoc *m_Doc, PageItem* gItem, QList<PageItem*> &gpL, QStack<QList<PageItem *> > *groupStackT, QList<PageItem *> *target)
{
QList<double> colWidths;
QList<double> rowHeights;
+
+ // 1. Although this was not intended, legacy tables allowed user to link frames together
+ // New table do not support that, so if one frame has any link, we stop the conversion
+ // here, those frame will be converted to a standard group.
+ // 2. Pre-1.4.3 versions had a bug where item TopLink/LeftLink/BottomLink/RightLink were
+ // lost when copy/pasting tables. Exit conversion too so these broken tables can be
+ // converted to standard groups (at least until we find a good way to process that case)
+ bool hasTableLinks = false;
+ bool hasTextLinks = false;
+ for (int a = 0; a < gpL.count(); a++)
+ {
+ PageItem* it = gpL[a];
+ it->isTableItem = false;
+ if (it->nextInChain() || it->prevInChain())
+ hasTextLinks = true;
+ if (it->LeftLink || it->RightLink || it->BottomLink || it->TopLink)
+ hasTableLinks = true;
+ }
+
+ if (!hasTableLinks || hasTextLinks)
+ return false;
+
PageItem *topLeft = NULL;
for (int a = 0; a < gpL.count(); a++)
{
@@ -1043,6 +1065,11 @@
break;
}
}
+
+ // Check we have found enough rows and columns so that no item will disappear
+ if ((colWidths.count() * rowHeights.count()) < gpL.count())
+ return false;
+
m_Doc->dontResize = true;
int z = m_Doc->itemAdd(PageItem::Table, PageItem::Unspecified, gItem->xPos(), gItem->yPos(), gItem->width(), gItem->height(), 0.0, CommonStrings::None, CommonStrings::None, true);
PageItem_Table* currItem = m_Doc->Items->takeAt(z)->asTable();
@@ -1138,6 +1165,8 @@
delete item;
}
delete gItem;
+
+ return true;
}
void setWidgetBoldFont(QWidget* w, bool wantBold)
Modified: trunk/Scribus/scribus/util.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18282&path=/trunk/Scribus/scribus/util.h
==============================================================================
--- trunk/Scribus/scribus/util.h (original)
+++ trunk/Scribus/scribus/util.h Sun May 12 21:46:50 2013
@@ -152,7 +152,12 @@
void SCRIBUS_API getDashArray(int dashtype, double linewidth, QVector<float> &m_array);
void SCRIBUS_API printBacktrace(int nFrames);
-void SCRIBUS_API convertOldTable(ScribusDoc *m_Doc, PageItem* gItem, QList<PageItem*> &gpL, QStack< QList<PageItem*> > *groupStackT = NULL, QList<PageItem *> *target = NULL);
+
+/*!
+ *\brief Convert pre-1.5.x tables to table as implemented in 1.5.x
+ *\retval true on success, false it items have to be converted to a group
+*/
+bool SCRIBUS_API convertOldTable(ScribusDoc *m_Doc, PageItem* gItem, QList<PageItem*> &gpL, QStack< QList<PageItem*> > *groupStackT = NULL, QList<PageItem *> *target = NULL);
void SCRIBUS_API setWidgetBoldFont(QWidget* w, bool wantBold);
/*!
More information about the scribus-commit
mailing list