DlgLayerManager.cpp
资源名称:QGIS.rar [点击查看]
上传用户:oybseng
上传日期:2015-04-27
资源大小:7831k
文件大小:13k
源码类别:
GDI/图象编程
开发平台:
Visual C++
- // DlgLayerManager.cpp : implementation file
- //
- #include "stdafx.h"
- #include "..qgis.h"
- #include "DlgLayerManager.h"
- #include "..QObjectsincludeQLayerObj.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDlgLayerManager dialog
- //第一个参数是操作类别
- CDlgLayerManager::CDlgLayerManager(int nOpflag,CQMapObj * pMap,CWnd* pParent /*=NULL*/)
- : CDialog(CDlgLayerManager::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDlgLayerManager)
- //}}AFX_DATA_INIT
- if(!pMap)return;
- m_pMap = pMap;
- m_nIndex = -1; //表示图层的正确位置
- m_nOpflag = nOpflag;
- }
- void CDlgLayerManager::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDlgLayerManager)
- DDX_Control(pDX, IDC_LIST_LAYER_QGIS, m_LayerList);
- DDX_Text(pDX,IDC_EDIT_LAYER_ID_QGIS,m_lLayerID);
- DDX_Text(pDX,IDC_EDIT_LAYER_NAME_QGIS,m_szLayerName);
- DDX_Text(pDX,IDC_EDIT_LAYER_DIS_QGIS,m_szLayerDis);
- DDX_Radio(pDX,IDC_RADIO_LAYER_SHOW,m_nLayerShow);
- DDX_Radio(pDX,IDC_RADIO_LAYER_DELETE_QGIS,m_nLayerDel);
- DDX_Radio(pDX,IDC_RADIO_LAYER_EDIT_QGIS,m_nLayerEdit);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDlgLayerManager, CDialog)
- //{{AFX_MSG_MAP(CDlgLayerManager)
- ON_NOTIFY(NM_CLICK, IDC_LIST_LAYER_QGIS, OnClickListLayerQgis)
- ON_BN_CLICKED(IDC_BUTTON_NEW_LAYER_QGIS, OnButtonNewLayerQgis)
- ON_BN_CLICKED(IDC_BUTTON_DELETE_LAYER_QGIS, OnButtonDeleteLayerQgis)
- ON_BN_CLICKED(IDC_BUTTON_TOP_QGIS, OnButtonTopQgis)
- ON_BN_CLICKED(IDC_BUTTON_BOTTOM_QGIS, OnButtonBottomQgis)
- ON_BN_CLICKED(IDC_BUTTON_PRE_QGIS, OnButtonPreQgis)
- ON_BN_CLICKED(IDC_BUTTON_NEXT_QGIS, OnButtonNextQgis)
- ON_BN_CLICKED(IDC_BUTTON_SET_CUR_QGIS,OnButtonSetCurQgis)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDlgLayerManager message handlers
- BOOL CDlgLayerManager::OnInitDialog()
- {
- CDialog::OnInitDialog();
- //初始化列表控件
- m_pcurLyr = NULL;
- m_pcurLyr = m_pMap->GetCurLayer();
- if(!m_pcurLyr) return FALSE;
- if(m_nOpflag == 0)
- SetControlEdit(FALSE);
- else if(m_nOpflag == 1)
- SetControlEdit(TRUE);
- m_LayerList.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
- m_LayerList.InsertColumn(0,"图层ID",LVCFMT_CENTER,80);
- m_LayerList.InsertColumn(1,"图层名称",LVCFMT_CENTER,120);
- m_LayerList.InsertColumn(2,"图层描述",LVCFMT_CENTER,120);
- m_LayerList.InsertColumn(3,"显示状态",LVCFMT_CENTER,80); // return TRUE unless you set the focus to a control
- m_LayerList.InsertColumn(4,"可编辑状态",LVCFMT_CENTER,100);
- m_LayerList.InsertColumn(5,"当前图层",LVCFMT_CENTER,100);
- GetDlgItem(IDC_EDIT_LAYER_ID_QGIS)->EnableWindow(FALSE);
- ResetList(m_pMap);
- int nLayercount = m_pMap->GetLayerCount();
- m_pLyrVector.clear();
- for(int i=0;i<nLayercount;i++)
- {
- CQLayerObj * pLyr = m_pMap->GetLayer(i);
- if(pLyr && !pLyr->GetDeleteFlag())
- {
- m_pLyrVector.push_back(pLyr);
- }
- }
- CString szLayerCount;
- szLayerCount.Format("%d",nLayercount);
- GetDlgItem(IDC_EDIT_LAYER_COUNT_QGIS)->SetWindowText(LPCTSTR(szLayerCount));
- GetDlgItem(IDC_EDIT_CUR_LAYER_NAME_QGIS)->SetWindowText(LPCTSTR(m_pcurLyr->GetLayerName()));
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CDlgLayerManager::ResetList(CQMapObj *pMap)
- {
- UpdateData(TRUE);
- m_LayerList.DeleteAllItems();
- if(!pMap) return;
- int nLayerCount = pMap->GetLayerCount();
- if(nLayerCount == 0)return;
- int nitem = 0;
- long lCurLyrId = m_pMap->GetCurLayer()->GetLayerID();
- for(int i=0;i<nLayerCount;i++)
- {
- CQLayerObj * pLayer = pMap->GetLayer(i);
- if(!pLayer)return;
- if(pLayer->GetDeleteFlag())continue;
- long lID = pLayer->GetLayerID();
- CString szID;
- szID.Format("%ld",lID);
- CString szLayerName = pLayer->GetLayerName();
- CString szLayerDis = pLayer->GetLayerDis();
- BOOL bCanEdit = pLayer->GetEditFlag();
- BOOL bShow = pLayer->GetShowFlag();
- CString szCurLyr;
- szCurLyr = (lCurLyrId == lID) ? "是" : "否";
- CString szShow,szDelete,szEdit;
- szShow = bShow ? "显示" : "隐藏";
- szEdit = bCanEdit ? "可编辑" : "冻结";
- nitem = m_LayerList.InsertItem(0xffff,LPCTSTR(szID));
- m_LayerList.SetItem(nitem,1,1,LPCTSTR(szLayerName),NULL,0,0,0);
- m_LayerList.SetItem(nitem,2,1,LPCTSTR(szLayerDis),NULL,0,0,0);
- m_LayerList.SetItem(nitem,3,1,LPCTSTR(szShow),NULL,0,0,0);
- m_LayerList.SetItem(nitem,4,1,LPCTSTR(szEdit),NULL,0,0,0);
- m_LayerList.SetItem(nitem,5,1,LPCTSTR(szCurLyr),NULL,0,0,0);
- }
- m_pcurLyr = NULL;
- m_pcurLyr = m_pMap->GetCurLayer();
- if(!m_pcurLyr)
- {
- AfxMessageBox("获取当前图层失败!");
- return;
- }
- SetControlContent(m_pcurLyr);
- UpdateData(FALSE);
- }
- void CDlgLayerManager::ResetList(vector<CQLayerObj *> pLyrVector)
- {
- UpdateData(TRUE);
- m_LayerList.DeleteAllItems();
- if(!m_pMap) return;
- int nLayerCount = pLyrVector.size();
- if(nLayerCount == 0)return;
- int nitem = 0;
- long lCurLyrId = m_pcurLyr->GetLayerID();
- for(int i=0;i<nLayerCount;i++)
- {
- CQLayerObj * pLayer = pLyrVector[i];
- if(!pLayer)return;
- if(pLayer->GetDeleteFlag())continue;
- long lID = pLayer->GetLayerID();
- CString szID;
- szID.Format("%ld",lID);
- CString szLayerName = pLayer->GetLayerName();
- CString szLayerDis = pLayer->GetLayerDis();
- BOOL bCanEdit = pLayer->GetEditFlag();
- BOOL bShow = pLayer->GetShowFlag();
- CString szCurLyr;
- szCurLyr = (lCurLyrId == lID) ? "是" : "否";
- CString szShow,szDelete,szEdit;
- szShow = bShow ? "显示" : "隐藏";
- szEdit = bCanEdit ? "可编辑" : "冻结";
- nitem = m_LayerList.InsertItem(0xffff,LPCTSTR(szID));
- m_LayerList.SetItem(nitem,1,1,LPCTSTR(szLayerName),NULL,0,0,0);
- m_LayerList.SetItem(nitem,2,1,LPCTSTR(szLayerDis),NULL,0,0,0);
- m_LayerList.SetItem(nitem,3,1,LPCTSTR(szShow),NULL,0,0,0);
- m_LayerList.SetItem(nitem,4,1,LPCTSTR(szEdit),NULL,0,0,0);
- m_LayerList.SetItem(nitem,5,1,LPCTSTR(szCurLyr),NULL,0,0,0);
- }
- UpdateData(FALSE);
- }
- //设置控件的操作状态
- void CDlgLayerManager::SetControlEdit(BOOL bEdit)
- {
- int nLayercount = m_pLyrVector.size();
- if(nLayercount == 1)
- {
- GetDlgItem(IDC_RADIO_LAYER_DELETE_QGIS)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_LAYER_UDELETE_QGIS)->EnableWindow(FALSE);
- }
- else
- {
- GetDlgItem(IDC_RADIO_LAYER_DELETE_QGIS)->EnableWindow(bEdit);
- GetDlgItem(IDC_RADIO_LAYER_UDELETE_QGIS)->EnableWindow(bEdit);
- }
- }
- void CDlgLayerManager::OnClickListLayerQgis(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- m_nIndex = -1;
- POSITION pos = m_LayerList.GetFirstSelectedItemPosition();
- m_nIndex=m_LayerList.GetNextSelectedItem(pos);
- if(m_nIndex>-1)
- {
- CQLayerObj * pLyr = NULL;
- pLyr = m_pLyrVector[m_nIndex];
- if(!pLyr->GetDeleteFlag() && pLyr)
- {
- SetControlContent(pLyr);
- }
- }
- *pResult = 0;
- }
- void CDlgLayerManager::SetControlContent(CQLayerObj *pLayer)
- {
- UpdateData(TRUE);
- CQLayerObj * ppLayer = NULL;
- ppLayer = pLayer;
- if(!ppLayer)
- {
- AfxMessageBox("当前图层对象不存在!");
- return;
- }
- m_lLayerID = ppLayer->GetLayerID();
- m_szLayerName = ppLayer->GetLayerName();
- m_szLayerDis = ppLayer->GetLayerDis();
- m_nLayerShow = ppLayer->GetShowFlag() ? 0 : 1;
- m_nLayerDel = ppLayer->GetDeleteFlag() ? 0 : 1;
- m_nLayerEdit = ppLayer->GetEditFlag() ? 0 : 1;
- UpdateData(FALSE);
- }
- void CDlgLayerManager::OnOK()
- {
- UpdateData(TRUE);
- int nLayerCount = m_pLyrVector.size();
- if(nLayerCount == 1 && m_nLayerDel == 0)
- {
- AfxMessageBox("地图中必须存在一个图层!");
- m_nLayerDel = 0;
- UpdateData(FALSE);
- return;
- }
- int nLyrCount = 0;
- for(int i=0;i<nLayerCount;i++)
- {
- CQLayerObj * player = m_pLyrVector[i];
- if(!player) return;
- if(player->GetLayerName().IsEmpty())
- {
- nLyrCount++;
- long lId = player->GetLayerID();
- CString szName;
- szName.Format("%ld",lId);
- player->SetLayerName(szName);
- }
- }
- if(nLyrCount != 0)
- {
- AfxMessageBox("经过图层修改信息修改后,有%d个图层的名称为空,为了使一个图层有意义,系统已经进行了自动赋值操作,请见谅!");
- ResetList(m_pLyrVector);
- return;
- }
- int nLayerCountInMap = m_pMap->GetLayerCount();
- for(int m=0;m<nLayerCountInMap;m++)
- {
- CQLayerObj * pLyr = m_pMap->GetLayer(m);
- if(!pLyr) return;
- m_pMap->RemoveLayer(pLyr); //可以全部都删除
- }
- for(int j=0;j<nLayerCount;j++)
- {
- if(m_pLyrVector[j])
- {
- m_pMap->AddLayer(m_pLyrVector[j]);
- m_pLyrVector[j]->SetMapID(m_pMap->GetMapID());
- }
- }
- CDialog::OnOK();
- }
- //新建图层
- void CDlgLayerManager::OnButtonNewLayerQgis()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- if(!m_pMap)
- {
- AfxMessageBox("当前的地图对象不存在!");
- return;
- }
- CQLayerObj * pLyr = NULL;
- pLyr = new CQLayerObj;
- if(!pLyr)
- {
- AfxMessageBox("图层创建失败!");
- return;
- }
- pLyr->SetMapID(m_pMap->GetMapID());
- long lLayerID = pLyr->GetLayerID();
- //到最后点击了确定后才能生效 m_pMap->AddLayer(pLyr);
- //m_pMap->SetCurLayer(pLyr);
- m_pLyrVector.push_back(pLyr);
- int nLyrCount = m_pLyrVector.size();
- CString szLayerCount;
- szLayerCount.Format("%d",nLyrCount);
- ResetList(m_pLyrVector); //在这里面已经设置了的显示当前图层的显示顺序
- SetControlEdit(TRUE);
- GetDlgItem(IDC_EDIT_LAYER_COUNT_QGIS)->SetWindowText(LPCTSTR(szLayerCount));
- UpdateData(FALSE);
- }
- //删除图层
- void CDlgLayerManager::OnButtonDeleteLayerQgis()
- {
- // TODO: Add your control notification handler code here
- if(m_nIndex == -1)
- {
- AfxMessageBox("请先选择要删除的图层");
- return;
- }
- if(!m_pMap)
- {
- AfxMessageBox("当前地图不存在!");
- return;
- }
- int nLyrcount = m_pLyrVector.size();
- if(m_nIndex > nLyrcount-1)
- {
- AfxMessageBox("图层索引超出限差");
- return;
- }
- long nLyr = m_pcurLyr->GetLayerID();
- if(nLyr == m_pLyrVector[m_nIndex]->GetLayerID())
- {
- AfxMessageBox("当前图层不能删除!");
- return;
- }
- m_pLyrVector[m_nIndex]->SetDeleteFlag(TRUE);
- ResetList(m_pLyrVector);
- SetControlContent(m_pcurLyr);
- int nLyrCount = m_pLyrVector.size();
- m_nIndex = -1;
- CString szLayerCount;
- szLayerCount.Format("%d",nLyrCount);
- SetControlEdit(FALSE);
- GetDlgItem(IDC_EDIT_LAYER_COUNT_QGIS)->SetWindowText(LPCTSTR(szLayerCount));
- GetDlgItem(IDC_EDIT_CUR_LAYER_NAME_QGIS)->SetWindowText(LPCTSTR(m_pcurLyr->GetLayerName()));
- UpdateData(FALSE);
- }
- //置换图层的顺序
- //将最后一个图层的位置移动到第一个
- void CDlgLayerManager::OnButtonTopQgis()
- {
- // TODO: Add your control notification handler code here
- if(!m_pMap)
- {
- AfxMessageBox("当前地图不存在!");
- return;
- }
- int nLyrCount = m_pLyrVector.size();
- if(nLyrCount == 0)return;
- CQLayerObj * pTemp = NULL; //临时变量用于交换指针
- pTemp = m_pLyrVector[0];
- m_pLyrVector[0] = m_pLyrVector[nLyrCount-1];
- m_pLyrVector[nLyrCount-1] = pTemp;
- ResetList(m_pLyrVector);
- m_LayerList.SetSelectionMark(0);
- }
- //将第一个图层移动到最后的一个位置
- void CDlgLayerManager::OnButtonBottomQgis()
- {
- // TODO: Add your control notification handler code here
- if(!m_pMap)
- {
- AfxMessageBox("当前地图不存在!");
- return;
- }
- int nLyrCount = m_pLyrVector.size();
- if(nLyrCount == 0)return;
- CQLayerObj * pTemp = NULL;
- pTemp = m_pLyrVector[0];
- m_pLyrVector[0] = m_pLyrVector[nLyrCount-1];
- m_pLyrVector[nLyrCount-1] = pTemp;
- ResetList(m_pLyrVector);
- m_LayerList.SetSelectionMark(nLyrCount-1);
- }
- void CDlgLayerManager::OnButtonPreQgis()
- {
- // TODO: Add your control notification handler code here
- if(!m_pMap)
- {
- AfxMessageBox("当前地图不存在!");
- return;
- }
- if(m_nIndex <= -1)
- {
- AfxMessageBox("请先在列表框中选中你要移动位置的图层!");
- return;
- }
- if(m_nIndex<1)
- return;
- CQLayerObj * pTemp = NULL;
- pTemp = m_pLyrVector[m_nIndex];
- m_pLyrVector[m_nIndex] = m_pLyrVector[m_nIndex-1];
- m_pLyrVector[m_nIndex-1] = pTemp;
- m_nIndex--;
- ResetList(m_pLyrVector);
- m_LayerList.SetSelectionMark(m_nIndex);
- }
- void CDlgLayerManager::OnButtonNextQgis()
- {
- // TODO: Add your control notification handler code here
- if(!m_pMap)
- {
- AfxMessageBox("当前地图不存在!");
- return;
- }
- int nLyrCount = m_pLyrVector.size();
- if(nLyrCount == 0)return;
- if(m_nIndex>=nLyrCount-1)
- return;
- CQLayerObj * pTemp = NULL;
- pTemp = m_pLyrVector[m_nIndex];
- m_pLyrVector[m_nIndex] = m_pLyrVector[m_nIndex+1];
- m_pLyrVector[m_nIndex+1] = pTemp;
- m_nIndex++;
- ResetList(m_pLyrVector);
- m_LayerList.SetSelectionMark(m_nIndex);
- }
- void CDlgLayerManager::OnButtonSetCurQgis()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- if(m_nIndex == -1 || !m_pMap)
- {
- AfxMessageBox("图层索引有误,或者当前地图不存在!");
- return;
- }
- m_pcurLyr = m_pLyrVector[m_nIndex];
- m_nIndex = -1;
- ResetList(m_pLyrVector);
- SetControlContent(m_pcurLyr);
- GetDlgItem(IDC_EDIT_CUR_LAYER_NAME_QGIS)->SetWindowText(LPCTSTR(m_pcurLyr->GetLayerName()));
- UpdateData(FALSE);
- }
- void CDlgLayerManager::OnCancel()
- {
- CDialog::OnCancel();
- }