📄 pagequery1.cpp
字号:
//////////////////////////////////////////////////////
//
// NRDB Pro - Spatial database and mapping application
//
// Copyright (c) 1989-2004 Richard D. Alexander
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// NRDB Pro is part of the Natural Resources Database Project
//
// Homepage: http://www.nrdb.co.uk/
// Users' Forum: http://nrdb.mypalawan.info/
//
#include "stdafx.h"
#include "nrdb.h"
#include "PageQuery1.h"
#include "SheetQuery.h"
#include "dlgselectfeatures.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPageQuery1 property page
IMPLEMENT_DYNCREATE(CPageQuery1, CPropertyPage)
CPageQuery1::CPageQuery1(CQuery* pQuery, CQuery* pQueryPrev, int nType) : CPropertyPage(CPageQuery1::IDD)
{
m_pQuery = pQuery;
m_pQueryPrev = pQueryPrev;
m_nType = nType;
m_bUpdateList = FALSE;
m_pTooltip = NULL;
m_nNumber = 0;
//{{AFX_DATA_INIT(CPageQuery1)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CPageQuery1::CPageQuery1()
{
m_pTooltip = NULL;
}
CPageQuery1::~CPageQuery1()
{
if (m_pTooltip != NULL) delete m_pTooltip;
}
void CPageQuery1::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPageQuery1)
DDX_Control(pDX, IDC_FTYPE, m_cbFType);
DDX_Control(pDX, IDC_ELEMENTS, m_ctrlTree);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPageQuery1, CPropertyPage)
//{{AFX_MSG_MAP(CPageQuery1)
ON_CBN_SELCHANGE(IDC_FTYPE, OnSelchangeFtype)
ON_BN_CLICKED(IDC_SELECTALL, OnSelectall)
ON_NOTIFY(TVN_SELCHANGED, IDC_ELEMENTS, OnSelchangedElements)
ON_BN_CLICKED(IDC_DICTIONARY, OnDictionary)
ON_BN_CLICKED(IDC_SELECT, OnSelect)
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPageQuery1 message handlers
BOOL CPageQuery1::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// Set font for tree control
LOGFONT lf;
memset(&lf,0,sizeof(LOGFONT));
lf.lfHeight = -11;
lf.lfPitchAndFamily = 12;
lf.lfCharSet = NRDB_CHARSET;
strcpy(lf.lfFaceName, BDString(IDS_DEFAULTFONT));
m_font.CreateFontIndirect(&lf);
m_ctrlTree.SetFont(&m_font);
long lFType = 0;
// Initialise the tree control
m_imagelist.Create(IDB_TREECTRL, 16, 0, RGB(255,255,255));
m_ctrlTree.SetImageList(&m_imagelist, TVSIL_NORMAL);
// Initialise feature types
m_cbFType.Init(BDFTypeSel());
// Retrieved saved feature type
m_cbFType.GetItemDataX(lFType);
if (m_pQueryPrev->GetFType() != 0 &&
m_pQueryPrev->GetFType() == lFType)
{
UpdateList(m_pQueryPrev);
*m_pQuery = *m_pQueryPrev;
} else
{
OnSelchangeFtype();
};
// Enable tooltips
BDHwndDialog() = m_hWnd;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
///////////////////////////////////////////////////////////////////////////////
void CPageQuery1::OnSelchangeFtype()
{
BeginWaitCursor();
long lFType;
m_bUpdateList = TRUE;
m_ctrlTree.DeleteAllItems();
// Retrieve the selected feature
if (m_cbFType.GetItemDataX(lFType) != CB_ERR)
{
// Initialise the query
m_pQuery->Initialise(lFType);
// Display the results in the tree control
UpdateList(m_pQuery);
}
m_bUpdateList = FALSE;
EndWaitCursor();
}
/////////////////////////////////////////////////////////////////////////////
void CPageQuery1::UpdateList(CQuery* pQuery, HTREEITEM hParent)
{
CQueryElement* pElement = pQuery;
m_bUpdateList = TRUE;
HTREEITEM hItem = m_ctrlTree.InsertItem(pElement->GetDesc(), hParent);
m_ctrlTree.SetCheck(hItem, pElement->GetSelected());
HTREEITEM hLast = TVI_ROOT;
while (pElement != NULL)
{
pElement = pElement->GetNextQuery();
if (pElement != NULL)
{
// If a feature type then move one level down and exit
if (pElement->GetDataType() == BDFTYPE)
{
UpdateList((CQuery*)pElement, hItem);
break;
}
// Otherise add at this level
else
{
if (pElement->GetDataType() != BDQUERYSTATS)
{
hLast = m_ctrlTree.InsertItem(pElement->GetDesc(), hItem);
m_ctrlTree.SetCheck(hLast, pElement->GetSelected());
};
};
// If a link type then add links to tree
if (pElement->GetDataType() == BDLINK ||
pElement->GetDataType() == BDFEATURE ||
pElement->GetDataType() == BDBOOLEAN)
{
UpdateLink((CQueryLink*)pElement, hLast);
}
};
};
if (hParent == TVI_ROOT) m_ctrlTree.Expand(hItem, TVE_EXPAND);
m_bUpdateList = FALSE;
}
///////////////////////////////////////////////////////////////////////////////
//
// Update features for the feature type
//
void CPageQuery1::UpdateLink(CQueryLink* pLink, HTREEITEM hParent)
{
HTREEITEM hItem;
for (int i = 0; i < pLink->m_aFeatures.GetSize(); i++)
{
CQueryFeature* pFeature = &pLink->m_aFeatures.GetAt(i);
hItem = m_ctrlTree.InsertItem(pFeature->m_sName, hParent);
m_ctrlTree.SetCheck(hItem, pFeature->GetSelected());
}
}
///////////////////////////////////////////////////////////////////////////////
void CPageQuery1::OnSelectall()
{
// Determine which item has been selected
HTREEITEM hItem = m_ctrlTree.GetSelectedItem();
if (hItem != NULL)
{
DWORD dw = m_ctrlTree.GetItemData(hItem);
BOOL bCheck = !m_ctrlTree.GetCheck(hItem);
m_ctrlTree.SetCheck(hItem, bCheck);
// If a link then select all subitems
HTREEITEM hChild = m_ctrlTree.GetChildItem(hItem);
while (hChild != NULL)
{
m_ctrlTree.SetCheck(hChild, bCheck);
hChild = m_ctrlTree.GetNextSiblingItem(hChild);
};
};
}
///////////////////////////////////////////////////////////////////////////////
//
// Allows features to be selected by parent
//
void CPageQuery1::OnSelect()
{
long lFType = 0;
// Determine the parent feature type of that selected
int index = m_cbFType.GetCurSel();
if (index != CB_ERR)
{
lFType = m_cbFType.GetItemData(index);
// Create a dialog allowing a sub-set of the features to be selected
CDlgSelectFeatures dlg(lFType);
if (dlg.DoModal() == IDOK)
{
// Retrieve the data
RetrieveSelections(m_pQuery);
// Update the selected features
CQueryElement* pElement = m_pQuery;
while (pElement != NULL)
{
if (pElement->GetDataType() == BDFEATURE)
{
CQueryLink* pLink = (CQueryLink*)pElement;
for (int i = 0; i < pLink->m_aFeatures.GetSize(); i++)
{
pLink->m_aFeatures[i].SetSelected(FALSE);
for (int j = 0; j < dlg.GetFeatures().GetSize(); j++)
{
if ((long)dlg.GetFeatures().GetAt(j) == pLink->m_aFeatures[i].m_lId)
{
pLink->m_aFeatures[i].SetSelected(TRUE);
break;
}
}
}
}
pElement = pElement->GetNextQuery();
}
// Restore the selections
m_ctrlTree.DeleteAllItems();
UpdateList(m_pQuery);
}
};
}
///////////////////////////////////////////////////////////////////////////////
void CPageQuery1::RetrieveSelections(CQuery* pQuery, HTREEITEM hItem)
{
CQueryElement* pElement = pQuery;
HTREEITEM hLast = NULL;
CString s;
if (hItem == TVI_ROOT) hItem = m_ctrlTree.GetChildItem(hItem);
if (hItem != NULL)
{
BOOL bCheck = m_ctrlTree.GetCheck(hItem);
pElement->SetSelected(bCheck);
s = m_ctrlTree.GetItemText(hItem);
pElement = pElement->GetNextQuery();
while (pElement != NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -