Kaydet (Commit) 058deb4a authored tarafından Lionel Elie Mamane's avatar Lionel Elie Mamane

fdo#32958 join editor: remove empty lines

Change-Id: If150261bae55cf91c8a344f34c79194ad29db903
üst 6e41b520
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <algorithm> #include <algorithm>
#include <list>
using std::list;
#include <utility>
using std::pair;
using std::make_pair;
#define SOURCE_COLUMN 1 #define SOURCE_COLUMN 1
#define DEST_COLUMN 2 #define DEST_COLUMN 2
...@@ -60,6 +65,9 @@ namespace dbaui ...@@ -60,6 +65,9 @@ namespace dbaui
long m_nDataPos; long m_nDataPos;
Reference< XPropertySet> m_xSourceDef; Reference< XPropertySet> m_xSourceDef;
Reference< XPropertySet> m_xDestDef; Reference< XPropertySet> m_xDestDef;
enum opcode { DELETE, INSERT, MODIFY };
typedef list< pair < opcode, pair < OConnectionLineDataVec::size_type, OConnectionLineDataVec::size_type> > > ops_type;
ops_type m_ops;
void fillListBox(const Reference< XPropertySet>& _xDest,long nRow,sal_uInt16 nColumnId); void fillListBox(const Reference< XPropertySet>& _xDest,long nRow,sal_uInt16 nColumnId);
...@@ -230,15 +238,17 @@ namespace dbaui ...@@ -230,15 +238,17 @@ namespace dbaui
sal_Bool ORelationControl::SaveModified() sal_Bool ORelationControl::SaveModified()
{ {
DBG_CHKTHIS(ORelationControl,NULL); DBG_CHKTHIS(ORelationControl,NULL);
sal_Int32 nRow = GetCurRow(); long nRow = GetCurRow();
if ( nRow != BROWSER_ENDOFSELECTION ) if ( nRow != BROWSER_ENDOFSELECTION )
{ {
String sFieldName(m_pListCell->GetSelectEntry()); String sFieldName(m_pListCell->GetSelectEntry());
OConnectionLineDataVec* pLines = m_pConnData->GetConnLineDataList(); OConnectionLineDataVec* pLines = m_pConnData->GetConnLineDataList();
if ( pLines->size() <= static_cast<sal_uInt32>(nRow) ) if ( pLines->size() <= static_cast<OConnectionLineDataVec::size_type>(nRow) )
{ {
pLines->push_back(new OConnectionLineData()); pLines->push_back(new OConnectionLineData());
nRow = pLines->size() - 1; nRow = pLines->size() - 1;
// add new past-pLines row
m_ops.push_back(make_pair(INSERT, make_pair(nRow+1, nRow+2)));
} }
OConnectionLineDataRef pConnLineData = (*pLines)[nRow]; OConnectionLineDataRef pConnLineData = (*pLines)[nRow];
...@@ -252,8 +262,18 @@ namespace dbaui ...@@ -252,8 +262,18 @@ namespace dbaui
pConnLineData->SetDestFieldName( sFieldName ); pConnLineData->SetDestFieldName( sFieldName );
break; break;
} }
// the modification we just did does *not* need to be registered in m_ops;
// it is already taken into account (by the codepath that called us)
//m_ops.push_back(make_pair(MODIFY, make_pair(nRow, nRow+1)));
} }
const OConnectionLineDataVec::size_type oldSize = m_pConnData->GetConnLineDataList()->size();
OConnectionLineDataVec::size_type line = m_pConnData->normalizeLines();
const OConnectionLineDataVec::size_type newSize = m_pConnData->GetConnLineDataList()->size();
assert(newSize <= oldSize);
m_ops.push_back(make_pair(MODIFY, make_pair(line, newSize)));
m_ops.push_back(make_pair(DELETE, make_pair(newSize, oldSize)));
return sal_True; return sal_True;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -636,12 +656,27 @@ OTableListBoxControl::OTableListBoxControl( Window* _pParent ...@@ -636,12 +656,27 @@ OTableListBoxControl::OTableListBoxControl( Window* _pParent
} }
m_pParentDialog->setValid(bValid); m_pParentDialog->setValid(bValid);
if ( pLines->size() >= static_cast<sal_uInt32>(m_pRC_Tables->GetRowCount()) ) ORelationControl::ops_type::iterator i (m_pRC_Tables->m_ops.begin());
const ORelationControl::ops_type::const_iterator e (m_pRC_Tables->m_ops.end());
m_pRC_Tables->DeactivateCell();
for(; i != e; ++i)
{ {
m_pRC_Tables->DeactivateCell(); switch(i->first)
m_pRC_Tables->RowInserted(m_pRC_Tables->GetRowCount(), pLines->size() - static_cast<sal_uInt32>(m_pRC_Tables->GetRowCount()) + 1, sal_True); {
m_pRC_Tables->ActivateCell(); case ORelationControl::DELETE:
m_pRC_Tables->RowRemoved(i->second.first, i->second.second - i->second.first);
break;
case ORelationControl::INSERT:
m_pRC_Tables->RowInserted(i->second.first, i->second.second - i->second.first);
break;
case ORelationControl::MODIFY:
for(OConnectionLineDataVec::size_type j = i->second.first; j < i->second.second; ++j)
m_pRC_Tables->RowModified(j);
break;
}
} }
m_pRC_Tables->ActivateCell();
m_pRC_Tables->m_ops.clear();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void fillEntryAndDisable(ListBox& _rListBox,const String& _sEntry) void fillEntryAndDisable(ListBox& _rListBox,const String& _sEntry)
...@@ -696,9 +731,7 @@ OTableListBoxControl::OTableListBoxControl( Window* _pParent ...@@ -696,9 +731,7 @@ OTableListBoxControl::OTableListBoxControl( Window* _pParent
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
sal_Bool OTableListBoxControl::SaveModified() sal_Bool OTableListBoxControl::SaveModified()
{ {
sal_Bool bRet = m_pRC_Tables->SaveModified(); return m_pRC_Tables->SaveModified();
m_pRC_Tables->getData()->normalizeLines();
return bRet;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TTableWindowData::value_type OTableListBoxControl::getReferencingTable() const TTableWindowData::value_type OTableListBoxControl::getReferencingTable() const
......
...@@ -77,8 +77,13 @@ namespace dbaui ...@@ -77,8 +77,13 @@ namespace dbaui
void ResetConnLines(); void ResetConnLines();
/** moves the empty lines to the back /** moves the empty lines to the back
removes duplicated empty lines
caller is responsible for repainting them
@return infex of first changed line, or one-past-the-end if no change
*/ */
void normalizeLines(); OConnectionLineDataVec::size_type normalizeLines();
const OConnectionLineDataVec* GetConnLineDataList() const { return &m_vConnLineData; } const OConnectionLineDataVec* GetConnLineDataList() const { return &m_vConnLineData; }
OConnectionLineDataVec* GetConnLineDataList() { return &m_vConnLineData; } OConnectionLineDataVec* GetConnLineDataList() { return &m_vConnLineData; }
......
...@@ -162,22 +162,25 @@ OTableConnectionData* OTableConnectionData::NewInstance() const ...@@ -162,22 +162,25 @@ OTableConnectionData* OTableConnectionData::NewInstance() const
return new OTableConnectionData(); return new OTableConnectionData();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void OTableConnectionData::normalizeLines() OConnectionLineDataVec::size_type OTableConnectionData::normalizeLines()
{ {
// noch ein wenig Normalisierung auf den LineDatas : leere Lines vom Anfang an das Ende verschieben // remove empty lines
sal_Int32 nCount = m_vConnLineData.size(); OConnectionLineDataVec::size_type nCount = m_vConnLineData.size();
for(sal_Int32 i=0;i<nCount;) OConnectionLineDataVec::size_type nRet = nCount;
for(OConnectionLineDataVec::size_type i = 0; i < nCount;)
{ {
if(m_vConnLineData[i]->GetSourceFieldName().isEmpty() || m_vConnLineData[i]->GetDestFieldName().isEmpty()) if(m_vConnLineData[i]->GetSourceFieldName().isEmpty() && m_vConnLineData[i]->GetDestFieldName().isEmpty())
{ {
OConnectionLineDataRef pData = m_vConnLineData[i]; OConnectionLineDataRef pData = m_vConnLineData[i];
m_vConnLineData.erase(m_vConnLineData.begin()+i); m_vConnLineData.erase(m_vConnLineData.begin()+i);
m_vConnLineData.push_back(pData);
--nCount; --nCount;
if (i < nRet)
nRet=i;
} }
else else
++i; ++i;
} }
return nRet;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment