Mercurial > hg > svgui
comparison layer/ImageLayer.cpp @ 464:69089c9dc42e
* Fix crash in SimpleSPARQLQuery
* Fix failure to add images from local files
author | Chris Cannam |
---|---|
date | Thu, 15 Jan 2009 18:20:40 +0000 |
parents | 22b72f0f6a4e |
children | 1fe7951a61e8 |
comparison
equal
deleted
inserted
replaced
463:1461cfc7e446 | 464:69089c9dc42e |
---|---|
52 { | 52 { |
53 } | 53 } |
54 | 54 |
55 ImageLayer::~ImageLayer() | 55 ImageLayer::~ImageLayer() |
56 { | 56 { |
57 for (FileSourceMap::iterator i = m_remoteFiles.begin(); | 57 for (FileSourceMap::iterator i = m_fileSources.begin(); |
58 i != m_remoteFiles.end(); ++i) { | 58 i != m_fileSources.end(); ++i) { |
59 delete i->second; | 59 delete i->second; |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 void | 63 void |
605 | 605 |
606 ImageDialog dialog(tr("Select image"), "", ""); | 606 ImageDialog dialog(tr("Select image"), "", ""); |
607 | 607 |
608 if (dialog.exec() == QDialog::Accepted) { | 608 if (dialog.exec() == QDialog::Accepted) { |
609 | 609 |
610 checkAddRemote(dialog.getImage()); | 610 checkAddSource(dialog.getImage()); |
611 | 611 |
612 ImageModel::ChangeImageCommand *command = | 612 ImageModel::ChangeImageCommand *command = |
613 new ImageModel::ChangeImageCommand | 613 new ImageModel::ChangeImageCommand |
614 (m_model, m_editingPoint, dialog.getImage(), dialog.getLabel()); | 614 (m_model, m_editingPoint, dialog.getImage(), dialog.getLabel()); |
615 m_editingCommand->addCommand(command); | 615 m_editingCommand->addCommand(command); |
625 bool | 625 bool |
626 ImageLayer::addImage(long frame, QString url) | 626 ImageLayer::addImage(long frame, QString url) |
627 { | 627 { |
628 QImage image(getLocalFilename(url)); | 628 QImage image(getLocalFilename(url)); |
629 if (image.isNull()) { | 629 if (image.isNull()) { |
630 delete m_remoteFiles[url]; | 630 std::cerr << "Failed to open image from url \"" << url.toStdString() << "\" (local filename \"" << getLocalFilename(url).toStdString() << "\"" << std::endl; |
631 m_remoteFiles.erase(url); | 631 delete m_fileSources[url]; |
632 m_fileSources.erase(url); | |
632 return false; | 633 return false; |
633 } | 634 } |
634 | 635 |
635 ImageModel::Point point(frame, url, ""); | 636 ImageModel::Point point(frame, url, ""); |
636 ImageModel::EditCommand *command = | 637 ImageModel::EditCommand *command = |
711 image, | 712 image, |
712 label); | 713 label); |
713 | 714 |
714 if (dialog.exec() == QDialog::Accepted) { | 715 if (dialog.exec() == QDialog::Accepted) { |
715 | 716 |
716 checkAddRemote(dialog.getImage()); | 717 checkAddSource(dialog.getImage()); |
717 | 718 |
718 ImageModel::ChangeImageCommand *command = | 719 ImageModel::ChangeImageCommand *command = |
719 new ImageModel::ChangeImageCommand | 720 new ImageModel::ChangeImageCommand |
720 (m_model, *points.begin(), dialog.getImage(), dialog.getLabel()); | 721 (m_model, *points.begin(), dialog.getImage(), dialog.getLabel()); |
721 | 722 |
891 } | 892 } |
892 | 893 |
893 QString | 894 QString |
894 ImageLayer::getLocalFilename(QString img) const | 895 ImageLayer::getLocalFilename(QString img) const |
895 { | 896 { |
896 if (m_remoteFiles.find(img) == m_remoteFiles.end()) { | 897 if (m_fileSources.find(img) == m_fileSources.end()) { |
897 checkAddRemote(img); | 898 checkAddSource(img); |
898 if (m_remoteFiles.find(img) == m_remoteFiles.end()) { | 899 if (m_fileSources.find(img) == m_fileSources.end()) { |
899 return img; | 900 return img; |
900 } | 901 } |
901 } | 902 } |
902 return m_remoteFiles[img]->getLocalFilename(); | 903 return m_fileSources[img]->getLocalFilename(); |
903 } | 904 } |
904 | 905 |
905 void | 906 void |
906 ImageLayer::checkAddRemote(QString img) const | 907 ImageLayer::checkAddSource(QString img) const |
907 { | 908 { |
908 if (FileSource::isRemote(img)) { | 909 std::cerr << "ImageLayer::checkAddSource(" << img.toStdString() << "): yes, trying..." << std::endl; |
909 | 910 |
910 std::cerr << "ImageLayer::checkAddRemote(" << img.toStdString() << "): yes, trying..." << std::endl; | 911 if (m_fileSources.find(img) != m_fileSources.end()) { |
911 | 912 return; |
912 if (m_remoteFiles.find(img) != m_remoteFiles.end()) { | 913 } |
913 return; | 914 |
914 } | 915 ProgressDialog dialog(tr("Opening image URL..."), true, 2000); |
915 | 916 FileSource *rf = new FileSource(img, &dialog); |
916 ProgressDialog dialog(tr("Opening image URL..."), true, 2000); | 917 if (rf->isOK()) { |
917 FileSource *rf = new FileSource(img, &dialog); | 918 std::cerr << "ok, adding it (local filename = " << rf->getLocalFilename().toStdString() << ")" << std::endl; |
918 if (rf->isOK()) { | 919 m_fileSources[img] = rf; |
919 std::cerr << "ok, adding it (local filename = " << rf->getLocalFilename().toStdString() << ")" << std::endl; | 920 connect(rf, SIGNAL(ready()), this, SLOT(fileSourceReady())); |
920 m_remoteFiles[img] = rf; | 921 } else { |
921 connect(rf, SIGNAL(ready()), this, SLOT(remoteFileReady())); | 922 delete rf; |
922 } else { | 923 } |
923 delete rf; | 924 } |
924 } | 925 |
925 } | 926 void |
926 } | 927 ImageLayer::checkAddSources() |
927 | |
928 void | |
929 ImageLayer::checkAddRemotes() | |
930 { | 928 { |
931 const ImageModel::PointList &points(m_model->getPoints()); | 929 const ImageModel::PointList &points(m_model->getPoints()); |
932 | 930 |
933 for (ImageModel::PointList::const_iterator i = points.begin(); | 931 for (ImageModel::PointList::const_iterator i = points.begin(); |
934 i != points.end(); ++i) { | 932 i != points.end(); ++i) { |
935 | 933 |
936 checkAddRemote((*i).image); | 934 checkAddSource((*i).image); |
937 } | 935 } |
938 } | 936 } |
939 | 937 |
940 void | 938 void |
941 ImageLayer::remoteFileReady() | 939 ImageLayer::fileSourceReady() |
942 { | 940 { |
943 // std::cerr << "ImageLayer::remoteFileReady" << std::endl; | 941 // std::cerr << "ImageLayer::fileSourceReady" << std::endl; |
944 | 942 |
945 FileSource *rf = dynamic_cast<FileSource *>(sender()); | 943 FileSource *rf = dynamic_cast<FileSource *>(sender()); |
946 if (!rf) return; | 944 if (!rf) return; |
947 | 945 |
948 QString img; | 946 QString img; |
949 for (FileSourceMap::const_iterator i = m_remoteFiles.begin(); | 947 for (FileSourceMap::const_iterator i = m_fileSources.begin(); |
950 i != m_remoteFiles.end(); ++i) { | 948 i != m_fileSources.end(); ++i) { |
951 if (i->second == rf) { | 949 if (i->second == rf) { |
952 img = i->first; | 950 img = i->first; |
953 // std::cerr << "it's image \"" << img.toStdString() << "\"" << std::endl; | 951 // std::cerr << "it's image \"" << img.toStdString() << "\"" << std::endl; |
954 break; | 952 break; |
955 } | 953 } |