[Kst] branches/work/kst/portto4/kst/src
Peter Kümmel
syntheticpp at gmx.net
Thu Aug 12 16:32:11 CEST 2010
SVN commit 1162736 by kuemmel:
better data source path handling:
- save absolute and relative path if possible
- when loading try relative path for data sources first
- fall back to absolute path if relative path does not exists
CCBUG: 221689
M +16 -2 libkst/dataprimitive.cpp
M +3 -1 libkstapp/mainwindow.cpp
--- branches/work/kst/portto4/kst/src/libkst/dataprimitive.cpp #1162735:1162736
@@ -37,10 +37,10 @@
void DataPrimitive::Private::saveFilename(const QString& fn, QXmlStreamWriter& s) {
if (!fn.isEmpty()) {
+ // QDir::current is set to *.kst's file path in mainwindow.cpp
QDir current = QDir::current();
- QString currentP = QDir::currentPath();
QString relFn = current.relativeFilePath(fn);
- s.writeAttribute("file", fn);
+ s.writeAttribute("file", current.absoluteFilePath(fn));
if (QDir::isRelativePath(relFn)) { // is absolute if on a differnt disk/network
s.writeAttribute("fileRelative", relFn);
}
@@ -94,6 +94,20 @@
QString DataPrimitive::readFilename(const QXmlStreamAttributes& attrs)
{
+ // TODO discuss strategy:
+ // - first try relative path
+ // - fall back to absolute path
+
+ // QDir::current is set to *.kst's file path in mainwindow.cpp
+ QDir current = QDir::current();
+
+ QString fnRel = attrs.value("fileRelative").toString();
+
+ if (!fnRel.isEmpty() && current.exists(fnRel)) {
+ // internally only use absolute paths
+ return current.absoluteFilePath(fnRel);
+ }
+
return attrs.value("file").toString();
}
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #1162735:1162736
@@ -205,7 +205,9 @@
return;
}
QString restorePath = QDir::currentPath();
- QDir::setCurrent(fn.left(fn.lastIndexOf("/")));
+ QString kstfiledir = fn.left(fn.lastIndexOf("/"));
+ QDir::setCurrent(kstfiledir);
+ QString currentP = QDir::currentPath();
_doc->save(fn);
QDir::setCurrent(restorePath);
setWindowTitle("Kst - " + fn);
More information about the Kst
mailing list