| 841 | } |
| 842 | |
| 843 | void ccColorScaleEditorDialog::importScale() |
| 844 | { |
| 845 | //persistent settings |
| 846 | QSettings settings; |
| 847 | settings.beginGroup(ccPS::LoadFile()); |
| 848 | QString currentPath = settings.value(ccPS::CurrentPath(), ccFileUtils::defaultDocPath()).toString(); |
| 849 | |
| 850 | //ask for a filename |
| 851 | QString filename = QFileDialog::getOpenFileName(this,"Select color scale file",currentPath,"*.xml"); |
| 852 | if (filename.isEmpty()) |
| 853 | { |
| 854 | //process cancelled by user |
| 855 | return; |
| 856 | } |
| 857 | |
| 858 | //save last loading parameters |
| 859 | settings.setValue(ccPS::CurrentPath(),QFileInfo(filename).absolutePath()); |
| 860 | settings.endGroup(); |
| 861 | |
| 862 | //try to load the file |
| 863 | ccColorScale::Shared scale = ccColorScale::LoadFromXML(filename); |
| 864 | if (scale) |
| 865 | { |
| 866 | assert(m_manager); |
| 867 | if (m_manager) |
| 868 | { |
| 869 | ccColorScale::Shared otherScale = m_manager->getScale(scale->getUuid()); |
| 870 | if (otherScale) |
| 871 | { |
| 872 | QString message = "A color scale with the same UUID"; |
| 873 | if (otherScale->getName() == scale->getName()) |
| 874 | message += QString(" and the same name (%1)").arg(scale->getName()); |
| 875 | message += " is already in store!"; |
| 876 | message += "\n"; |
| 877 | message += "Do you want to force the importation of this new scale? (a new UUID will be generated)"; |
| 878 | |
| 879 | if (QMessageBox::question (this, |
| 880 | "UUID conflict", |
| 881 | message, |
| 882 | QMessageBox::Yes, |
| 883 | QMessageBox::No) == QMessageBox::No) |
| 884 | { |
| 885 | ccLog::Warning("[ccColorScaleEditorDialog::importScale] Importation cancelled due to a conflicting UUID (color scale may already be in store)"); |
| 886 | return; |
| 887 | } |
| 888 | //generate a new UUID |
| 889 | scale->setUuid(QUuid::createUuid().toString()); |
| 890 | } |
| 891 | //now we can import the scale |
| 892 | m_manager->addScale(scale); |
| 893 | ccLog::Print(QString("[ccColorScaleEditorDialog::importScale] Color scale '%1' successfully imported").arg(scale->getName())); |
| 894 | } |
| 895 | |
| 896 | updateMainComboBox(); |
| 897 | |
| 898 | setActiveScale(scale); |
| 899 | } |
| 900 | } |
nothing calls this directly
no test coverage detected