Exemplo n.º 1
0
bool BookInfo::locationsHasChanged(const QHash<QString, BookLocation*>& locations)
{
    qDebug() << Q_FUNC_INFO << " " << m_locations.size() << " other: " << locations.size();
    if(m_locations.size() != locations.size())
        return true;

    QHash<QString, BookLocation*>::const_iterator it = m_locations.constBegin();
    QHash<QString, BookLocation*>::const_iterator itEnd = m_locations.constEnd();

    while(it != itEnd)
    {
        if(locations.find(it.key()) == locations.end())
            return true;
        else{
            if(it.value()->note != locations.find(it.key()).value()->note)
                return true;
            if(it.value()->operation != locations.find(it.key()).value()->operation)
                return true;
            if(it.value()->pos != locations.find(it.key()).value()->pos)
                return true;
            if(it.value()->page!= locations.find(it.key()).value()->page)
                return true;
        }
        ++it;
    }

    return false;
}
Exemplo n.º 2
0
int main ()
{
    QHash<int, int> myQHash;
    QHash<int, int> :: iterator it;

    myQHash[1] = 500;
    myQHash[2] = 300;
    myQHash[3] = 100;

    it = myQHash.begin();

    it = myQHash.find(1);
    if (it.value() == 500) {
        it = myQHash.erase(it);
    }
    
    it = myQHash.find(2);
    if (it.value() == 300) {
        it = myQHash.erase(it);
    }

    assert(!(myQHash.empty()));

    return 0;
}
Exemplo n.º 3
0
void StbImageFactory::parseFile(const QString &path, QList<ResourceData *> &content, const QHash<QString,QString>& rules)
{
    QDir dir(path);
    QString name = dir.dirName();
    dir.cdUp();
    if(dir.exists())
    {
        debug( "RESOURCE PARSING" , "StbImage found " << name);
        int comp = 4; // alpha by default
        //int comp = 3;
        bool mipmap = true;
        bool filtering = true;
        bool wrap_s = true;
        bool wrap_t = true;
        if(rules.contains("alpha") && rules.find("alpha").value() == "true")
            comp = 4;
        if(rules.contains("mipmap") && rules.find("mipmap").value() == "false")
            mipmap = false;
        if(rules.contains("filtering") && rules.find("filtering").value() == "false")
            filtering = false;
        if(rules.contains("wrap_s") && rules.find("wrap_s").value() == "false")
            wrap_s = false;
        if(rules.contains("wrap_t") && rules.find("wrap_t").value() == "false")
            wrap_t = false;

        StbImage* image = new StbImage(name,path,this,0,mipmap,filtering,wrap_s,wrap_t,comp);
        content.push_back(image);
    }
    else
    {
        debug( "RESOURCE PARSING" , path << " : " << dir << " does not exist");
    }
}
Exemplo n.º 4
0
DENG_ENTRYPOINT void *GetGameAPI(char const *name)
{
    if (auto *ptr = Common_GetGameAPI(name))
    {
        return ptr;
    }

    #define HASH_ENTRY(Name, Func) std::make_pair(QByteArray(Name), de::function_cast<void *>(Func))
    static QHash<QByteArray, void *> const funcs(
    {
        HASH_ENTRY("DrawWindow",    D_DrawWindow),
        HASH_ENTRY("EndFrame",      D_EndFrame),
        HASH_ENTRY("GetInteger",    D_GetInteger),
        HASH_ENTRY("GetPointer",    D_GetVariable),
        HASH_ENTRY("PostInit",      D_PostInit),
        HASH_ENTRY("PreInit",       G_PreInit),
        HASH_ENTRY("Shutdown",      D_Shutdown),
        HASH_ENTRY("TryShutdown",   G_TryShutdown),
    });
    #undef HASH_ENTRY

    auto found = funcs.find(name);
    if (found != funcs.end()) return found.value();
    return nullptr;
}
Exemplo n.º 5
0
void QgsHttpRequestHandler::imageColors( QHash<QRgb, int>& colors, const QImage& image )
{
  colors.clear();
  int width = image.width();
  int height = image.height();

  const QRgb* currentScanLine = nullptr;
  QHash<QRgb, int>::iterator colorIt;
  for ( int i = 0; i < height; ++i )
  {
    currentScanLine = ( const QRgb* )( image.scanLine( i ) );
    for ( int j = 0; j < width; ++j )
    {
      colorIt = colors.find( currentScanLine[j] );
      if ( colorIt == colors.end() )
      {
        colors.insert( currentScanLine[j], 1 );
      }
      else
      {
        colorIt.value()++;
      }
    }
  }
}
Exemplo n.º 6
0
void AdaptiveLayout::tKey::ArrangeProperties(const QHash<QString, int> &propsOrder, int max)
{
    QVector<int> permutation;
    permutation.resize(m_Properties.size());
    for( QHash<QString, int>::iterator i = m_Properties.begin(); i != m_Properties.end(); ++i )
    {
        int indexFrom = i.value();
        int indexTo = indexFrom;
        QHash<QString, int>::const_iterator p = propsOrder.find(i.key());
        if( p != propsOrder.end() )  // If we fail to find, the result may be incorrect
        {
            indexTo = p.value();
        }
        i.value() = indexTo;
        permutation[indexFrom] = indexTo;
    }
    QVector<float> newProps;
    newProps.resize(max + 1);
    for( int iactor = 0; iactor < m_Actors.size(); iactor++ )
    {
        tActor& actor = m_Actors[iactor];
        newProps.fill(0.f);
        for( int i = 0; i < actor.props.size(); i++ )
        {
            newProps[permutation[i]] = actor.props[i];
        }
        actor.props = newProps;
    }
}
Exemplo n.º 7
0
QString EvaluateSubExpression(const QString& subexpr, const QVariant& v) {
  if (subexpr.size() == 0) {
    // limit the displayed decimal places
    if ((QMetaType::Type)v.type() == QMetaType::Double) {
      return QString::number(v.toDouble(), 'f', 2);
    }
    return v.toString();
  } else if (subexpr.at(0) == '[') {
    int rightbracket = subexpr.indexOf(']');
    if (rightbracket > 0) {
      bool ok = false;
      int index = subexpr.mid(1, rightbracket-1).toInt(&ok);
      if (ok && (QMetaType::Type)v.type() == QMetaType::QVariantList) {
        return EvaluateSubExpression(subexpr.mid(rightbracket + 1),
                                     v.toList().at(index));
      }
    }
  } else {
    int dot = subexpr.indexOf('.');
    QString key = subexpr.mid(0, dot);
    if ((QMetaType::Type)v.type() == QMetaType::QVariantHash) {
      QHash<QString, QVariant> h = v.toHash();
      QHash<QString, QVariant>::const_iterator it = h.find(key);
      if (it != h.end())
        return EvaluateSubExpression(subexpr.mid(key.length() + 1), *it);
    } else if ((QMetaType::Type)v.type() == QMetaType::QVariantMap) {
      QMap<QString, QVariant> h = v.toMap();
      QMap<QString, QVariant>::const_iterator it = h.find(key);
      if (it != h.end())
        return EvaluateSubExpression(subexpr.mid(key.length() + 1), *it);
    }
  }

  return "";
}
Exemplo n.º 8
0
KPrPageLayout * KPrPageLayouts::pageLayout( const QString & name, KoPALoadingContext & loadingContext, const QRectF & pageRect )
{
    KPrPageLayout * pageLayout = 0;

    QHash<QString, KoXmlElement*> layouts = loadingContext.odfLoadingContext().stylesReader().presentationPageLayouts();
    QHash<QString, KoXmlElement*>::iterator it( layouts.find( name ) );

    if ( it != layouts.end() ) {
        pageLayout = new KPrPageLayout();
        if ( pageLayout->loadOdf( *( it.value() ), pageRect ) ) {
            QMap<KPrPageLayoutWrapper, KPrPageLayout *>::const_iterator it( m_pageLayouts.constFind( KPrPageLayoutWrapper( pageLayout ) ) );
            if ( it != m_pageLayouts.constEnd() ) {
                delete pageLayout;
                pageLayout = *it;
            }
            else {
                m_pageLayouts.insert( KPrPageLayoutWrapper( pageLayout ), pageLayout );
            }
        }
        else {
            delete pageLayout;
            pageLayout = 0;
        }
    }
    return pageLayout;
}
Exemplo n.º 9
0
/*
 * Input:   A English word
 * Return:  The translation of the word or NULL if the word not found.
 */
QString QMyHashMap::findWord(QString word)
{
    QHash<QString, QString>::iterator it=dic.find(word);
    if(it==dic.end())
        return "";
    return it.value();
}
Exemplo n.º 10
0
//------------------------------------------------------------------------------
// Name: process_potential_pointer
// Desc:
//------------------------------------------------------------------------------
void DialogHeap::process_potential_pointer(const QHash<edb::address_t, edb::address_t> &targets, Result &result) {
	
	if(IProcess *process = edb::v1::debugger_core->process()) {
		if(result.data.isEmpty()) {
			edb::address_t pointer(0);
			edb::address_t block_ptr = block_start(result);
			edb::address_t block_end = block_ptr + result.size;

			while(block_ptr < block_end) {

				if(process->read_bytes(block_ptr, &pointer, edb::v1::pointer_size())) {
					auto it = targets.find(pointer);
					if(it != targets.end()) {
					#if QT_POINTER_SIZE == 4
						result.data += QString("dword ptr [%1] |").arg(edb::v1::format_pointer(it.key()));
					#elif QT_POINTER_SIZE == 8
						result.data += QString("qword ptr [%1] |").arg(edb::v1::format_pointer(it.key()));
					#endif
					result.points_to.push_back(it.value());
					}
				}

				block_ptr += edb::v1::pointer_size();
			}

			result.data.truncate(result.data.size() - 2);
		}
	}
}
Core::Command *NavigationSubWidget::command(const QString &title) const
{
    const QHash<Id, Command *> commandMap = m_parentWidget->commandMap();
    QHash<Id, Command *>::const_iterator r = commandMap.find(Id::fromString(title));
    if (r != commandMap.end())
        return r.value();
    return 0;
}
Exemplo n.º 12
0
	QHash<int, Collection::Album_ptr> LocalCollectionStorage::GetAllAlbums ()
	{
		QHash<int, Collection::Album_ptr> newAlbums;

		QSqlQuery getter (DB_);
		QHash<int, QStringList> trackGenres;
		if (!getter.exec ("SELECT TrackId, Name FROM genres;"))
		{
			Util::DBLock::DumpError (getter);
			throw std::runtime_error ("cannot fetch genres");
		}

		while (getter.next ())
			trackGenres [getter.value (0).toInt ()] << getter.value (1).toString ();

		if (!getter.exec ("SELECT albums.Id, albums.Name, albums.Year, albums.CoverPath, tracks.Id, tracks.TrackNumber, tracks.Name, tracks.Length, tracks.Path FROM tracks INNER JOIN albums ON tracks.AlbumID = albums.Id;"))
		{
			Util::DBLock::DumpError (getter);
			throw std::runtime_error ("cannot fetch albums");
		}

		while (getter.next ())
		{
			const int albumID = getter.value (0).toInt ();
			auto albumPos = newAlbums.find (albumID);
			if (albumPos == newAlbums.end ())
			{
				const Collection::Album a =
				{
					albumID,
					getter.value (1).toString (),
					getter.value (2).toInt (),
					getter.value (3).toString (),
					QList<Collection::Track> ()
				};
				albumPos = newAlbums.insert (albumID, Collection::Album_ptr (new Collection::Album (a)));
			}

			auto albumPtr = *albumPos;
			auto& tracks = albumPtr->Tracks_;

			const int trackId = getter.value (4).toInt ();
			Collection::Track t =
			{
				trackId,
				getter.value (5).toInt (),
				getter.value (6).toString (),
				getter.value (7).toInt (),
				trackGenres.value (trackId),
				getter.value (8).toString ()
			};

			tracks << t;
		}
		getter.finish ();

		return newAlbums;
	}
Exemplo n.º 13
0
bool ODFItem::setFileId(const QHash<QString, quint64> &names, const QString& value, quint64 &fileid) const {
    if ( value == sUNDEF) {
        fileid = i64UNDEF;
        return true; // legal; some properties might not have a value(name)
    }
    if ( Ilwis3Connector::ilwisType(value) & itCOORDSYSTEM) {
        if ( value == "latlonwgs84.csy" ) {
            Resource resource = mastercatalog()->name2Resource("code=epsg:4326", itCOORDSYSTEM);
            if ( !resource.isValid()) {
               return ERROR1(ERR_FIND_SYSTEM_OBJECT_1, "Wgs 84");
            }
            fileid = resource.id();
            return true;
        }
        if ( value == "unknown.csy" ) {
            Resource resource = mastercatalog()->name2Resource("code=csy:unknown", itCOORDSYSTEM);
            if ( !resource.isValid()) {
                return ERROR1(ERR_FIND_SYSTEM_OBJECT_1, "'Unknown' coordinate system");
            }
            fileid = resource.id();
            return true;
        }
    }
    if ( Ilwis3Connector::ilwisType(value) & itGEOREF) {
        if ( value == "none.grf" ) {
            Resource resource = mastercatalog()->name2Resource("code=georef:undetermined", itGEOREF);
            if ( !resource.isValid()) {
                return ERROR1(ERR_FIND_SYSTEM_OBJECT_1, "'undetermined' georeference");
            }
            fileid = resource.id();
            return true;
        }
    }
    QString completeName =  (value.contains(QRegExp("\\\\|/"))) ? value : _ini.fileInfo().canonicalPath() + "/" + value;
    QHash<QString, quint64>::const_iterator iter = names.find(completeName.toLower());
    if (iter != names.end()){
        fileid = iter.value();
    } else {
        // at this time we can't rely on the working catalog to be set(if we are initializing it), so no normal resolve
        // the mastercatalog will contain system items at this moment so we can check these first
        QString baseName = value.left(value.indexOf("."));
        IlwisTypes tp = Ilwis3Connector::ilwisType(value);
        Resource resource = mastercatalog()->name2Resource(baseName, tp);
        if ( resource.isValid()) {
            fileid = resource.id();
        } else {
            QUrl url = QUrl::fromLocalFile(completeName);
            fileid = mastercatalog()->url2id(url, tp);
            if ( fileid == i64UNDEF) {
                kernel()->issues()->log(TR(ERR_MISSING_1).arg(completeName));
                fileid = i64UNDEF;
                return false;
            }
        }
    }
    return true;

}
Exemplo n.º 14
0
bool ContentDialog::hasWidget(int id, GenericChatroomWidget* chatroomWidget, const QHash<int, std::tuple<ContentDialog*, GenericChatroomWidget*>>& list)
{
    auto iter = list.find(id);

    if (iter == list.end() || std::get<0>(iter.value()) != this)
        return false;

    return chatroomWidget == std::get<1>(iter.value());
}
Exemplo n.º 15
0
bool ContentDialog::isWidgetActive(int id, const QHash<int, std::tuple<ContentDialog *, GenericChatroomWidget *> > &list)
{
    auto iter = list.find(id);

    if (iter == list.end())
        return false;

    return std::get<0>(iter.value())->activeChatroomWidget == std::get<1>(iter.value());
}
Exemplo n.º 16
0
bool needTangents(const hfm::Mesh& mesh, const QHash<QString, hfm::Material>& materials) {
    // Check if we actually need to calculate the tangents
    for (const auto& meshPart : mesh.parts) {
        auto materialIt = materials.find(meshPart.materialID);
        if (materialIt != materials.end() && (*materialIt).needTangentSpace()) {
            return true;
        }
    }
    return false;
}
Exemplo n.º 17
0
void loadStylesheet(const QString &name, QHash<QString, StyleData> &dict)
{
   QFile file(name);

   if (! file.open(QIODevice::ReadOnly)) {
      err("Unable to open RTF style sheet file %s, using default file\n", qPrintable(name));
      return;
   }
   msg("Loading RTF style sheet %s\n", qPrintable(name));

   static const QRegExp seperator("[ \t]*=[ \t]*");
   uint lineNr = 1;

   QTextStream t(&file);
   t.setCodec("UTF-8");

   while (! t.atEnd()) {
      QString s = t.readLine().trimmed();

      if (s.isEmpty() || s.at(0) == '#') {
         continue;   // skip blanks & comments
      }

      int sepStart;
      int sepLength;
      
      sepStart  = seperator.indexIn(s);
      sepLength = seperator.matchedLength();  

      if (sepStart <= 0) {
         // no valid assignment statement
         warn(qPrintable(name), lineNr, "Assignment of style sheet name expected\n");
         continue;
      }

      QString key = s.left(sepStart);

      if (! dict.contains(key)) { 
         // not a valid style sheet name
         warn(qPrintable(name), lineNr, "Invalid style sheet name %s ignored.\n", qPrintable(key));
         continue;
      }

      // add command separator   
      StyleData &styleData = dict.find(key).value();

      s += " "; 
      styleData.setStyle(s.mid(sepStart + sepLength), key);

      lineNr++;
   }
}
Exemplo n.º 18
0
	/*
		Check if in the value string there are variable or property tags

		If it is a variable tag try to get the value from the variables lists.

		Variables tags are betweeen square brackets [].
		Property tags are between curl brackets {}.

		If the variable/property tag is not found, it is replaced by an empty string.
	*/
	void RuleNode::tagsToValue( QString& value, const QHash<QString, QString>& variables )
	{
		static QString empty;

		// VARIABLES
		QRegExp regex_variables_tags( "(\\[[a-zA-Z0-9_\\- \\.]+\\])", Qt::CaseInsensitive );
		// Search for variable value is between square brackets
		int pos = 0;
		while( (pos = regex_variables_tags.indexIn( value, pos ) ) != -1 )
		{
			QString var = regex_variables_tags.cap( 1 );
			//pos += regex.matchedLength();

			// Search for the variable in the variables list
			QHash<QString,QString>::const_iterator it = variables.find( var );
			if( it != variables.end()  )
			{
				// found it, replace by the variable tag, by the variable value
				value.replace( var, it.value(), Qt::CaseInsensitive );
				pos += it.value().length();
			}
			else
			{
				// not found replace by an empty string
				value.replace( var, empty, Qt::CaseInsensitive );
			}
		}

		// PROPERTIES
		QRegExp regex_properties_tags( "\\{([a-zA-Z0-9_\\- \\.]+)\\}", Qt::CaseInsensitive );
		// Search for variable value is between curl brackets
		pos = 0;
		while( (pos = regex_properties_tags.indexIn( value, pos ) ) != -1 )
		{
			QString var = regex_properties_tags.cap( 1 );

			// Search for the variable in the variables list
			QHash<QString,QString>::const_iterator it = _brain->_properties.find( var );
			if( it != _brain->_properties.end()  )
			{
				// found it, replace by the property tag, by the property value
				value.replace( "{" + var + "}", it.value(), Qt::CaseInsensitive );
				pos += it.value().length();
			}
			else
			{
				// not found replace by an empty string
				value.replace( var, empty, Qt::CaseInsensitive );
			}
		}

	}
