QString Human::filterString() const { std::stringstream completeString; completeString << name().toStdString() << " " << profession().toStdString(); return (QString(completeString.str().c_str())); }
/*! Returns a rich text formatted QString representing the contents the contact. */ QString OPimContact::toRichText() const { QString text; QString value, comp, state; QString str; bool marker = false; Config cfg( "qpe" ); cfg.setGroup( "Appearance" ); int addressformat = cfg.readNumEntry( "AddressFormat", Zip_City_State ); // name, jobtitle and company if ( !( value = fullName() ).isEmpty() ) text += "<b><h3><img src=\"addressbook/AddressBook\"> " + Qtopia::escapeString( value ) + "</h3></b>"; if ( !( value = jobTitle() ).isEmpty() ) text += Qtopia::escapeString( value ) + " "; comp = company(); if ( !( value = department() ).isEmpty() ) { text += Qtopia::escapeString( value ); if ( comp ) text += ", " + Qtopia::escapeString( comp ); } else if ( comp ) text += "<br>" + Qtopia::escapeString( comp ); text += "<br><hr>"; // defailt email QString defEmail = defaultEmail(); if ( !defEmail.isEmpty() ) { text += "<b><img src=\"addressbook/email\"> " + QObject::tr( "Default Email: " ) + "</b>" + Qtopia::escapeString( defEmail ); marker = true; } // business address if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || !businessZip().isEmpty() || !businessCountry().isEmpty() ) { text += QObject::tr( "<br><b>Work Address:</b>" ); marker = true; } if ( !( value = businessStreet() ).isEmpty() ) { text += "<br>" + Qtopia::escapeString( value ); marker = true; } switch ( addressformat ) { case Zip_City_State: { // Zip_Code City, State state = businessState(); if ( !( value = businessZip() ).isEmpty() ) { text += "<br>" + Qtopia::escapeString( value ) + " "; marker = true; } if ( !( value = businessCity() ).isEmpty() ) { marker = true; if ( businessZip().isEmpty() && !businessStreet().isEmpty() ) text += "<br>"; text += Qtopia::escapeString( value ); if ( state ) text += ", " + Qtopia::escapeString( state ); } else if ( !state.isEmpty() ) { text += "<br>" + Qtopia::escapeString( state ); marker = true; } break; } case City_State_Zip: { // City, State Zip_Code state = businessState(); if ( !( value = businessCity() ).isEmpty() ) { marker = true; text += "<br>" + Qtopia::escapeString( value ); if ( state ) text += ", " + Qtopia::escapeString( state ); } else if ( !state.isEmpty() ) { text += "<br>" + Qtopia::escapeString( state ); marker = true; } if ( !( value = businessZip() ).isEmpty() ) { text += " " + Qtopia::escapeString( value ); marker = true; } break; } } if ( !( value = businessCountry() ).isEmpty() ) { text += "<br>" + Qtopia::escapeString( value ); marker = true; } // rest of Business data str = office(); if ( !str.isEmpty() ) { text += "<br><b>" + QObject::tr( "Office: " ) + "</b>" + Qtopia::escapeString( str ); marker = true; } str = businessWebpage(); if ( !str.isEmpty() ) { text += "<br><b><img src=\"addressbook/webpagework\"> " + QObject::tr( "Business Web Page: " ) + "</b>" + Qtopia::escapeString( str ); marker = true; } str = businessPhone(); if ( !str.isEmpty() ) { text += "<br><b><img src=\"addressbook/phonework\"> " + QObject::tr( "Business Phone: " ) + "</b>" + Qtopia::escapeString( str ); marker = true; } str = businessFax(); if ( !str.isEmpty() ) { text += "<br><b><img src=\"addressbook/faxwork\"> " + QObject::tr( "Business Fax: " ) + "</b>" + Qtopia::escapeString( str ); marker = true; } str = businessMobile(); if ( !str.isEmpty() ) { text += "<br><b><img src=\"addressbook/mobilework\"> " + QObject::tr( "Business Mobile: " ) + "</b>" + Qtopia::escapeString( str ); marker = true; } str = businessPager(); if ( !str.isEmpty() ) { text += "<br><b>" + QObject::tr( "Business Pager: " ) + "</b>" + Qtopia::escapeString( str ); marker = true; } // text += "<br>"; // home address if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || !homeZip().isEmpty() || !homeCountry().isEmpty() ) { text += QObject::tr( "<br><b>Home Address:</b>" ); marker = true; } if ( !( value = homeStreet() ).isEmpty() ) { text += "<br>" + Qtopia::escapeString( value ); marker = true; } switch ( addressformat ) { case Zip_City_State: { // Zip_Code City, State state = homeState(); if ( !( value = homeZip() ).isEmpty() ) { text += "<br>" + Qtopia::escapeString( value ) + " "; marker = true; } if ( !( value = homeCity() ).isEmpty() ) { marker = true; if ( homeZip().isEmpty() && !homeStreet().isEmpty() ) text += "<br>"; text += Qtopia::escapeString( value ); if ( !state.isEmpty() ) text += ", " + Qtopia::escapeString( state ); } else if ( !state.isEmpty() ) { text += "<br>" + Qtopia::escapeString( state ); marker = true; } break; } case City_State_Zip: { // City, State Zip_Code state = homeState(); if ( !( value = homeCity() ).isEmpty() ) { marker = true; text += "<br>" + Qtopia::escapeString( value ); if ( state ) text += ", " + Qtopia::escapeString( state ); } else if ( !state.isEmpty() ) { text += "<br>" + Qtopia::escapeString( state ); marker = true; } if ( !( value = homeZip() ).isEmpty() ) { text += " " + Qtopia::escapeString( value ); marker = true; } break; } } if ( !( value = homeCountry() ).isEmpty() ) { text += "<br>" + Qtopia::escapeString( value ); marker = true; } // rest of Home data str = homeWebpage(); if ( !str.isEmpty() ) { text += "<br><b><img src=\"addressbook/webpagehome\"> " + QObject::tr( "Home Web Page: " ) + "</b>" + Qtopia::escapeString( str ); marker = true; } str = homePhone(); if ( !str.isEmpty() ) { text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr( "Home Phone: " ) + "</b>" + Qtopia::escapeString( str ); marker = true; } str = homeFax(); if ( !str.isEmpty() ) { text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr( "Home Fax: " ) + "</b>" + Qtopia::escapeString( str ); marker = true; } str = homeMobile(); if ( !str.isEmpty() ) { text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr( "Home Mobile: " ) + "</b>" + Qtopia::escapeString( str ); marker = true; } if ( marker ) text += "<br><hr>"; // the rest... str = emails(); if ( !str.isEmpty() && ( str != defEmail ) ) text += "<br><b>" + QObject::tr( "All Emails: " ) + "</b>" + Qtopia::escapeString( str ); str = profession(); if ( !str.isEmpty() ) text += "<br><b>" + QObject::tr( "Profession: " ) + "</b>" + Qtopia::escapeString( str ); str = assistant(); if ( !str.isEmpty() ) text += "<br><b>" + QObject::tr( "Assistant: " ) + "</b>" + Qtopia::escapeString( str ); str = manager(); if ( !str.isEmpty() ) text += "<br><b>" + QObject::tr( "Manager: " ) + "</b>" + Qtopia::escapeString( str ); str = gender(); if ( !str.isEmpty() && str.toInt() != 0 ) { text += "<br>"; if ( str.toInt() == 1 ) str = QObject::tr( "Male" ); else if ( str.toInt() == 2 ) str = QObject::tr( "Female" ); text += "<b>" + QObject::tr( "Gender: " ) + "</b>" + str; } str = spouse(); if ( !str.isEmpty() ) text += "<br><b>" + QObject::tr( "Spouse: " ) + "</b>" + Qtopia::escapeString( str ); if ( birthday().isValid() ) { str = TimeString::numberDateString( birthday() ); text += "<br><b>" + QObject::tr( "Birthday: " ) + "</b>" + Qtopia::escapeString( str ); } if ( anniversary().isValid() ) { str = TimeString::numberDateString( anniversary() ); text += "<br><b>" + QObject::tr( "Anniversary: " ) + "</b>" + Qtopia::escapeString( str ); } str = children(); if ( !str.isEmpty() ) text += "<br><b>" + QObject::tr( "Children: " ) + "</b>" + Qtopia::escapeString( str ); str = nickname(); if ( !str.isEmpty() ) text += "<br><b>" + QObject::tr( "Nickname: " ) + "</b>" + Qtopia::escapeString( str ); // categories if ( categoryNames( "Contacts" ).count() ) { text += "<br><b>" + QObject::tr( "Category:" ) + "</b> "; text += categoryNames( "Contacts" ).join( ", " ); } // notes last if ( !( value = notes() ).isEmpty() ) { text += "<br><hr><b>" + QObject::tr( "Notes:" ) + "</b> "; QRegExp reg( "\n" ); //QString tmp = Qtopia::escapeString(value); QString tmp = QStyleSheet::convertFromPlainText( value ); //tmp.replace( reg, "<br>" ); text += "<br>" + tmp + "<br>"; } return text; }
void Human::print() { qDebug() << name() << "-" << profession(); qDebug() << " Exp:" << experience() << " Health:" << health(); }
QVariant Human::data(int role) const { switch(role) { case IdRole: return (unsigned int)id(); case FilterStringRole: return filterString(); case ProfessionRole: return profession(); case PosXRole: return posX(); case PosYRole: return posY(); case PosZRole: return posZ(); case NameRole: return name(); case ArcherLevelRole: return archerLevel(); case BlacksmithLevelRole: return blacksmithLevel(); case BuilderLevelRole: return builderLevel(); case CarpenterLevelRole: return carpenterLevel(); case EngineerLeveRole: return engineerLevel(); case FarmerLevelRole: return farmerLevel(); case FishermanLevelRole: return fishermanLevel(); case ForagerLevelRole: return foragerLevel(); case InfantryLevelRole: return infantryLevel(); case MinerLevelRole: return minerLevel(); case StoneMasonLevelRole: return stoneMasonLevel(); case WoodChopperLevelRole: return woodChopperLevel(); case TailorLevelRole: return tailorLevel(); case TraderLevelRole: return traderLevel(); case HerderLevelRole: return herderLevel(); case AdventurerLevelRole: return adventurerLevel(); case Unknown1Role: return unknown1Level(); case Unknown2Role: return unknown2Level(); case Unknown3Role: return unknown3Level(); case Unknown4Role: return unknown4Level(); case ExperienceRole: return experience(); case AutoChopTreesRole: return autoChop(); case GatherBerriesRole: return gatherBerries(); case HuntChickenRole: return huntChicken(); case HuntBoarRole: return huntBoar(); case ShowBowRangeRole: return showBowRange(); case TrainNearTargetRole: return trainNearTarget(); case RotationRole: return rotation(); case EquipHandRole: return equipHand(); case EquipOffhandRole: return equipOffhand(); case EquipHeadRole: return equipHead(); case EquipBodyRole: return equipBody(); case EquipFeetRole: return equipFeet(); case HealthRole: return health(); case MoraleRole: return morale(); case FatigueRole: return fatigue(); case HungerRole: return hunger(); default: return QVariant(); } }
/** * @brief Write the Human data back to a file. */ void Human::writeToFile( QFile &unitFile ) { QTextStream unitStream(&unitFile); unitStream << profession() << "/" << QString("%1").arg(posX(),0,'g',8) << "/" << QString("%1").arg(posY(),0,'g',8) << "/" << QString("%1").arg(posZ(),0,'g',8) << "/" << name() << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(archerLevel())); unitFile.write(Utils::toBinary(blacksmithLevel())); unitFile.write(Utils::toBinary(builderLevel())); unitFile.write(Utils::toBinary(carpenterLevel()).constData()); unitFile.write(Utils::toBinary(engineerLevel()).constData()); unitFile.write(Utils::toBinary(farmerLevel()).constData()); unitFile.write(Utils::toBinary(fishermanLevel()).constData()); unitFile.write(Utils::toBinary(foragerLevel()).constData()); unitFile.write(Utils::toBinary(infantryLevel()).constData()); unitFile.write(Utils::toBinary(minerLevel()).constData()); unitFile.write(Utils::toBinary(stoneMasonLevel()).constData()); unitFile.write(Utils::toBinary(woodChopperLevel()).constData()); unitFile.write(Utils::toBinary(tailorLevel()).constData()); unitFile.write(Utils::toBinary(traderLevel()).constData()); unitFile.write(Utils::toBinary(herderLevel()).constData()); unitFile.write(Utils::toBinary(adventurerLevel()).constData()); unitFile.write(Utils::toBinary(unknown1Level()).constData()); unitFile.write(Utils::toBinary(unknown2Level()).constData()); unitFile.write(Utils::toBinary(unknown3Level()).constData()); unitFile.write(Utils::toBinary(unknown4Level()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(experience()).constData()); unitStream << "/"; unitStream.flush(); unitStream << QString(autoChop()?"True":"False") << "/" << QString(gatherBerries()?"True":"False") << "/" << QString(huntChicken()?"True":"False") << "/" << QString(huntBoar()?"True":"False") << "/" << QString(showBowRange()?"True":"False") << "/"; unitStream << QString(trainNearTarget()?"True":"False") << "/"; unitStream << QString("%1").arg(rotation(),0,'g',8) << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipHand()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipOffhand()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipHead()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipBody()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipFeet()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(health()).constData()); unitStream << "/"; unitStream.flush(); // Dump some of the options in the file. for (unsigned int i = 0; i<52; i++) { unitStream << QString(option(i)?"True":"False") << "/"; } unitStream << timeToEat() << "/" << morale() << "/" << fatigue() << "/" << hunger() << "/"; // Dump more options in the file. for (unsigned int i = 52; i<52+12; i++) { unitStream << QString(option(i)?"True":"False") << "/"; } // Inventory Preferences for (int i = 0; i<inventoryPreferences()->length(); i++) { unitStream << inventoryPreferences()->at(i) << "/"; } // Inventory Items unitStream << inventoryItems()->length() << "/"; for (int i = 0; i<inventoryItems()->length(); i++) { unitStream << inventoryItems()->at(i) << "/"; } // Spare Inventory unitStream << spareInventory()->length() << "/"; for (int i = 0; i<spareInventory()->length(); i++) { unitStream << spareInventory()->at(i) << "/"; } // Patrol unitStream << patrolSetpoints()->length() << "/"; for (int i = 0; i<patrolSetpoints()->length(); i++) { unitStream << patrolSetpoints()->at(i) << "/"; } unitStream << patrolIndex() << "/"; unitStream << guardedUnit() << "/"; // Profession Experience for (int i = 0; i<professionEXP()->length(); i++) { unitStream << professionEXP()->at(i) << "/"; } unitStream << maxWeight() << "/"; unitStream << endl; unitStream.flush(); }