void EntityIdentifier::parseEntityDefinition(JSONObject *entity, QString const &category, QColor catcolor, int packID) { QString id; if (entity->has("id")) id = entity->at("id")->asString(); else id = "Unknown"; if (entity->has("catcolor")) { QString colorname = entity->at("catcolor")->asString(); catcolor.setNamedColor(colorname); assert(catcolor.isValid()); } QColor color; if (entity->has("color")) { QString colorname = entity->at("color")->asString(); color.setNamedColor(colorname); assert(color.isValid()); } else { // use hashed by name instead quint32 hue = qHash(id); color.setHsv(hue % 360, 255, 255); } QString name = id; if (entity->has("name")) { name = entity->at("name")->asString(); } // enter entity into manager TentityMap& map = getMapForPackID(packID); map.insert(id, EntityInfo(name, category, catcolor, color)); }
void EntityIdentifier::parseEntityDefinition(JSONObject *entity, QString const &category, QColor catcolor, int packID) { QString id("unknown"); if (entity->has("id")) id = entity->at("id")->asString().toLower(); if (entity->has("catcolor")) { QString colorname = entity->at("catcolor")->asString(); catcolor.setNamedColor(colorname); assert(catcolor.isValid()); } QColor color; if (entity->has("color")) { QString colorname = entity->at("color")->asString(); color.setNamedColor(colorname); assert(color.isValid()); } else { // use hashed by name instead quint32 hue = qHash(id); color.setHsv(hue % 360, 255, 255); } QString name; if (entity->has("name")) { // use provided name name = entity->at("name")->asString(); } else { // or try to build name automatically // split at underscores QStringList tokens = id.toLower().replace('_',' ').split(" "); // make first character uppercase for (QList<QString>::iterator tokItr = tokens.begin(); tokItr != tokens.end(); ++tokItr) { (*tokItr) = (*tokItr).at(0).toUpper() + (*tokItr).mid(1); } name = tokens.join(" "); } // enter entity into manager TentityMap& map = getMapForPackID(packID); map.insert(id, EntityInfo(name, category, catcolor, color)); // add duplicates: when new 1.11+ or 1.13+ id definitions are available // legacy id is stored in own definition element (duplicates automatically) if (entity->has("idlist")) { JSONArray *idlist = dynamic_cast<JSONArray *>(entity->at("idlist")); int len = idlist->length(); for (int j = 0; j < len; j++) { QString idl = entity->at("idlist")->at(j)->asString().toLower(); map.insert(idl, EntityInfo(name, category, catcolor, color)); } } }
Entity EntityManager::createEntity() { Entity nextEntity; // If an old entity is available for reuse if (_dead.getSize() != 0) { // Get last dead entity and bring it back to life nextEntity = _dead.popBack(); _alive.add(nextEntity); } else { EntityId newId = _nextEntityId++; // Add entity to master list of entities if this is a completely new entity _entities.set(newId, EntityInfo(newId)); // Set entity ID to return nextEntity._id = newId; } // Create new entity _alive.add(nextEntity); // Update counters _totalCreated++; _count++; // Return entity id return nextEntity; }
void AsyncEntityListFilter::onWorkerFinished(EntityInstanceList matched, EntityInstanceList skipped) { QMutexLocker lck(&aMtx); if(aWorkerState != EntityListFilterState::Idle) aWorkerCancel.unlock(); if(!aQueueList.isEmpty()){ EntityInstanceList l(aQueueList); EntityInfo i(aQueueInfo); EntityCompareConditions f(aQueueFilter); aQueueList= EntityInstanceList(); aQueueInfo= EntityInfo(); aQueueFilter= EntityCompareConditions(); emit invokeWorkerFilter(&aWorkerCancel, l, i, f); }else{ emit done(matched, skipped, (aWorkerState != EntityListFilterState::Idle)); aWorkerState= EntityListFilterState::Idle; } }
* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses/>. */ #include <QtCore> #include "task.h" // Global static instance used to ensure a single instance of the class. EntityInfo Task::aInfo= EntityInfo(); // This function is called to create an instance of the class. // Calling the constructor publicly is not allowed. The constructor // is private and is only called by this Instance function. const EntityInfo &Task::info() { if (aInfo.isEmpty()){ aInfo.aName2property.insert(QObject::tr("Type"),TaskProperty::Type); aInfo.aName2property.insert(QObject::tr("Source"),TaskProperty::Source); aInfo.aName2property.insert(QObject::tr("Destination"),TaskProperty::Destination); aInfo.aInfo.insert(TaskProperty::Type, PropertyInfo("\\d{12}", "\\d{12}", QVariant::Int)); aInfo.aInfo.insert(TaskProperty::Source, PropertyInfo(".*", ".*", QVariant::String)); aInfo.aInfo.insert(TaskProperty::Destination, PropertyInfo(".*", ".*", QVariant::String));