MCPcopy Create free account
hub / github.com/MiniZinc/MiniZincIDE / currentModelFile

Method currentModelFile

MiniZincIDE/mainwindow.cpp:908–955  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

906}
907
908QString MainWindow::currentModelFile()
909{
910 if (curEditor) {
911 if (curEditor->filepath.endsWith(".fzn") ||
912 (curEditor->filepath.endsWith(".mzn") && !curEditor->filepath.endsWith(".mzc.mzn"))) {
913 // The current file is a model
914 return curEditor->filepath;
915 }
916 if (curEditor->filepath.isEmpty()) {
917 // The current file is a playground buffer
918 QTemporaryDir* modelTmpDir = new QTemporaryDir;
919 if (!modelTmpDir->isValid()) {
920 throw InternalError("Could not create temporary directory for compilation.");
921 } else {
922 cleanupTmpDirs.append(modelTmpDir);
923 QString model = modelTmpDir->path() + "/untitled_model." + (curEditor->filename.endsWith(".fzn") ? "fzn" : "mzn");
924 QFile modelFile(model);
925 if (modelFile.open(QIODevice::ReadWrite)) {
926 QTextStream ts(&modelFile);
927#if QT_VERSION < 0x060000
928 ts.setCodec("UTF-8");
929#endif
930 ts << curEditor->document()->toPlainText();
931 modelFile.close();
932 } else {
933 throw InternalError("Could not write temporary model file.");
934 }
935 curEditor->playgroundTempFile = model;
936 return model;
937 }
938 }
939 }
940
941 auto modelFiles = getProject().modelFiles();
942 if (modelFiles.count() == 0) {
943 // There are no model files
944 return "";
945 }
946 if (modelFiles.count() == 1) {
947 return modelFiles[0];
948 }
949
950 int selectedModel = paramDialog->getModel(modelFiles);
951 if (selectedModel == -1) {
952 return "";
953 }
954 return modelFiles[selectedModel];
955}
956
957bool MainWindow::promptSaveModified()
958{

Callers 5

testProject106GoodMethod · 0.80
testProject106BadMethod · 0.80
testProject105GoodMethod · 0.80
testProject105BadMethod · 0.80
testMoocProjectMethod · 0.80

Calls 5

InternalErrorClass · 0.85
isValidMethod · 0.80
modelFilesMethod · 0.80
countMethod · 0.80
getModelMethod · 0.80

Tested by 5

testProject106GoodMethod · 0.64
testProject106BadMethod · 0.64
testProject105GoodMethod · 0.64
testProject105BadMethod · 0.64
testMoocProjectMethod · 0.64