00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <TeQtThemeItem.h>
00023 #include <TeQtViewsListView.h>
00024 #include <TeAppTheme.h>
00025 #include <TeQtLegendItem.h>
00026 #include <TeQtChartItem.h>
00027 #include "../../kernel/TeDatabase.h"
00028 #include <qpixmap.h>
00029 #include "../../../../app_icons/theme.xpm"
00030 #include "../../../../app_icons/fileTheme.xpm"
00031 #include "../../../../app_icons/externalTheme.xpm"
00032 #include "../../../../app_icons/invalidExternalTheme.xpm"
00033 #include <qimage.h>
00034
00035
00036 TeQtThemeItem::TeQtThemeItem(QListViewItem *parent,
00037 QString text, TeAppTheme* appTheme)
00038 : TeQtCheckListItem(parent,text,CheckBox), appTheme_(appTheme)
00039 {
00040 type_ = THEME;
00041 TeAbstractTheme* absTheme = appTheme_->getTheme();
00042
00043 if (absTheme->type() == TeTHEME)
00044 setPixmap(0, QPixmap(theme_xpm));
00045 else if (absTheme->type() == TeFILETHEME)
00046 setPixmap(0, QPixmap(fileTheme_xpm));
00047 else if (absTheme->type() == TeEXTERNALTHEME)
00048 setPixmap(0, QPixmap(externalTheme_xpm));
00049
00050 invalidThemeItem_ = false;
00051 setRenameEnabled(0,true);
00052 setSelected(false);
00053 setEnabled(true);
00054
00055 order_ = absTheme->priority();
00056 }
00057
00058
00059 void TeQtThemeItem::setThemeItemAsInvalid()
00060 {
00061 invalidThemeItem_ = true;
00062 TeAbstractTheme* absTheme = appTheme_->getTheme();
00063 if (absTheme->type() == TeEXTERNALTHEME)
00064 setPixmap(0, QPixmap(invalidExternalTheme_xpm));
00065 }
00066
00067
00068 void TeQtThemeItem::stateChange(bool visible)
00069 {
00070 TeQtViewsListView *lView = (TeQtViewsListView*)listView();
00071 lView->checkItemStateChanged(this, visible);
00072 }
00073
00074
00075 void TeQtThemeItem::removeLegends()
00076 {
00077 vector<QListViewItem*> legendVector = getChildren();
00078 unsigned int i;
00079 for (i = 0; i < legendVector.size(); ++i)
00080 {
00081 TeQtCheckListItem *checkItem = (TeQtCheckListItem*)legendVector[i];
00082 if (checkItem->getType() == TeQtCheckListItem::LEGEND ||
00083 checkItem->getType() == TeQtCheckListItem::LEGENDTITLE)
00084 delete checkItem;
00085 }
00086 }
00087
00088
00089 void TeQtThemeItem::removeCharts()
00090 {
00091 vector<QListViewItem*> legendVector = getChildren();
00092 unsigned int i;
00093 for (i = 0; i < legendVector.size(); ++i)
00094 {
00095 TeQtCheckListItem *checkItem = (TeQtCheckListItem*)legendVector[i];
00096 if (checkItem->getType() == TeQtCheckListItem::CHART ||
00097 checkItem->getType() == TeQtCheckListItem::CHARTTITLE)
00098 delete checkItem;
00099 }
00100 }
00101
00102
00103 void TeQtThemeItem::getLegends(vector<const QPixmap*>& pixmapVector, vector<string>& labelVector, string& title)
00104 {
00105 vector<QListViewItem*> legendVector = getChildren();
00106 unsigned int i;
00107 for (i = 0; i < legendVector.size(); ++i)
00108 {
00109 TeQtCheckListItem *checkItem = (TeQtCheckListItem*)legendVector[i];
00110
00111 if (checkItem->getType() == TeQtCheckListItem::LEGENDTITLE)
00112 {
00113 title = checkItem->text().latin1();
00114 }
00115 else if (checkItem->getType() == TeQtCheckListItem::LEGEND)
00116 {
00117 TeQtLegendItem *legendItem = (TeQtLegendItem*)checkItem;
00118 pixmapVector.push_back(legendItem->pixmap(0));
00119 labelVector.push_back(legendItem->text().latin1());
00120 }
00121 }
00122 }
00123
00124 TeQtCheckListItem* TeQtThemeItem::getLegendItem(TeLegendEntry* leg)
00125 {
00126 vector<QListViewItem*> legendVector = getChildren();
00127 unsigned int i;
00128 for (i = 0; i < legendVector.size(); ++i)
00129 {
00130 TeQtCheckListItem *checkItem = (TeQtCheckListItem*)legendVector[i];
00131
00132 if (checkItem->getType() == TeQtCheckListItem::LEGEND)
00133 {
00134 TeQtLegendItem *legendItem = (TeQtLegendItem*)checkItem;
00135 if(legendItem->legendEntry()->id() == leg->id())
00136 return legendItem;
00137 }
00138 }
00139 return (TeQtCheckListItem*)0;
00140 }
00141
00142 void TeQtThemeItem::updateAlias()
00143 {
00144 TeTheme* baseTheme = (TeTheme*)appTheme_->getTheme();
00145 if(baseTheme->type() != TeTHEME)
00146 return;
00147
00148 TeDatabase* db = baseTheme->layer()->database();
00149 map<int, map<string, string> >& mapThemeAlias = db->mapThemeAlias();
00150 map<string, string>& mapAA = mapThemeAlias[baseTheme->id()];
00151
00152 vector<QListViewItem*> itemVec = getChildren();
00153
00154 unsigned int i;
00155 for (i = 0; i < itemVec.size(); ++i)
00156 {
00157 TeQtCheckListItem *checkItem = (TeQtCheckListItem*)itemVec[i];
00158
00159 if (checkItem->getType() == TeQtCheckListItem::LEGENDTITLE)
00160 {
00161 string attr, nattr;
00162 if(baseTheme->grouping().groupMode_ != TeNoGrouping)
00163 {
00164 attr = baseTheme->grouping().groupAttribute_.name_;
00165 nattr = baseTheme->grouping().groupNormAttribute_;
00166 }
00167
00168 if(nattr.empty() || nattr == "NONE")
00169 {
00170 map<string, string>::iterator it = mapAA.find(attr);
00171 if(it != mapAA.end())
00172 {
00173 string alias = it->second;
00174 if(alias.empty())
00175 checkItem->setText(0, attr.c_str());
00176 else
00177 checkItem->setText(0, alias.c_str());
00178 }
00179 else
00180 checkItem->setText(0, attr.c_str());
00181 }
00182 else
00183 {
00184 string alias = attr;
00185 map<string, string>::iterator it = mapAA.find(attr);
00186 if(it != mapAA.end())
00187 alias = it->second;
00188
00189 it = mapAA.find(nattr);
00190 if(it != mapAA.end())
00191 alias += "/" + it->second;
00192 else
00193 alias += "/" + nattr;
00194
00195 checkItem->setText(0, alias.c_str());
00196 }
00197 }
00198 else if (checkItem->getType() == TeQtCheckListItem::CHART)
00199 {
00200 string attr = ((TeQtChartItem*)checkItem)->name();
00201 map<string, string>::iterator it = mapAA.find(attr);
00202 if(it != mapAA.end())
00203 {
00204 string alias = it->second;
00205 checkItem->setText(0, alias.c_str());
00206 }
00207 else
00208 checkItem->setText(0, attr.c_str());
00209 }
00210 }
00211 }
00212