Пример #1
0
void QmlSelectGroup::loadList()
{
    downloader = new QDownloader;
    connect(downloader,SIGNAL(fileCreated()),this,SLOT(fileLoaded()));
    downloader->setFileName("get_schem.json");
    downloader->setUrl(rootUrl+"/get_faculties");
    downloader->startDownload();
}
/**
 * collapse a list of paths into files and directories.  The collapsing part is that
 * if list contains a directory and a file in that directory (or a sub-directory) the it is
 * ignored.
 *
 * For example:
 * paths = { "/home/user/project1/index.php" => 1, "/home/user/project1/js/index.js" => 1,
 *           "/home/user/project1/" => 1, "/home/user/project2/index.php" => 1 }
 *
 * Then, the final result will be
 *
 * collapsedDirs = { "/home/user/project1/" => 1 }
 * collapsedFiles = {"/home/user/project2/index.php" => 1 }
 *
 * @param tagCache to find out if a path is a file or a directory
 * @param paths the list of paths to be checked
 * @param collapsedDis the directories in paths
 * @param collapsedFiles the files in paths (except files in any of collapsedDirs)
 */
static void CollapseDirsFiles(t4p::TagCacheClass& tagCache, std::map<wxString, int>& paths,
                              std::map<wxString, int>& collapsedDirs, std::map<wxString, int>& collapsedFiles) {
    std::map<wxString, int>::iterator mapIt;
    std::vector<wxString> sortedPaths;
    for (mapIt = paths.begin(); mapIt != paths.end(); ++mapIt) {
        sortedPaths.push_back(mapIt->first);
    }
    std::sort(sortedPaths.begin(), sortedPaths.end());

    std::vector<wxString>::iterator path;
    for (path = sortedPaths.begin(); path != sortedPaths.end(); ++path) {
        // we want to know if the path is a file or a directory
        // in the case of deletes, we can't query the file system as the file/dir no
        // longer exists
        // we can look it up in the tag cache instead
        if (wxFileName::DirExists(*path) || tagCache.HasDir(*path)) {
            wxFileName dirCreated;
            dirCreated.AssignDir(*path);

            // if a parent dir already exists, then it means that this is a subdir and we want to skip it
            size_t dirCount = dirCreated.GetDirCount();
            bool foundSubDir = false;
            for (size_t i = 0; i < dirCount; ++i) {
                if (collapsedDirs.find(dirCreated.GetPath()) != collapsedDirs.end()) {
                    foundSubDir = true;
                    break;
                }
                dirCreated.RemoveLastDir();
            }
            if (!foundSubDir) {
                collapsedDirs[*path] = 1;
            }
        } else if (wxFileName::FileExists(*path) || tagCache.HasFullPath(*path)) {
            // if the file's dir parent dir has been labeled as created, we want to skip it
            wxFileName fileCreated(*path);
            wxFileName fileDir;
            fileDir.AssignDir(fileCreated.GetPath());
            size_t dirCount = fileDir.GetDirCount();
            bool foundSubDir = false;
            for (size_t i = 0; i < dirCount; ++i) {
                if (collapsedDirs.find(fileDir.GetPath()) != collapsedDirs.end()) {
                    foundSubDir = true;
                    break;
                }
                fileDir.RemoveLastDir();
            }
            if (!foundSubDir) {
                collapsedFiles[*path] = 1;
            }
        }
    }
}
void
CreateCollectionPage::initializePage()
{
    Virtaus::Core::Collection* collection = new Virtaus::Core::Collection;

    QString collection_path = QDir::homePath()+"/"+tr("My Collections");
    collection_path += "/"+field("name").toString();

    collection->setInfo("name", field("name").toString());
    collection->setInfo("author", field("author").toString());
    collection->setInfo("email", field("email").toString());
    collection->setInfo("path", collection_path);

    Virtaus::Core::DataWriter* writer = new Virtaus::Core::DataWriter;
    QObject::connect(writer, SIGNAL(fileCreated(QString)), this, SLOT(file_created(QString)));
    success = writer->createCollection(collection);

    if (success)
        setFinalPage(true);
}
Пример #4
0
/**
* @brief Creates a new file with selected data
* @param asset The asset created
* @param file The file where are located the values.
* @throw ImportException The data is not valid
*/
void ImportNewData::import(const Asset &asset, const QString& file) const {
	QString data;
	QFile importedCSV(file);
	QStringList rowOfData;
	QStringList rowData;
	data.clear();
	rowOfData.clear();
	rowData.clear();
	QRegExp date_regex("^(20|19)[0-9]{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$");
	QRegExp value_regex("^([0-9]+)([.])([0-9][0-9])$");
	QDate previousDate = QDate::fromString("2999-01-01", "yyyy-MM-dd");
	int data_index;
	if (asset.getOrigin() == "ProjectVaR") {
		data_index = 1;
	} else {
		data_index = 6;
	}

	if (importedCSV.open(QFile::ReadOnly)) {
		data = importedCSV.readAll();
		rowOfData = data.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
		importedCSV.close();
	}

	//FILE CREATION OF IMPORTED DATA
	// Do unique names
	QFile fileCreated(asset.getFile());
	// The file is open in write-only mode and we check the opening
	if (!fileCreated.open(QIODevice::WriteOnly | QIODevice::Text)) {
		return;
	}
	QTextStream flux(&fileCreated);
	flux.setCodec("UTF-8");
	QDate endDate = asset.getEndDate();
	QDate startDate = asset.getStartDate();
	rowData = rowOfData.at(0).split(",");
	if (!(rowData.count() < data_index)) {
		if (!((QString) rowData[0]).isEmpty() && !((QString)rowData[data_index]).isEmpty()) {
			flux << rowData[0] << "," << rowData[data_index] << "\n";
			// x = 1 to avoid the first line with labels
			for (int x =1; x < rowOfData.size()-1; x++) {
				rowData = rowOfData.at(x).split(",");
				//Check dates and values are correct
				if(date_regex.exactMatch(rowData[0]) && value_regex.exactMatch(rowData[data_index])) {
					QDate currentDate = QDate::fromString(rowData[0], "yyyy-MM-dd");
					//checks the order of dates
					if(previousDate > currentDate) {
						previousDate = currentDate;
						//checks if we are on still in the range of dates
						if ((endDate >= currentDate)) {
							if(startDate > currentDate) {
								break;
							}
							flux << rowData[0] << "," << rowData[data_index] << "\n";
						}
					} else {
						throw CreateAssetException("Dates are not sorted");
						return;
					}

				} else {
					throw CreateAssetException("The data is invalid");
					return;
				}
			}
		} else {
			throw CreateAssetException("Header is missing");
			return;
		}
	} else {
		throw CreateAssetException("Wrong file type");
		return;
	}
	fileCreated.close();
}