PageRenderTime 23ms CodeModel.GetById 10ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/src/grid_view/laborcolumn.cpp

https://code.google.com/p/dwarftherapist/
C++ | 106 lines | 74 code | 9 blank | 23 comment | 10 complexity | 1b0849dfc1dfffda899b2d52a2b0b125 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 "laborcolumn.h"
 25#include "gamedatareader.h"
 26#include "columntypes.h"
 27#include "dwarfmodel.h"
 28#include "dwarf.h"
 29#include "viewcolumnset.h"
 30
 31LaborColumn::LaborColumn(QString title, int labor_id, int skill_id, ViewColumnSet *set, QObject *parent) 
 32	: ViewColumn(title, CT_LABOR, set, parent)
 33	, m_labor_id(labor_id)
 34	, m_skill_id(skill_id)
 35{}
 36
 37LaborColumn::LaborColumn(QSettings &s, ViewColumnSet *set, QObject *parent) 
 38	: ViewColumn(s, set, parent)
 39	, m_labor_id(s.value("labor_id", -1).toInt())
 40	, m_skill_id(s.value("skill_id", -1).toInt())
 41{}
 42
 43LaborColumn::LaborColumn(const LaborColumn &to_copy) 
 44    : ViewColumn(to_copy)
 45    , m_labor_id(to_copy.m_labor_id)
 46    , m_skill_id(to_copy.m_skill_id)
 47{}
 48
 49QStandardItem *LaborColumn::build_cell(Dwarf *d) {
 50	GameDataReader *gdr = GameDataReader::ptr();
 51	QStandardItem *item = init_cell(d);
 52
 53	item->setData(CT_LABOR, DwarfModel::DR_COL_TYPE);
 54	short rating = d->get_rating_by_skill(m_skill_id);
 55	if (rating < 0 && d->labor_enabled(m_labor_id)) {
 56		item->setData(float(rating + 0.5f), DwarfModel::DR_SORT_VALUE); // push assigned labors above no exp in sort order
 57	} else {
 58		item->setData(rating, DwarfModel::DR_SORT_VALUE);		
 59	}
 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>%2<h4>%3</h4>").arg(m_title).arg(skill_str).arg(d->nice_name()));
 79	return item;
 80}
 81
 82QStandardItem *LaborColumn::build_aggregate(const QString &group_name, const QVector<Dwarf*> &) {
 83	QStandardItem *item = new QStandardItem;
 84	item->setStatusTip(m_title + " :: " + group_name);
 85	QColor bg;
 86	if (m_override_set_colors) {
 87		bg = m_bg_color;
 88	} else {
 89		bg = set()->bg_color();
 90	}
 91	item->setData(CT_LABOR, DwarfModel::DR_COL_TYPE);
 92	item->setData(bg, Qt::BackgroundColorRole);
 93	item->setData(bg, DwarfModel::DR_DEFAULT_BG_COLOR);
 94	item->setData(true, DwarfModel::DR_IS_AGGREGATE);
 95	item->setData(m_labor_id, DwarfModel::DR_LABOR_ID);
 96	item->setData(group_name, DwarfModel::DR_GROUP_NAME);
 97	item->setData(0, DwarfModel::DR_RATING);
 98	item->setData(m_set->name(), DwarfModel::DR_SET_NAME);
 99	return item;
100}
101
102void LaborColumn::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}