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