Crossfire Server, Branch 1.12  R12190
CRETreasurePanel.cpp
Go to the documentation of this file.
00001 #include <Qt>
00002 
00003 extern "C" {
00004 #include "global.h"
00005 #include "treasure.h"
00006 }
00007 
00008 #include "CRETreasurePanel.h"
00009 #include "CREUtils.h"
00010 
00011 CRETreasurePanel::CRETreasurePanel()
00012 {
00013     QGridLayout* layout = new QGridLayout(this);
00014 
00015     myUsing = new QTreeWidget(this);
00016     myUsing->setColumnCount(1);
00017     myUsing->setHeaderLabel(tr("Used by"));
00018     myUsing->setIconSize(QSize(32, 32));
00019     layout->addWidget(myUsing, 1, 1);
00020 }
00021 
00022 void CRETreasurePanel::setTreasure(const treasurelist* treas)
00023 {
00024     myUsing->clear();
00025     myTreasure = treas;
00026 
00027     const archt* arch;
00028     QTreeWidgetItem* root = NULL;
00029 
00030     QString name = myTreasure->name;
00031 
00032     for (arch = first_archetype; arch; arch = arch->more ? arch->more : arch->next)
00033     {
00034         if (arch->clone.randomitems && name == arch->clone.randomitems->name)
00035         {
00036             if (root == NULL)
00037             {
00038                 root = CREUtils::archetypeNode(NULL);
00039                 myUsing->addTopLevelItem(root);
00040                 root->setExpanded(true);
00041             }
00042             CREUtils::archetypeNode(arch, root);
00043         }
00044     }
00045 
00046     root = NULL;
00047 
00048     const treasurelist* list;
00049     const treasure* t;
00050 
00051     for (list = first_treasurelist; list; list = list->next)
00052     {
00053         for (t = list->items; t; t = t->next)
00054         {
00055             if (t->name == name)
00056             {
00057                 if (root == NULL)
00058                 {
00059                     root = CREUtils::treasureNode(NULL);
00060                     myUsing->addTopLevelItem(root);
00061                     root->setExpanded(true);
00062                 }
00063                 CREUtils::treasureNode(list, root);
00064             }
00065         }
00066     }
00067 }