00001 #include "TeGUIUtils.h"
00002 #include "../../kernel/TeViewNode.h"
00003 #include "../../kernel/TeView.h"
00004 #include "../../kernel/TeDatabase.h"
00005
00006 bool fillThemeCombo(TeGeomRep tg, TeView* view, QComboBox* cBox, string selName, bool clear)
00007 {
00008
00009
00010 if (clear)
00011 cBox->clear();
00012
00013 int idx = 0;
00014 int count = 0;
00015
00016 vector<TeViewNode *>& themeVec = view->themes();
00017 for(unsigned int i=0; i<themeVec.size(); i++)
00018 {
00019 TeAbstractTheme* t = (TeAbstractTheme*)themeVec[i];
00020 if(t->type() < 2 && t->visibleGeoRep() & tg)
00021 {
00022 cBox->insertItem(t->name().c_str());
00023 if (!t->name().compare(selName))
00024 {
00025 idx = count;
00026 }
00027 count++;
00028 }
00029 }
00030
00031 if (count > 0)
00032 {
00033 cBox->setCurrentItem(idx);
00034 }
00035
00036 return (count > 0);
00037 }
00038
00039 bool fillThemeCombo(vector<TeGeomRep>& tg, TeView* view, QComboBox* cBox, string selName, bool clear)
00040 {
00041 if(clear)
00042 cBox->clear();
00043
00044 vector<TeViewNode *> themeVec = view->themes();
00045 if (clear)
00046 cBox->clear();
00047
00048 int idx = 0;
00049 int count = 0;
00050
00051 for(unsigned int i=0; i<themeVec.size(); i++)
00052 {
00053 TeAbstractTheme* t = (TeAbstractTheme*)themeVec[i];
00054 if (t->type() >= 2)
00055 continue;
00056
00057 bool hasGeomRep = false;
00058 for(unsigned int j=0; j<tg.size(); ++j)
00059 {
00060 if(t->visibleGeoRep() & tg[j])
00061 hasGeomRep = true;
00062 }
00063
00064 if(hasGeomRep)
00065 {
00066 cBox->insertItem(t->name().c_str());
00067 if (!t->name().compare(selName))
00068 {
00069 idx = count;
00070 }
00071 count++;
00072 }
00073 }
00074
00075 if (count > 0)
00076 {
00077 cBox->setCurrentItem(idx);
00078 }
00079
00080 return (count > 0);
00081 }
00082
00083 bool fillThemeCombo( TeView* view, QComboBox* cBox, string selName, bool clear)
00084 {
00085 vector<TeViewNode *> themeVec = view->themes();
00086
00087 if (clear)
00088 cBox->clear();
00089
00090 int idx = 0;
00091 int count = 0;
00092
00093 for(unsigned int i=0; i<themeVec.size(); i++)
00094 {
00095 TeAbstractTheme* t = (TeAbstractTheme*)themeVec[i];
00096 if (t->type() >= 2)
00097 continue;
00098 cBox->insertItem(t->name().c_str());
00099 if (!t->name().compare(selName))
00100 {
00101 idx = count;
00102 }
00103 count++;
00104 }
00105
00106 if (count > 0)
00107 {
00108 cBox->setCurrentItem(idx);
00109 }
00110
00111 return (count > 0);
00112 }
00113
00114
00115 bool fillTableCombo(TeView* view,
00116 QComboBox *cTableCombo,
00117 QComboBox *cThemeCombo,
00118 string selName, bool clear, TeAttrTableType tableType)
00119 {
00120 TeTable ttable;
00121 string tableName;
00122 string themeName = string(cThemeCombo->currentText().ascii());
00123 TeTheme* currTheme = view->get(themeName);
00124
00125 if (currTheme == NULL)
00126 return false;
00127
00128 TeAttrTableVector atvec;
00129 currTheme->getAttTables(atvec, tableType);
00130
00131 if (atvec.size() == 0)
00132 return false;
00133
00134 if (clear)
00135 cTableCombo->clear();
00136 int idx = 0;
00137
00138 for(unsigned int i=0; i<atvec.size(); i++)
00139 {
00140 TeTable ttable = atvec[i];
00141 tableName = ttable.name();
00142 cTableCombo->insertItem(tableName.c_str());
00143 if(selName.compare(tableName))
00144 {
00145 idx = i;
00146 }
00147 }
00148
00149 cTableCombo->setCurrentItem(idx);
00150 return true;
00151 }
00152
00153
00154 bool fillColumnCombo(TeAttrDataType aType,
00155 TeTheme* theme,
00156 QComboBox *cColumnCombo,
00157 QComboBox *cTableCombo,
00158 string selName, bool clear)
00159 {
00160
00161
00162
00163 TeAttributeList columns;
00164 TeAttrTableVector atvec;
00165 theme->getAttTables(atvec);
00166
00167 string tableName = string(cTableCombo->currentText().ascii());
00168 unsigned int t;
00169
00170 for (t = 0; t < atvec.size(); t++)
00171 {
00172 if (!tableName.compare(atvec[t].name()))
00173 break;
00174 }
00175
00176 if (t == atvec.size())
00177 return false;
00178
00179 TeTable ttable = atvec[t];
00180 columns = ttable.attributeList();
00181
00182 if (clear)
00183 cColumnCombo->clear();
00184
00185 int idx = 0;
00186 int count = 0;
00187
00188 for(unsigned int i=0; i<columns.size(); i++)
00189 {
00190 int type = columns[i].rep_.type_;
00191 string colName = columns[i].rep_.name_;
00192 if ((aType == TeUNKNOWN) || (type == aType))
00193 {
00194 cColumnCombo->insertItem(colName.c_str());
00195 if (!selName.compare(colName))
00196 {
00197 idx = count;
00198 }
00199 count++;
00200 }
00201 }
00202
00203 if (count > 0)
00204 cColumnCombo->setCurrentItem(idx);
00205
00206 return count> 0;
00207 }
00208
00209 bool fillColumnCombo(vector<TeAttrDataType> &aTypeVec,
00210 TeTheme* theme,
00211 QComboBox *cColumnCombo,
00212 QComboBox *cTableCombo,
00213 string selName, bool clear)
00214 {
00215 if(clear)
00216 cColumnCombo->clear();
00217
00218 for(unsigned int i = 0; i < aTypeVec.size(); i++)
00219 fillColumnCombo(aTypeVec[i], theme, cColumnCombo, cTableCombo, selName, false);
00220
00221 return true;
00222 }
00223
00224 bool fillColumnCombo(vector<TeAttrDataType> &aTypeVec, TeTheme* theme, QComboBox *cColumnCombo, bool clear)
00225 {
00226 if(clear)
00227 cColumnCombo->clear();
00228 TeAttrTableVector attrTables = theme->attrTables();
00229 for(unsigned int i=0; i<attrTables.size(); ++i)
00230 {
00231 TeAttributeList attrList = attrTables[i].attributeList();
00232 for(unsigned int j=0; j<attrList.size(); ++j)
00233 {
00234 for(unsigned int type=0; type<aTypeVec.size(); ++type)
00235 {
00236 if(attrList[j].rep_.type_==aTypeVec[type])
00237 {
00238 string tableCol = attrTables[i].name()+"."+attrList[j].rep_.name_;
00239 cColumnCombo->insertItem(tableCol.c_str());
00240 }
00241 }
00242 }
00243 }
00244 return true;
00245 }
00246
00247 bool fillLayerCombo(TeDatabase* db, TeGeomRep rep, QComboBox *lColumnCombo, const string& current, bool clear)
00248 {
00249 int cur=0;
00250 if (clear)
00251 lColumnCombo->clear();
00252 else
00253 cur=lColumnCombo->count();
00254
00255 TeLayerMap& layerMap = db->layerMap();
00256 TeLayerMap::iterator itlay = layerMap.begin();
00257 int i=0;
00258 while ( itlay != layerMap.end() )
00259 {
00260 if ((*itlay).second->geomRep() & rep)
00261 {
00262 lColumnCombo->insertItem((*itlay).second->name().c_str());
00263 if ((*itlay).second->name() == current)
00264 cur += i;
00265 ++i;
00266 }
00267 ++itlay;
00268 }
00269 lColumnCombo->setCurrentItem(cur);
00270 return i>0;
00271 }