00001 #include "glacierconfigdlg.h" 00002 00003 00004 GlacierConfigDlg::GlacierConfigDlg( GLIMSGIDData &giddata, 00005 GLIMSLineData &linedata ) 00006 : mLineData( linedata ), mGIDData( giddata ) { 00007 00008 QPushButton *pb2; // NEW GID BUTTON 00009 QPushButton *pb3; // EDIT GID BUTTON 00010 QPushButton *pb5; // SET LINES BUTTON 00011 QVBoxLayout *vbl; // MAIN LAYOUT 00012 QHBoxLayout *hbl; // BUTTON LAYOUT 00013 00014 mSelectedGID = -1; 00015 00016 // ------------------------------------------------------- 00017 // CREATE THE LIST AND COLUMN HEADER 00018 mListView = new QListView( this ); 00019 mListView->addColumn( "GID" ); 00020 mListView->addColumn( "Name" ); 00021 mListView->addColumn( "Local ID" ); 00022 mListView->addColumn( "WGMS ID" ); 00023 mListView->addColumn( "Parent ID" ); 00024 // ------------------------------------------------------- 00025 00026 // REMOVE SORTING ABILITY 00027 mListView->setSorting( -1 ); 00028 00029 // ------------------------------------------------------- 00030 // CREATE THE BUTTONS 00031 pb2 = new QPushButton( "New Glacier ID", this ); 00032 pb3 = new QPushButton( "Edit Glacier ID", this ); 00033 pb5 = new QPushButton( "Set Lines", this ); 00034 // ------------------------------------------------------- 00035 00036 // ------------------------------------------------------- 00037 // CONNECT THE BUTTONS TO EVENT HANDLERS 00038 connect( pb2, SIGNAL( clicked() ), this, SLOT( newGlacier() ) ); 00039 connect( pb3, SIGNAL( clicked() ), this, SLOT( editGlacier() ) ); 00040 connect( pb5, SIGNAL( clicked() ), this, SLOT( glacierIDChooser() ) ); 00041 connect( mListView, SIGNAL( selectionChanged() ), this, SLOT( setSelectedGID() ) ); 00042 // ------------------------------------------------------- 00043 00044 // CREATE THE MAIN LAYOUT 00045 vbl = new QVBoxLayout( this ); 00046 00047 // ADD THE LIST VIEW 00048 vbl->addWidget( mListView ); 00049 00050 // CREATE THE BUTTON LAYOUT 00051 hbl = new QHBoxLayout( vbl ); 00052 00053 // ADD THE BUTTONS 00054 hbl->addWidget( pb2 ); 00055 hbl->addWidget( pb3 ); 00056 hbl->addWidget( pb5 ); 00057 00058 connect( &giddata, 00059 SIGNAL( datasetChanged() ), 00060 this, 00061 SLOT( loadList() ) ); 00062 00063 // FILL THE LIST 00064 loadList(); 00065 00066 mChooserDlg = new GlacierIDChooserDlg (mGIDData, mLineData) ; 00067 mChooserDlg->hide() ; 00068 00069 connect( mChooserDlg, SIGNAL (repaintViews()), this, SLOT(updateListSelection()) ) ; 00070 00071 } 00072 00073 00074 GlacierConfigDlg::~GlacierConfigDlg( ) { 00075 00076 } 00077 00078 00079 void GlacierConfigDlg::keyPressEvent (QKeyEvent * e) { 00080 int keyPressed = e->key() ; 00081 switch (keyPressed){ 00082 case Key_Delete : 00083 mGIDData.push(); 00084 delSel(e); 00085 break; 00086 00087 case Key_Enter : 00088 editGlacier() ; 00089 break; 00090 00091 default: e->ignore() ; 00092 } 00093 loadList() ; 00094 00095 } 00096 00097 void GlacierConfigDlg::delSel(QKeyEvent * e) { 00098 00099 if ( !mGIDData.size() ) 00100 return; 00101 00102 bool kCtrlDown = false ; 00103 if (e->state() & Qt::ControlButton) { 00104 kCtrlDown = true ; 00105 } 00106 00107 SelectionSet &refSelSet = mGIDData.getSelSet() ; 00108 00109 if ( mGIDData.getType() == VectorData::POINT ) { 00110 for ( int isel=0; isel < (int)refSelSet.size(); isel++ ) { 00111 for ( int i=0; i < (int)refSelSet.size(); i++ ) 00112 if ( refSelSet[isel].obj < refSelSet[i].obj ) 00113 refSelSet[i].obj--; 00114 mGIDData.delNode( refSelSet[isel].obj ); 00115 refSelSet.clear(); 00116 } 00117 } 00118 else { 00119 int szLine = 0; 00120 for ( int isel=0; isel < (int)refSelSet.size(); isel++ ) { 00121 Shape &s = *mGIDData.getXYSet()[ refSelSet[isel].obj ]; 00122 Line &l = dynamic_cast<Line&>( s ); 00123 szLine = l.size(); 00124 if ( kCtrlDown || szLine <= (int)refSelSet[isel].nodes.size() ) { 00125 for ( int i=0; i < (int)refSelSet.size(); i++ ) 00126 if ( refSelSet[isel].obj < refSelSet[i].obj ) 00127 refSelSet[i].obj--; 00128 mGIDData.delLine( refSelSet[isel].obj ); 00129 } 00130 else { 00131 std::sort( refSelSet[isel].nodes.begin(), refSelSet[isel].nodes.end() ); 00132 for ( int inode=refSelSet[isel].nodes.size()-1; inode > -1; inode-- ) 00133 mGIDData.delLineNode( refSelSet[isel].obj, refSelSet[isel].nodes[inode] ); 00134 } 00135 } 00136 00137 if ( !kCtrlDown && refSelSet.size() == 1 && refSelSet[0].nodes.size() == 1 ) { 00138 if ( refSelSet[0].nodes[0] >= szLine-1 ) 00139 refSelSet[0].nodes[0]--; 00140 if ( refSelSet[0].nodes[0] < 0 ) { 00141 refSelSet.clear(); 00142 } 00143 } 00144 else { 00145 refSelSet.clear(); 00146 } 00147 } 00148 00149 emit repaintViews() ; 00150 00151 } 00152 00153 00154 void GlacierConfigDlg::newGlacier( ) { 00155 // CREATE THE GID FORM & DISPLAY IT 00156 GlacierIDDlg *giddlg = new GlacierIDDlg( mGIDData ); 00157 giddlg->exec(); 00158 00159 // RELOAD THE LIST 00160 loadList(); 00161 } 00162 00163 00164 void GlacierConfigDlg::editGlacier( ) { 00165 // ------------------------------------------------------- 00166 // TEST IF THERE'S A GID SELECTED 00167 if ( mSelectedGID == -1 ) { 00168 QMessageBox::information( NULL, "Error", "There are no Glacier IDs available" ); 00169 return; 00170 } 00171 // ------------------------------------------------------- 00172 00173 // CREATE THE GID FORM & DISPLAY IT 00174 GlacierIDDlg *giddlg = new GlacierIDDlg( mGIDData, mSelectedGID ); 00175 giddlg->exec(); 00176 00177 // RELOAD THE LIST 00178 loadList(); 00179 } 00180 00181 00182 // ------------------------------------------------------- 00183 // SET CUR LINES 00184 void GlacierConfigDlg::setCurLines( ) { 00185 /* SelectionSet &selset = mLineData.getSelSet(); 00186 00187 // for each selected line, assign the selected GID to it 00188 for ( int isel = 0 ; isel < selset.size() ; isel++ ) { 00189 mLineData.setGID( selset[isel].obj, mSelectedGID ); 00190 } 00191 updateListSelection() ; 00192 */ 00193 } 00194 00195 // ------------------------------------------------------- 00196 // LOAD LIST 00197 void GlacierConfigDlg::loadList( ) { 00198 // CLEAR THE LIST 00199 mListView->clear(); 00200 std::vector<GlacierIDDef> &gidset = mGIDData.getDefSet(); 00201 unsigned int i = 0 ; // iterator 00202 00203 // ADD LIST ITEMS FOR EVERY GID 00204 for (i = mGIDData.getDefSet().size(); i > 0; i--) { 00205 GlacierIDDef gid = gidset[i - 1]; 00206 QListViewItem *item = new QListViewItem( mListView, 00207 gid.toString().c_str(), 00208 gid.mName.c_str(), 00209 gid.mLocalID.c_str(), 00210 gid.mWGMSID.c_str(), 00211 gid.mParentID.c_str() ); 00212 mListView->insertItem( item ); 00213 } 00214 } 00215 00216 00217 // ------------------------------------------------------- 00218 // UPDATE LIST SELECTION 00219 00220 void GlacierConfigDlg::updateListSelection() { 00221 // added by dls 12/4/2004 00222 // show selected items as selected in the glacier id config dialog 00223 QListViewItem *item ; // temp list item 00224 unsigned int i = 0 ; // iterator 00225 00226 item = mListView->firstChild() ; 00227 if (item != NULL) { 00228 for (i = 0 ; i < (unsigned int)mListView->childCount() ; i++) { 00229 item->setSelected(false) ; 00230 item = item->nextSibling(); 00231 } 00232 } 00233 else return ; 00234 00235 // show selected glacier IDs as selected in listview 00236 SelectionSet &gidselset = mGIDData.getSelSet(); // set of selected glacier ID points from the GID vector data 00237 for (i = 0 ; &gidselset != NULL && i < (unsigned int)gidselset.size() ; i++) { 00238 item = mListView->firstChild() ; 00239 int selGID = gidselset[i].obj ; 00240 00241 for (int j = 0 ; j != selGID ; j++) { 00242 item = item->nextSibling(); 00243 } 00244 item->setSelected(true) ; 00245 } 00246 00247 // show selected lines as selected in listview 00248 SelectionSet &lineselset = mLineData.getSelSet(); // set of selected lines from the line vector data 00249 for (i = 0 ; &lineselset != NULL && i < (unsigned int)lineselset.size() ; i++) { // step through selected lines 00250 int selLine = lineselset[i].obj ; // get the line obj for the current selected line 00251 std::vector<Shape*> &glXYSet = mLineData.getXYSet() ; // get the line data 00252 GlacierLine &xyline = dynamic_cast<GlacierLine&>(*glXYSet[selLine]); // get the line matching the selected line from the line data 00253 00254 item = mListView->firstChild() ; // get the first item in the ListView 00255 for (int j = 0 ; j < mListView->childCount() ; j++) { // step through each ListView item 00256 if (xyline.mGID == j) { // if the selected line's related glacier ID equals the selected ListView index 00257 item->setSelected(true) ; // highlight the ListView item 00258 } 00259 item = item->nextSibling(); // get the next ListView item 00260 } 00261 } 00262 00263 mListView->triggerUpdate () ; 00264 } 00265 00266 00267 // ------------------------------------------------------- 00268 // SET SELECTED GID 00269 void GlacierConfigDlg::setSelectedGID() { 00270 QListViewItem *selectedItem ; // SELECTED GID 00271 QListViewItem *item ; // TEMP LIST ITEM 00272 int i = 0 ; // COUNTER 00273 00274 // GET CURRENT SELECTED ITEM 00275 selectedItem = mListView->selectedItem(); 00276 00277 // FIND INDEX OF CURRENTLY SELECTED ITEM 00278 item = mListView->firstChild(); 00279 00280 while ( selectedItem != item && i < mListView->childCount() ) { 00281 i++; 00282 item = item->nextSibling(); 00283 } 00284 00285 // ASSIGN NEW SELECTED ITEM INDEX 00286 mSelectedGID = i; 00287 mLineData.setDefGID( mSelectedGID ); 00288 00289 // added by dls 12/3/2004 00290 // HIGLIGHT SELECTED GID POINT & RELATED LINE IN VIEWS 00291 // set selected GID point in selection set so it's highlighted on screen 00292 SelectionSet &gidselset = mGIDData.getSelSet(); // set of selected glacier ID points from the GID vector data 00293 if (gidselset.size()) { 00294 gidselset.clear() ; // clear the current selection 00295 } 00296 SelectionSet::SelObj gidselobj ; // create a new selection object 00297 gidselobj.obj = mSelectedGID ; // set the selection object to be current glacier ID 00298 00299 gidselset.add ( gidselobj ) ; // add selection to selection set 00300 00301 // set selected line related to GID point in selection set so it's highlighted on screen 00302 SelectionSet &lineselset = mLineData.getSelSet(); // set of selected lines from the line vector data 00303 if (lineselset.size()) { 00304 lineselset.clear() ; // clear the current selection 00305 } 00306 SelectionSet::SelObj lineselobj ; // create a new selection object 00307 std::vector<Shape*> &glXYSet = mLineData.getXYSet() ; 00308 for (i = 0 ; (unsigned int)i < glXYSet.size() ; i++) { 00309 GlacierLine &xyline = dynamic_cast<GlacierLine&>(*glXYSet[i]); 00310 if (xyline.mGID == mSelectedGID) { 00311 lineselobj.obj = i ; // set the selection object to be current selected glacier ID 00312 lineselset.add ( lineselobj ) ; // add selection to selection set 00313 } 00314 } 00315 00316 emit repaintViews(); 00317 } 00318 00319 00320 00321
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |