void tst_QVersitProperty::testParameters()
{
    QString typeParameterName(QLatin1String("TYPE"));

    QString name(QLatin1String("type"));
    QString value1(QLatin1String("home"));
    mVersitProperty->insertParameter(name,value1);
    QMultiHash<QString,QString> parameters = mVersitProperty->parameters();
    QCOMPARE(parameters.count(), 1);
    QVERIFY(parameters.contains(typeParameterName,QLatin1String("home")));

    QString value2(QLatin1String("voice"));
    mVersitProperty->insertParameter(name,value2);
    parameters = mVersitProperty->parameters();
    QCOMPARE(parameters.count(), 2);
    QVERIFY(parameters.contains(typeParameterName,QLatin1String("home")));
    QVERIFY(parameters.contains(typeParameterName,QLatin1String("voice")));

    mVersitProperty->removeParameter(name,value1);
    QCOMPARE(mVersitProperty->parameters().count(), 1);
    QVERIFY(parameters.contains(typeParameterName,QLatin1String("home")));

    mVersitProperty->removeParameter(name,value2);
    QCOMPARE(mVersitProperty->parameters().count(), 0);

    mVersitProperty->insertParameter(name, value1);
    mVersitProperty->insertParameter(name, value2);
    QCOMPARE(mVersitProperty->parameters().count(), 2);
    mVersitProperty->removeParameters(name);
    QCOMPARE(mVersitProperty->parameters().count(), 0);
}
예제 #2
0
void IcecastService::ParseDirectoryFinished(
    QFuture<IcecastBackend::StationList> future) {
  IcecastBackend::StationList all_stations = future.result();
  sort(all_stations.begin(), all_stations.end(),
       StationSorter<IcecastBackend::Station>());
  // Remove duplicates by name. These tend to be multiple URLs for the same
  // station.
  IcecastBackend::StationList::iterator it =
      unique(all_stations.begin(), all_stations.end(),
             StationEquality<IcecastBackend::Station>());
  all_stations.erase(it, all_stations.end());

  // Cluster stations by genre.
  QMultiHash<QString, IcecastBackend::Station*> genres;

  // Add stations.
  for (int i = 0; i < all_stations.count(); ++i) {
    IcecastBackend::Station& s = all_stations[i];
    genres.insert(s.genre, &s);
  }

  QSet<QString> genre_set = genres.keys().toSet();

  // Merge genres with only 1 or 2 stations into "Other".
  for (const QString& genre : genre_set) {
    if (genres.count(genre) < 3) {
      const QList<IcecastBackend::Station*>& small_genre = genres.values(genre);
      for (IcecastBackend::Station* s : small_genre) {
        s->genre = "Other";
      }
    }
  }

  backend_->ClearAndAddStations(all_stations);

  app_->task_manager()->SetTaskFinished(load_directory_task_id_);
  load_directory_task_id_ = 0;
}
void DayViewModel::assignDisplayValues()
{
    int count = itemsList.count();

    if(count == 0)
        return;

    QMultiHash<int,int> hashmap;

    //Counting how many items start at an index
    for(int i=0;i<count;i++)
    {
        int index = 0,itemCount=0;

        CalendarDataItem *calItem = ((CalendarDataItem*)(itemsList.at(i)));
        index = computeStartIndex(calItem->startTime);
        ((CalendarDataItem*)(itemsList.at(i)))->startIndex = index;
        ((CalendarDataItem*)(itemsList.at(i)))->xUnits = 0;
        ((CalendarDataItem*)(itemsList.at(i)))->yUnits = 0;
        ((CalendarDataItem*)(itemsList.at(i)))->widthUnits = 1.0;
        double htVal = (calItem->startTime.secsTo(calItem->endTime) / (60.0*30.0));
        if(htVal<0.5) {
            htVal = 0.5;
        }
        htVal = round(htVal);
        ((CalendarDataItem*)(itemsList.at(i)))->heightUnits = htVal;
        qDebug()<<"xUnits="<<calItem->xUnits<<",yUnits="<<calItem->yUnits<<",widthUnits="<<calItem->widthUnits<<", heightUnits="<<calItem->heightUnits<<",startIndex="<<calItem->startIndex;

        for(int j=0;j<calItem->heightUnits;j++) {
            if(hashmap.count(index+j) == 0) {
                itemCount = 1;
            } else {
                itemCount = hashmap.value(index+j);
                itemCount++;
            }
            hashmap.replace(index+j,itemCount);
        }

    }

    //Assign width values based on number of items at an index and their height
    for(int i=0;i<count;i++)
    {
        CalendarDataItem *calItem = ((CalendarDataItem*)(itemsList.at(i)));
        int startIndex = calItem->startIndex;
        int htUnits = calItem->heightUnits;
        int maxCount=1,tmpVal=0;

        for(int j=0;j<htUnits;j++) {
            tmpVal = hashmap.value(startIndex+j);
            if(tmpVal>maxCount) {
                maxCount = tmpVal;
            }
        }

        calItem->widthUnits = (calItem->widthUnits)/maxCount;
    }

    //Assign xUnits value
    QMultiHash<int,int> xOffsetHashmap;

    for(int i=0;i<count;i++)
    {
        int itemCount=0;
        CalendarDataItem *calItem = ((CalendarDataItem*)(itemsList.at(i)));
        int startIndex = calItem->startIndex;
        int htUnits = calItem->heightUnits;
        int maxCount=0,tmpVal=0;

        for(int j=0;j<htUnits;j++) {
            tmpVal = xOffsetHashmap.value(startIndex+j);
            if(tmpVal>maxCount) {
                maxCount = tmpVal;
            }
        }
        calItem->xUnits=maxCount;
        for(int j=0;j<htUnits;j++) {
            if(xOffsetHashmap.count(startIndex+j) == 0) {
                itemCount = 1;
            } else {
                itemCount = xOffsetHashmap.value(startIndex+j);
                itemCount++;
            }
            xOffsetHashmap.replace(startIndex+j,itemCount);
        }

    }

    return;
}
예제 #4
0
//------------------------------------------------------------------------------
//	FUNCTION: invalidate [ public ]
//------------------------------------------------------------------------------
void csvFilterProxyModel::invalidate()
{
	m_filterMapping.clear();

	if (!m_filterModel)
		return;

	// Make a hash of all the groups in the filter
	QMultiHash<size_t, int> groups;
	std::set<int> unusedFilterColumns;

	for (int filterCol = 0; filterCol < m_filterModel->columnCount(); ++filterCol)
	{
		unusedFilterColumns.insert(filterCol);

		size_t group = m_filterModel->data(m_filterModel->index(1, filterCol)).toULongLong();
		groups.insert(group, filterCol);
	}

	// filter in column order, but each group aside from 0 should be filtered using logical 'and' with all group members
	for (auto itr = unusedFilterColumns.begin(); itr != unusedFilterColumns.end(); ++itr)
	{
		int							filterCol = *itr;
		QString						columnName = m_filterModel->headerData(filterCol, Qt::Horizontal, Qt::DisplayRole).toString();
		size_t						group = m_filterModel->data(m_filterModel->index(1, filterCol)).toULongLong();
		size_t						numInGroup = (group == 0 ? 1 : groups.count(group));
		QList<QString>				filterColumnNames;

		// make a list of filter values, i.e. all the things in the filter column
		auto filterColumns = groups.values(group);
		qSort(filterColumns);

		if (group != 0)
		{
			// for each filter in the group
			for (auto groupColumnItr = filterColumns.begin(); groupColumnItr != filterColumns.end(); ++groupColumnItr)
			{
				int column = *groupColumnItr;

				filterColumnNames.push_back(m_filterModel->headerData(column, Qt::Horizontal, Qt::DisplayRole).toString());

				// erase other columns that are part of this group so we don't check them twice
				if (groupColumnItr != filterColumns.begin()) 
					unusedFilterColumns.erase(column);				
			}
		}
		else
		{
			filterColumnNames.push_back(columnName);
			filterColumns.clear();
			filterColumns.push_back(filterCol);
		}

		// find the corresponding column in this spreadsheet
		QList<int> masterColumns;
		for (int i = 0; i < filterColumnNames.size(); ++i)
		{
			for (int masterColumn = 0; masterColumn < sourceModel()->columnCount(); masterColumn++)
			{
				QString masterColunName = sourceModel()->headerData(masterColumn, Qt::Horizontal, Qt::DisplayRole).toString();
				if (masterColunName == filterColumnNames.at(i))
				{
					masterColumns.push_back(masterColumn);
					break;
				}
			}
		}

		// add the mappings to the mapping table
		QList<QPair<int, int>> filterMapping;
		for (int i = 0; i < filterColumns.size(); ++i)
		{
			filterMapping.push_back(QPair<int, int>(filterColumns.at(i), masterColumns.at(i)));
		}
		m_filterMapping.push_back(filterMapping);
	}

	QSortFilterProxyModel::invalidate();
}