Exemplo n.º 19
0
void qHashBench() {
    QElapsedTimer timer;
    timer.start();
    QHash<int,triple> data;
    triple point;
    int i;

    for (i = 0; i < RAND_COUNT; ++i) {
        point.x = i;
        point.y = rand();
        point.z = rand();
        //printf("%d %d %d %d\n", i, point.x, point.y, point.z);
        data[i] = point;
    }
    qDebug() << Q_FUNC_INFO << "creation: elapsed" << timer.elapsed();
    timer.restart();
    foreach (const triple &t, data) {
        if (t.x % 1000 == 0)
            doSomething(t.x);
    }
    qDebug() << "   foreach: elapsed" << timer.elapsed();
#if QT_VERSION >= 0x050700
    timer.restart();
    foreach (const triple &t, qAsConst(data)) {
        if (t.x % 1000 == 0)
            doSomething(t.x);
    }
    qDebug() << "   qAsConst foreach: elapsed" << timer.elapsed();
#endif
    timer.restart();
    for( auto it = data.begin(); it != data.end(); ++it ) {
        if (it->x % 1000 == 0)
            doSomething(it->x);
    }
    qDebug() << "   range-based for: elapsed" << timer.elapsed();
#if QT_VERSION >= 0x050700
    timer.restart();
    for( auto it = qAsConst(data).begin(); it != qAsConst(data).end(); ++it ) {
        if (it->x % 1000 == 0)
            doSomething(it->x);
    }
    qDebug() << "   qAsConst range-based for: elapsed" << timer.elapsed();
#endif
    timer.restart();
    for (i = 0; i < RAND_COUNT; ++i) {
        auto it = data.find(i);
        Q_ASSERT(it.value().x == i);
        if (it->x % 1000 == 0)
            doSomething(it.value().x);
    }
    qDebug() << "   find: elapsed" << timer.elapsed();
}
Exemplo n.º 20
0
void RunnerModel::matchesChanged(const QList<Plasma::QueryMatch> &matches)
{
    // Group matches by runner
    // We do not use a QMultiHash here because it keeps values in LIFO order, while we want FIFO.
    QHash<QString, QList<Plasma::QueryMatch> > matchesForRunner;
    Q_FOREACH(const Plasma::QueryMatch &match, matches) {
        QString runnerId = match.runner()->id();
        auto it = matchesForRunner.find(runnerId);
        if (it == matchesForRunner.end()) {
            it = matchesForRunner.insert(runnerId, QList<Plasma::QueryMatch>());
        }
        it.value().append(match);
    }
Exemplo n.º 21
0
void ContentDialog::updateStatus(int id, const QHash<int, std::tuple<ContentDialog *, GenericChatroomWidget *> > &list)
{
    auto iter = list.find(id);

    if (iter == list.end())
        return;

    GenericChatroomWidget* chatroomWidget = std::get<1>(iter.value());
    chatroomWidget->updateStatusLight();

    if (chatroomWidget->isActive())
        std::get<0>(iter.value())->updateTitle(chatroomWidget);
}
void Erosion::Arguments(const QHash<QString, QString> &args, int& shape, int& ksize)
{
	bool ok = false;
	QHash<QString, QString>::const_iterator it;

	if ((it = args.find("Value")) != args.end()) {
		ksize = it.value().toInt(&ok);

		if (!ok) {
			throw FormatException("couldn't convert \"Value\" argument for erosion");
		} else if (ksize < 0) {
			throw ArgumentException("\"Value\" argument for erosion must be positive");
		}
		ksize = 2 * (ksize-1) + 1;
	}

	if ((it = args.find("Shape")) != args.end()) {
		if (it.value() == "Rect") {
			shape = cv::MORPH_RECT;
		} else if (it.value() == "Cross") {
			shape = cv::MORPH_CROSS;
		} else if (it.value() == "Ellipse") {
			shape = cv::MORPH_ELLIPSE;
		} else {
			throw ArgumentException("\"Shape\" doesn't name an existing type");
		}
	}

	if ((it = args.find("KernelSize")) != args.end()) {
		ksize = it.value().toInt(&ok);

		if (!ok) {
			throw FormatException("couldn't convert \"KernelSize\" argument for dilation effect");
		} else if (ksize < 0) {
			throw ArgumentException("\"KernelSize\" argument for dilation effect must be positive");
		}
		ksize = 2 * (ksize-1) + 1;
	}
}
Exemplo n.º 23
0
bool QWSPropertyManager::getProperty(int winId, int property, const char *&data, int &len)
{
    QHash<int, QByteArray> props = d->properties.value(winId);
    QHash<int, QByteArray>::iterator it = props.find(property);
    if (it == props.end()) {
        data = 0;
        len = -1;
        return false;
    }
    data = it.value().constData();
    len = it.value().length();

    return true;
}
Exemplo n.º 24
0
void
CDBirthdayController::syncBirthdays(const QList<QContact> &birthdayContacts)
{
    QHash<ContactIdType, CalendarBirthday> oldBirthdays = mCalendar->birthdays();

    // Check all birthdays from the contacts if the stored calendar item is up-to-date
    foreach (const QContact &contact, birthdayContacts) {
#ifdef USING_QTPIM
        const QString contactDisplayLabel = contact.detail<QContactDisplayLabel>().label();
#else
        const QString contactDisplayLabel = contact.displayLabel();
#endif

        if (contactDisplayLabel.isNull()) {
            debug() << "Contact: " << contact << " has no displayLabel, so not syncing to calendar";
            continue;
        }

        QHash<ContactIdType, CalendarBirthday>::Iterator it = oldBirthdays.find(apiId(contact));

        if (oldBirthdays.end() != it) {
            const QContactBirthday contactBirthday = contact.detail<QContactBirthday>();
            const CalendarBirthday &calendarBirthday = *it;

            // Display label or birthdate was changed on the contact, so update the calendar.
            if ((contactDisplayLabel != calendarBirthday.summary()) ||
                (contactBirthday.date() != calendarBirthday.date())) {
                debug() << "Contact with calendar birthday: " << contactBirthday.date()
                        << " and calendar displayLabel: " << calendarBirthday.summary()
                        << " changed details to: " << contact << ", so update the calendar event";

                mCalendar->updateBirthday(contact);
            }

            // Birthday exists, so not a garbage one
            oldBirthdays.erase(it);
        } else {
            // Create new birthday
            mCalendar->updateBirthday(contact);
        }
    }

    // Remaining old birthdays in the calendar db do not did not match any contact, so remove them.
    foreach (const ContactIdType &id, oldBirthdays.keys()) {
        debug() << "Birthday with contact id" << id << "no longer has a matching contact, trashing it";
        mCalendar->deleteBirthday(id);
    }
}
Exemplo n.º 25
0
void scriptRemoveObject(const BASE_OBJECT *psObj)
{
	for (QHash<int, bindNode>::iterator i = bindings.find(psObj->id); i != bindings.end(); i++)
	{
		int id = i.key();
		bindNode node = i.value();
		BASE_OBJECT *psObj = IdToPointer(id, node.player);
		if (psObj && !psObj->died)
		{
			QScriptValueList args;
			args += convMax(psObj, node.engine);
			callFunction(node.engine, node.funcName, args);
		}
		bindings.erase(i);
	}
}
Exemplo n.º 26
0
 /**
  * Find a class in the cache.
  *
  * \param recurse if true the method will try loading dependancies (i.e.
  * other ontologies to fulfill the requirement
  */
 Class* findClass( const QUrl& uri, bool recurse = false ) {
     QHash<QUrl, Class>::iterator it = classCache.find( uri );
     if ( it != classCache.end() ) {
         return &it.value();
     }
     else {
         if ( recurse ) {
             // try loading the ontology containing the class
             QUrl parentNs = extractNamespace( uri );
             if ( m_manager->getOntology( parentNs ) ) {
                 return findClass( uri );
             }
         }
         return 0;
     }
 }
Exemplo n.º 27
0
 /**
  * Find a property in the cache.
  *
  * \param recurse if true the method will try loading dependancies (i.e.
  * other ontologies to fulfill the requirement
  */
 Property* findProperty( const QUrl& uri, bool recurse = false ) {
     QHash<QUrl, Property>::iterator it = propertyCache.find( uri );
     if ( it != propertyCache.end() ) {
         return &it.value();
     }
     else {
         if ( recurse ) {
             // try loading the ontology containing the property
             QUrl parentNs = extractNamespace( uri );
             if ( m_manager->getOntology( parentNs ) ) {
                 return findProperty( uri );
             }
         }
         return 0;
     }
 }
Exemplo n.º 28
0
void Sobel::Arguments(const QHash<QString, QString> &args, int& ksize)
{
	bool ok = false;
	QHash<QString,QString>::const_iterator it;

	if ((it = args.find("Value")) != args.end()) {
		ksize = it.value().toInt(&ok);

		if (!ok) {
			throw FormatException("couldn't convert \"Value\" argument for sobel");
		} else if (ksize < 0) {
			throw ArgumentException("\"Value\" argument for sobel must be positive");
		}
		ksize = (2 * (ksize-1) + 1);
		ksize = ksize > 31 ? 31 : ksize;
	}
}
Exemplo n.º 29
0
bool ContentDialog::existsWidget(int id, bool focus, const QHash<int, std::tuple<ContentDialog*, GenericChatroomWidget*>>& list)
{
    auto iter = list.find(id);
    if (iter == list.end())
        return false;

    if (focus)
    {
        if (std::get<0>(iter.value())->windowState() & Qt::WindowMinimized)
            std::get<0>(iter.value())->showNormal();

        std::get<0>(iter.value())->raise();
        std::get<0>(iter.value())->activateWindow();
        std::get<0>(iter.value())->onChatroomWidgetClicked(std::get<1>(iter.value()), false);
    }

    return true;
}
Exemplo n.º 30
0
int VPreviewManager::calculateBlockMargin(const QTextBlock &p_block, int p_tabStopWidth)
{
    static QHash<QString, int> spaceWidthOfFonts;

    if (!p_block.isValid()) {
        return 0;
    }

    QString text = p_block.text();
    int nrSpaces = 0;
    for (int i = 0; i < text.size(); ++i) {
        if (!text[i].isSpace()) {
            break;
        } else if (text[i] == ' ') {
            ++nrSpaces;
        } else if (text[i] == '\t') {
            nrSpaces += p_tabStopWidth;
        }
    }

    if (nrSpaces == 0) {
        return 0;
    }

    int spaceWidth = 0;
    QFont font;
    QVector<QTextLayout::FormatRange> fmts = p_block.layout()->formats();
    if (fmts.isEmpty()) {
        font = p_block.charFormat().font();
    } else {
        font = fmts.first().format.font();
    }

    QString fontName = font.toString();
    auto it = spaceWidthOfFonts.find(fontName);
    if (it != spaceWidthOfFonts.end()) {
        spaceWidth = it.value();
    } else {
        spaceWidth = QFontMetrics(font).width(' ');
        spaceWidthOfFonts.insert(fontName, spaceWidth);
    }

    return spaceWidth * nrSpaces;
}