171
190
QFile f(url.path());
172
191
if (!f.exists()) {
173
KMessageBox::sorry(0L, i18n("%1: There is no file with that name to open.").arg(url.path()));
192
KMessageBox::sorry(KstApp::inst(), i18n("%1: There is no file with that name to open.").arg(url.path()));
175
194
_updating = false;
176
195
KstApp::inst()->setPaused(false);
196
QApplication::restoreOverrideCursor();
180
200
_title = url.fileName(false);
181
201
_absFilePath = url.path();
202
_lastFilePath = url.path();
182
203
if (_title.isEmpty()) {
183
204
_title = _absFilePath;
185
206
QDomDocument doc(_title);
187
208
if (!f.open(IO_ReadOnly)) {
188
KMessageBox::sorry(0L, i18n("%1: File exists, but kst could not open it.").arg(url.path()));
209
KMessageBox::sorry(KstApp::inst(), i18n("%1: File exists, but kst could not open it.").arg(url.path()));
190
211
_updating = false;
191
212
KstApp::inst()->setPaused(false);
213
QApplication::restoreOverrideCursor();
195
217
if (!doc.setContent(&f)) {
196
KMessageBox::sorry(0L, i18n("%1: Not a valid kst plot specification file.").arg(url.path()));
218
KMessageBox::sorry(KstApp::inst(), i18n("%1: Not a valid kst plot specification file.").arg(url.path()));
199
221
_updating = false;
200
222
KstApp::inst()->setPaused(false);
223
QApplication::restoreOverrideCursor();
214
237
QString readingDocument = i18n("Reading Kst file");
216
239
if (docElem.tagName() != "kstdoc") {
240
QString err = i18n("Error opening file %1. Does not appear to be a Kst file.").arg(url.path());
241
KstDebug::self()->log(err, KstDebug::Error);
242
KMessageBox::sorry(KstApp::inst(), err);
219
244
_updating = false;
220
245
KstApp::inst()->setPaused(false);
246
QApplication::restoreOverrideCursor();
224
if (!docElem.attribute("version").isEmpty()) {
250
if (docElem.attribute("version") != "1.2" && !docElem.attribute("version").isEmpty()) {
251
QString err = i18n("Error opening file %2. Version %1 is too new. Update Kst or fix the Kst file.").arg(docElem.attribute("version")).arg(url.path());
252
KstDebug::self()->log(err, KstDebug::Error);
253
KMessageBox::sorry(KstApp::inst(), err);
227
255
_updating = false;
228
256
KstApp::inst()->setPaused(false);
257
QApplication::restoreOverrideCursor();
351
384
} else if (e.tagName() == "plot") {
352
385
KstBaseCurveList l = kstObjectSubList<KstDataObject,KstBaseCurve>(KST::dataObjectList);
353
386
Kst2DPlotPtr plot = new Kst2DPlot(e);
354
app->plotHolderWhileOpeningDocument().insert(plot->tagName(), plot);
355
} else if (e.tagName() == "matrix") {
356
KstDataObjectPtr p = new KstMatrix(e);
357
KstWriteLocker dowl(&KST::dataObjectList.lock());
358
KST::dataObjectList.append(p);
387
app->plotHolderWhileOpeningDocument()->insert(plot->tagName(), plot);
388
} else if (e.tagName() == "amatrix") {
389
KstAMatrixPtr p = new KstAMatrix(e);
390
KST::addMatrixToList(KstMatrixPtr(p));
391
} else if (e.tagName() == "smatrix") {
392
KstSMatrixPtr p = new KstSMatrix(e);
393
KST::addMatrixToList(KstMatrixPtr(p));
394
} else if (e.tagName() == "rmatrix") {
395
KstRMatrixPtr p = new KstRMatrix(e);
396
KST::addMatrixToList(KstMatrixPtr(p));
359
397
} else if (e.tagName() == "image") {
360
398
KstDataObjectPtr p = new KstImage(e);
361
399
KstWriteLocker dowl(&KST::dataObjectList.lock());
393
431
if (warnOldKstFile) {
394
KMessageBox::sorry(0L, i18n("You tried to load an old Kst file. Curves created by equations or PSDs will not be loaded."));
432
QApplication::restoreOverrideCursor();
433
KMessageBox::sorry(KstApp::inst(), i18n("You tried to load an old Kst file. Curves created by equations or PSDs will not be loaded."));
434
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
397
437
app->slotUpdateProgress(0, 0, i18n("Creating plots"));
398
438
// if we have anything left in plotHolderWhileOpeningDocument then
399
439
// we are most likely reading an old style document, so we create
400
440
// a default view and fill it with whatever is left...
401
if (!app->plotHolderWhileOpeningDocument().isEmpty() && !app->activeWindow()) {
441
if (!app->plotHolderWhileOpeningDocument()->isEmpty() && !app->activeWindow()) {
403
443
QString winName = app->newWindow(QString::null);
404
444
KstViewWindow *win = dynamic_cast<KstViewWindow*>(app->findWindow(winName));
537
583
ts << "\" />" << endl;
539
585
KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
586
KstRMatrixList rml = kstObjectSubList<KstMatrix,KstRMatrix>(KST::matrixList);
542
589
KST::dataSourceList.lock().readLock();
543
590
for (uint i = 0; i < KST::dataSourceList.count(); i++) {
544
591
KstDataSourcePtr dsp = KST::dataSourceList[i];
545
for (KstRVectorList::Iterator it = rvl.begin(); it != rvl.end(); ++it) {
546
if ((*it)->dataSource() == dsp) {
547
ts << " <kstfile>" << endl;
549
ts << " </kstfile>" << endl;
593
for (KstRVectorList::Iterator it = rvl.begin(); it != rvl.end() && !saved; ++it) {
594
if ((*it)->dataSource() == dsp) {
595
ts << " <kstfile>" << endl;
597
ts << " </kstfile>" << endl;
601
for (KstRMatrixList::Iterator it = rml.begin(); it != rml.end() && !saved; ++it) {
602
if ((*it)->dataSource() == dsp) {
603
ts << " <kstfile>" << endl;
605
ts << " </kstfile>" << endl;
696
765
emit updateDialogs();
699
769
void KstDoc::samplesUp() {
770
bool changed = false;
705
771
KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
706
772
for (int i = 0; i < (int)rvl.count(); i++) {
773
KstRVectorPtr V = rvl[i];
709
f0 = V->reqStartFrame();
710
n = V->reqNumFrames();
712
doSkip = V->doSkip();
714
fileN = V->fileLength();
775
int f0 = V->reqStartFrame();
776
int n = V->reqNumFrames();
777
int skip = V->skip();
778
bool doSkip = V->doSkip();
779
bool doAve = V->doAve();
780
int fileN = V->fileLength();
782
bool didChange = false;
716
783
if (f0 + 2 * n > fileN) {
784
didChange = f0 != fileN - n;
785
changed = changed || didChange;
721
V->changeFrames(f0, n, skip, doSkip, doAve);
793
V->changeFrames(f0, n, skip, doSkip, doAve);
722
795
V->writeUnlock();
732
806
void KstDoc::samplesDown() {
807
bool changed = false;
738
808
KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
739
809
for (int i = 0; i < (int)rvl.count(); i++) {
810
KstRVectorPtr V = rvl[i];
742
f0 = V->reqStartFrame();
812
int f0 = V->reqStartFrame();
744
814
f0 = V->startFrame();
745
n = V->reqNumFrames();
747
doSkip = V->doSkip();
749
fileN = V->fileLength();
816
int n = V->reqNumFrames();
817
int skip = V->skip();
818
bool doSkip = V->doSkip();
819
bool doAve = V->doAve();
821
bool didChange = false;
751
822
if (f0 - n < 0) {
824
changed = changed || didChange;
757
V->changeFrames(f0, n, skip, doSkip, doAve);
832
V->changeFrames(f0, n, skip, doSkip, doAve);
758
834
V->writeUnlock();
803
880
void KstDoc::purge() {
804
881
QString purging = i18n("Purging unused objects");
805
882
bool modified = false;
806
KstRVectorList rvl = kstObjectSubList<KstVector,KstRVector>(KST::vectorList);
807
884
KstApp *app = KstApp::inst();
809
KST::dataObjectList.lock().writeLock();
810
int cnt = rvl.count() + KST::dataObjectList.count();
813
app->slotUpdateProgress(cnt, prg, purging);
815
// ASSUMPTION: this only gets called from the data manager!
816
for (KstDataObjectList::Iterator it = KST::dataObjectList.begin(); it != KST::dataObjectList.end(); ++it) {
817
//kdDebug() << "OBJECT: " << (*it)->tagName() << " USAGE: " << (*it)->getUsage() << endl;
818
if ((*it)->getUsage() == 0) {
819
//kdDebug() << " -> REMOVED" << endl;
820
KstDataObjectList::Iterator byebye = it;
822
KST::dataObjectList.remove(byebye);
826
app->slotUpdateProgress(cnt, prg, purging);
828
KST::dataObjectList.lock().writeUnlock();
830
for (KstRVectorList::Iterator it = rvl.begin(); it != rvl.end(); ++it) {
831
//kdDebug() << "VECTOR: " << (*it)->tagName() << " USAGE: " << (*it)->getUsage() << endl;
832
if ((*it)->getUsage() == 1) {
833
//kdDebug() << " -> REMOVED" << endl;
834
KST::vectorList.lock().writeLock();
835
KST::vectorList.remove((*it).data());
836
KST::vectorList.lock().writeUnlock();
840
app->slotUpdateProgress(cnt, prg, purging);
843
app->slotUpdateProgress(0, 0, QString::null);
887
KST::dataObjectList.lock().readLock();
888
KST::matrixList.lock().readLock();
889
KST::vectorList.lock().readLock();
890
int cnt = KST::matrixList.count() + KST::vectorList.count() + KST::dataObjectList.count();
891
KST::vectorList.lock().readUnlock();
892
KST::matrixList.lock().readUnlock();
893
KST::dataObjectList.lock().readUnlock();
896
app->slotUpdateProgress(cnt, prg, purging);
899
// ASSUMPTION: this only gets called from the data manager!
900
KST::dataObjectList.lock().writeLock();
901
for (KstDataObjectList::Iterator it = KST::dataObjectList.begin(); it != KST::dataObjectList.end(); ++it) {
902
//kstdDebug() << "OBJECT: " << (*it)->tagName() << " USAGE: " << (*it)->getUsage() << endl;
903
if ((*it)->getUsage() == 0) {
904
//kstdDebug() << " -> REMOVED" << endl;
905
KstDataObjectList::Iterator byebye = it;
907
KST::dataObjectList.remove(byebye);
912
app->slotUpdateProgress(cnt, prg, purging);
914
KST::dataObjectList.lock().writeUnlock();
916
KST::vectorList.lock().readLock();
917
KstVectorList vectorList = QDeepCopy<KstVectorList>(KST::vectorList);
918
KST::vectorList.lock().readUnlock();
920
// clear unused vectors that are editable
921
for (KstVectorList::ConstIterator it = vectorList.begin(); it != vectorList.end(); ++it) {
922
//kstdDebug() << "VECTOR: " << (*it)->tagName() << " USAGE: " << (*it)->getUsage() << endl;
923
if ((*it)->getUsage() == 1) {
924
//kstdDebug() << " -> REMOVED" << endl;
925
KST::vectorList.lock().writeLock();
926
KST::vectorList.remove(const_cast<KstVector*>((*it).data()));
927
KST::vectorList.lock().writeUnlock();
932
app->slotUpdateProgress(cnt, prg, purging);
935
KST::matrixList.lock().readLock();
936
KstMatrixList matrixList = QDeepCopy<KstMatrixList>(KST::matrixList);
937
KST::matrixList.lock().readUnlock();
939
// clear unused matrices that are editable
940
for (KstMatrixList::ConstIterator it = matrixList.begin(); it != matrixList.end(); ++it) {
941
if ((*it)->getUsage() == 1) {
942
//kstdDebug() << " -> REMOVED" << endl;
943
KST::matrixList.lock().writeLock();
944
KST::matrixList.remove(const_cast<KstMatrix*>((*it).data()));
945
KST::matrixList.lock().writeUnlock();
950
app->slotUpdateProgress(cnt, prg, purging);
954
KstDataSourceList dataList;
955
KST::dataSourceList.lock().readLock();
956
for (KstDataSourceList::ConstIterator it = KST::dataSourceList.begin(); it != KST::dataSourceList.end(); ++it) {
957
if ((*it)->getUsage() == 1) {
958
//kstdDebug() << " -> REMOVED" << endl;
959
dataList.append(const_cast<KstDataSource*>((*it).data()));
963
KST::dataSourceList.lock().readUnlock();
964
KST::dataSourceList.lock().writeLock();
965
for (KstDataSourceList::ConstIterator it = dataList.begin(); it != dataList.end(); ++it) {
966
KST::dataSourceList.remove(const_cast<KstDataSource*>((*it).data()));
968
KST::dataSourceList.lock().writeUnlock();
846
970
setModified(modified);
847
971
emit updateDialogs();
973
app->slotUpdateProgress(0, 0, QString::null);