00001 #include "glacieridchooserdlg.h" 00002 00003 00004 GlacierIDChooserDlg::GlacierIDChooserDlg( GLIMSGIDData &giddata, 00005 GLIMSLineData &linedata ) 00006 : QDialog( NULL, NULL, true ), 00007 mLineData( linedata ), mGIDData( giddata ) { 00008 00009 setCaption( "Glacier ID Chooser" ); 00010 00011 QPushButton *pb5; // APPLY SET LINES BUTTON 00012 QPushButton *pb6; // HIDE DIALOG 00013 QVBoxLayout *vbl; // MAIN LAYOUT 00014 QHBoxLayout *hbl; // BUTTON LAYOUT 00015 00016 mSelectedGID = -1; 00017 00018 // ------------------------------------------------------- 00019 // CREATE THE LIST AND COLUMN HEADER 00020 mListView = new QListView( this ); 00021 mListView->addColumn( "GID" ); 00022 mListView->addColumn( "Name" ); 00023 mListView->addColumn( "Local ID" ); 00024 mListView->addColumn( "WGMS ID" ); 00025 mListView->addColumn( "Parent ID" ); 00026 // ------------------------------------------------------- 00027 00028 // REMOVE SORTING ABILITY 00029 mListView->setSorting( -1 ); 00030 00031 // ------------------------------------------------------- 00032 // CREATE THE BUTTONS 00033 pb5 = new QPushButton( "Apply", this ); 00034 pb6 = new QPushButton( "Close", this ); 00035 // ------------------------------------------------------- 00036 00037 // ------------------------------------------------------- 00038 // CONNECT THE BUTTONS TO EVENT HANDLERS 00039 connect( pb5, SIGNAL( clicked() ), this, SLOT( setCurLines() ) ); 00040 connect( pb6, SIGNAL( clicked() ), this, SLOT( hide() ) ); 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( pb5 ); 00055 hbl->addWidget( pb6 ); 00056 00057 connect( &giddata, 00058 SIGNAL( datasetChanged() ), 00059 this, 00060 SLOT( loadList() ) ); 00061 00062 // FILL THE LIST 00063 loadList(); 00064 } 00065 00066 00067 GlacierIDChooserDlg::~GlacierIDChooserDlg( ) {;} 00068 00069 // ------------------------------------------------------- 00070 // SET CUR LINES 00071 void GlacierIDChooserDlg::setCurLines( ) { 00072 SelectionSet &selset = mLineData.getSelSet(); 00073 00074 // for each selected line, assign the selected GID to it 00075 for ( int isel = 0 ; isel < selset.size() ; isel++ ) { 00076 mLineData.setGID( selset[isel].obj, mSelectedGID ); 00077 } 00078 this->hide() ; 00079 } 00080 00081 // ------------------------------------------------------- 00082 // LOAD LIST 00083 void GlacierIDChooserDlg::loadList( ) { 00084 // CLEAR THE LIST 00085 mListView->clear(); 00086 std::vector<GlacierIDDef> &gidset = mGIDData.getDefSet(); 00087 unsigned int i = 0 ; // iterator 00088 00089 // ADD LIST ITEMS FOR EVERY GID 00090 for (i = mGIDData.getDefSet().size(); i > 0; i--) { 00091 GlacierIDDef gid = gidset[i - 1]; 00092 QListViewItem *item = new QListViewItem( mListView, 00093 gid.toString().c_str(), 00094 gid.mName.c_str(), 00095 gid.mLocalID.c_str(), 00096 gid.mWGMSID.c_str(), 00097 gid.mParentID.c_str() ); 00098 mListView->insertItem( item ); 00099 } 00100 } 00101 00102 00103 // ------------------------------------------------------- 00104 // SET SELECTED GID 00105 void GlacierIDChooserDlg::setSelectedGID() { 00106 QListViewItem *selectedItem ; // SELECTED GID 00107 QListViewItem *item ; // TEMP LIST ITEM 00108 int i = 0 ; // COUNTER 00109 00110 // GET CURRENT SELECTED ITEM 00111 selectedItem = mListView->selectedItem(); 00112 00113 // FIND INDEX OF CURRENTLY SELECTED ITEM 00114 item = mListView->firstChild(); 00115 while ( selectedItem != item && i < mListView->childCount() ) { 00116 i++; 00117 item = item->nextSibling(); 00118 } 00119 00120 // ASSIGN NEW SELECTED ITEM INDEX 00121 mSelectedGID = i; 00122 mLineData.setDefGID( mSelectedGID ); 00123 emit repaintViews(); 00124 } 00125 00126 00127 00128
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |