PageRenderTime 21ms CodeModel.GetById 7ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/src/grid_view/militarypreferencecolumn.cpp

https://code.google.com/p/dwarftherapist/
C++ | 106 lines | 72 code | 11 blank | 23 comment | 7 complexity | 034acbaa75f5d607ceebd3f21849cf8e MD5 | raw file
  1/*
  2Dwarf Therapist
  3Copyright (c) 2009 Trey Stout (chmod)
  4
  5Permission is hereby granted, free of charge, to any person obtaining a copy
  6of this software and associated documentation files (the "Software"), to deal
  7in the Software without restriction, including without limitation the rights
  8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9copies of the Software, and to permit persons to whom the Software is
 10furnished to do so, subject to the following conditions:
 11
 12The above copyright notice and this permission notice shall be included in
 13all copies or substantial portions of the Software.
 14
 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 21THE SOFTWARE.
 22*/
 23
 24#include "militarypreferencecolumn.h"
 25#include "militarypreference.h"
 26#include "gamedatareader.h"
 27#include "columntypes.h"
 28#include "dwarfmodel.h"
 29#include "dwarf.h"
 30#include "viewcolumnset.h"
 31
 32MilitaryPreferenceColumn::MilitaryPreferenceColumn(const QString &title, const int &labor_id, const int &skill_id, ViewColumnSet *set, QObject *parent) 
 33	: ViewColumn(title, CT_MILITARY_PREFERENCE, set, parent)
 34	, m_labor_id(labor_id)
 35	, m_skill_id(skill_id)
 36{}
 37
 38MilitaryPreferenceColumn::MilitaryPreferenceColumn(QSettings &s, ViewColumnSet *set, QObject *parent) 
 39	: ViewColumn(s, set, parent)
 40	, m_labor_id(s.value("labor_id", -1).toInt())
 41	, m_skill_id(s.value("skill_id", -1).toInt())
 42{}
 43
 44MilitaryPreferenceColumn::MilitaryPreferenceColumn(const MilitaryPreferenceColumn &to_copy) 
 45    : ViewColumn(to_copy)
 46    , m_labor_id(to_copy.m_labor_id)
 47    , m_skill_id(to_copy.m_skill_id)
 48{}
 49
 50QStandardItem *MilitaryPreferenceColumn::build_cell(Dwarf *d) {
 51	GameDataReader *gdr = GameDataReader::ptr();
 52	QStandardItem *item = init_cell(d);
 53
 54	item->setData(CT_MILITARY_PREFERENCE, DwarfModel::DR_COL_TYPE);
 55	short rating = d->get_rating_by_skill(m_skill_id);
 56    short val = d->pref_value(m_labor_id);
 57    QString val_name = gdr->get_military_preference(m_labor_id)->value_name(val);
 58
 59    item->setData(rating * (val + 1), DwarfModel::DR_SORT_VALUE); // push assigned labors above no exp in sort order
 60	item->setData(rating, DwarfModel::DR_RATING);
 61	item->setData(m_labor_id, DwarfModel::DR_LABOR_ID);
 62	item->setData(m_set->name(), DwarfModel::DR_SET_NAME);
 63	
 64	QString skill_str;
 65	if (m_skill_id != -1 && rating > -1) {
 66		QString adjusted_rating = QString::number(rating);
 67		if (rating > 15)
 68			adjusted_rating = QString("15 +%1").arg(rating - 15);
 69        skill_str = tr("%1 %2<br/>[RAW LEVEL: <b><font color=blue>%3</font></b>]<br/><b>Experience:</b><br/>%4")
 70			.arg(gdr->get_skill_level_name(rating))
 71			.arg(gdr->get_skill_name(m_skill_id))
 72			.arg(adjusted_rating)
 73			.arg(d->get_skill(m_skill_id).exp_summary());
 74	} else {
 75		// either the skill isn't a valid id, or they have 0 experience in it
 76		skill_str = "0 experience";
 77	}
 78    item->setToolTip(QString("<h3>%1</h3><b>USING: %2</b><br/>%3<h4>%4</h4>")
 79        .arg(m_title)
 80        .arg(val_name)
 81        .arg(skill_str)
 82        .arg(d->nice_name())
 83    );
 84	return item;
 85}
 86
 87QStandardItem *MilitaryPreferenceColumn::build_aggregate(const QString &group_name, const QVector<Dwarf*> &) {
 88	Q_UNUSED(group_name);
 89	QStandardItem *item = new QStandardItem;
 90	item->setData(CT_MILITARY_PREFERENCE, DwarfModel::DR_COL_TYPE);
 91	
 92	QColor bg;
 93	if (m_override_set_colors) {
 94		bg = m_bg_color;
 95	} else {
 96		bg = set()->bg_color();
 97	}
 98	item->setData(bg, Qt::BackgroundColorRole);
 99	return item;
100}
101
102void MilitaryPreferenceColumn::write_to_ini(QSettings &s) {
103	ViewColumn::write_to_ini(s); 
104	s.setValue("skill_id", m_skill_id); 
105	s.setValue("labor_id", m_labor_id);
106}