QLayerList.cpp
资源名称:QGIS.rar [点击查看]
上传用户:oybseng
上传日期:2015-04-27
资源大小:7831k
文件大小:3k
源码类别:
GDI/图象编程
开发平台:
Visual C++
- // QLayerList.cpp: implementation of the CQLayerList class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "..stdafx.h"
- #include "..includeQLayerObj.h"
- #include "..includeQLayerList.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CQLayerList::CQLayerList()
- {
- }
- CQLayerList::~CQLayerList()
- {
- DeleteAll();
- }
- CQLayerList::CQLayerList(CQLayerList &List)
- {
- int nLayerCount = List.GetCount();
- if(nLayerCount == 0) return;
- RemoveAll();
- POSITION pos = List.GetHeadPosition();
- while (pos)
- {
- CQLayerObj * pLayer = new CQLayerObj(*(List.GetNext(pos)));
- AddTail((void *)pLayer);
- }
- }
- void CQLayerList::Add(CQLayerObj * pObject)
- {
- if(pObject)
- {
- CPtrList::AddTail(pObject);
- }
- }
- void CQLayerList::Delete(CQLayerObj * pObject)
- {
- if(!pObject) return;
- Remove(pObject);
- delete pObject;
- }
- void CQLayerList::Remove(CQLayerObj * pObject)
- {
- if(!pObject)return;
- POSITION pos = CPtrList::Find(pObject);
- if(pos)
- {
- RemoveAt(pos);
- }
- }
- void CQLayerList::DeleteAll()
- {
- while (!IsEmpty())
- {
- CQLayerObj * p = (CQLayerObj *)RemoveHead();
- if(p)
- delete p;
- }
- }
- CQLayerObj * CQLayerList::Find(long lLayerID)
- {
- int nCount = GetCount();
- POSITION pos = GetHeadPosition();
- while(pos)
- {
- CQLayerObj * p = (CQLayerObj *)GetNext(pos);
- if(p)
- {
- if(p->GetLayerID() == lLayerID)
- return p;
- }
- }
- return NULL;
- }
- void CQLayerList::Serialize(CArchive & ar)
- {
- if(ar.IsStoring())
- {
- CQLayerObj * pLayer = NULL;
- POSITION pos;
- pos = GetHeadPosition();
- //把有删除标志的对象删除
- while (pos)
- {
- pLayer = GetNext(pos);
- if(pLayer)
- {
- if(pLayer->GetDeleteFlag())
- Delete(pLayer);
- }
- }
- int nCount = GetCount();
- ar.Write(&nCount,sizeof(int));
- pos = GetHeadPosition();
- while (pos)
- {
- pLayer = GetNext(pos);
- if(pLayer)
- pLayer->Serialize(ar);
- }
- }
- else
- {
- int nCount = 0;
- ar.Read(&nCount,sizeof(int));
- CQLayerObj * pLayer = NULL;
- for(int i=0;i<nCount;i++)
- {
- pLayer = new CQLayerObj;
- pLayer->Serialize(ar);
- Add(pLayer);
- }
- }
- }
- inline CQLayerObj * CQLayerList::GetAt(POSITION& rPosition)
- {
- return (CQLayerObj *)(CPtrList::GetAt(rPosition));
- }
- inline POSITION CQLayerList::GetHeadPosition()
- {
- return (POSITION)CPtrList::GetTailPosition();
- }
- inline CQLayerObj * CQLayerList::GetNext(POSITION & rPosition)
- {
- return (CQLayerObj *)(CPtrList::GetNext(rPosition));
- }
- void CQLayerList::Copy(CQLayerList &List)
- {
- int nLayerCount = List.GetCount();
- if(nLayerCount == 0) return;
- RemoveAll();
- POSITION pos = List.GetHeadPosition();
- while (pos)
- {
- CQLayerObj * pLayer = new CQLayerObj(*(List.GetNext(pos)));
- AddTail((void *)pLayer);
- }
- }