Use std algorithme in view/grid
This commit is contained in:
parent
08ba72664c
commit
a4179804be
|
@ -40,6 +40,11 @@ struct Operation {
|
||||||
bool meta;
|
bool meta;
|
||||||
bool _virtual;
|
bool _virtual;
|
||||||
std::vector<wxString> childs;
|
std::vector<wxString> childs;
|
||||||
|
|
||||||
|
bool operator == (const wxString& opId)
|
||||||
|
{
|
||||||
|
return id == opId;
|
||||||
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
bool sortOperations(const Operation& op1, const Operation& op2);
|
bool sortOperations(const Operation& op1, const Operation& op2);
|
||||||
|
|
|
@ -137,36 +137,32 @@ void GridAccount::SetWeek(int week, int line) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Operation& GridAccount::GetOperation(const wxString& id)
|
Operation& GridAccount::GetOperation(const wxString& id) throw (OperationNotFound)
|
||||||
{
|
{
|
||||||
std::vector<Operation>::iterator it;
|
std::vector<Operation>::iterator it = std::find(_operations->begin(), _operations->end(), id);
|
||||||
|
|
||||||
for(it=_operations->begin(); it!=_operations->end(); it++)
|
if (it != _operations->end()) return *it;
|
||||||
if (it->id == id)
|
|
||||||
return *it;
|
throw OperationNotFound();
|
||||||
// I'm aware about the warning, but the method may not fail
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridAccount::UpdateOperation(Operation& op)
|
void GridAccount::UpdateOperation(Operation& op)
|
||||||
{
|
{
|
||||||
std::vector<Operation>::iterator it;
|
std::vector<Operation>::iterator it = std::find(_operations->begin(), _operations->end(), op.id);
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i=0; i < (int)_operations->size(); i++)
|
if (it != _operations->end())
|
||||||
if ((*_operations)[i].id == op.id)
|
|
||||||
{
|
{
|
||||||
if (_databaseSynchronization)
|
if (_databaseSynchronization)
|
||||||
_kiss->UpdateOperation(op);
|
_kiss->UpdateOperation(op);
|
||||||
(*_operations)[i] = op;
|
*it = op;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int GridAccount::GetDisplayedRow(const wxString& id)
|
int GridAccount::GetDisplayedRow(const wxString& id)
|
||||||
{
|
{
|
||||||
for(int i=0; i<(int)_displayedOperations.size(); i++)
|
std::vector<Operation>::iterator it = std::find(_displayedOperations.begin(), _displayedOperations.end(), id);
|
||||||
if (_displayedOperations[i].id == id)
|
|
||||||
return i;
|
if (it != _displayedOperations.end()) return it-_displayedOperations.begin();
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -476,14 +472,9 @@ void GridAccount::OnCellLeftClick(wxGridEvent& evt)
|
||||||
|
|
||||||
void GridAccount::DeleteOperation(const Operation& op)
|
void GridAccount::DeleteOperation(const Operation& op)
|
||||||
{
|
{
|
||||||
std::vector<Operation>::iterator it;
|
std::vector<Operation>::iterator it = std::find(_operations->begin(), _operations->end(), op.id);
|
||||||
|
|
||||||
for (it=_operations->begin(); it!=_operations->end(); it++)
|
if (it != _operations->end()) _operations->erase(it);
|
||||||
if (it->id == op.id)
|
|
||||||
{
|
|
||||||
_operations->erase(it);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridAccount::InsertIntoGrid(Operation& op)
|
void GridAccount::InsertIntoGrid(Operation& op)
|
||||||
|
@ -1231,9 +1222,7 @@ void GridAccount::GetSelectedOperations(std::vector<int>* rows)
|
||||||
const wxGridCellCoords& br = bbr[i];
|
const wxGridCellCoords& br = bbr[i];
|
||||||
for (int row = tl.GetRow(); row <= br.GetRow(); ++row)
|
for (int row = tl.GetRow(); row <= br.GetRow(); ++row)
|
||||||
{
|
{
|
||||||
for (it=rows->begin(); it!=rows->end(); it++)
|
it = std::find(rows->begin(), rows->end(), row);
|
||||||
if (*it == row)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (it != rows->end() || !row) continue;
|
if (it != rows->end() || !row) continue;
|
||||||
|
|
||||||
|
@ -1246,15 +1235,15 @@ void GridAccount::GetSelectedOperations(std::vector<int>* rows)
|
||||||
const wxGridCellCoordsArray& cells(GetSelectedCells());
|
const wxGridCellCoordsArray& cells(GetSelectedCells());
|
||||||
for (size_t i = 0; i < cells.size(); ++i)
|
for (size_t i = 0; i < cells.size(); ++i)
|
||||||
{
|
{
|
||||||
const wxGridCellCoords& c = cells[i];
|
int row = cells[i].GetRow();
|
||||||
|
|
||||||
for (it=rows->begin(); it!=rows->end(); it++)
|
if (!row) continue;
|
||||||
if (*it == c.GetRow())
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (it != rows->end() || !c.GetRow()) continue;
|
it = std::find(rows->begin(), rows->end(), row);
|
||||||
|
|
||||||
rows->push_back(c.GetRow());
|
if (it != rows->end()) continue;
|
||||||
|
|
||||||
|
rows->push_back(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,8 @@ typedef void (*updateOperationFunc)(Operation* op, void** params);
|
||||||
class GridAccount : public wxGrid
|
class GridAccount : public wxGrid
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
class OperationNotFound {};
|
||||||
|
|
||||||
GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id,
|
GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id,
|
||||||
bool canAddOperation, bool setWeek, bool synchronizeWithDatabase);
|
bool canAddOperation, bool setWeek, bool synchronizeWithDatabase);
|
||||||
~GridAccount();
|
~GridAccount();
|
||||||
|
@ -90,7 +92,7 @@ private:
|
||||||
int RemoveMeta(Operation op, int line, bool removeRoot, bool deleteOp);
|
int RemoveMeta(Operation op, int line, bool removeRoot, bool deleteOp);
|
||||||
void CheckMeta(Operation& op, int line, bool check);
|
void CheckMeta(Operation& op, int line, bool check);
|
||||||
|
|
||||||
Operation& GetOperation(const wxString& id);
|
Operation& GetOperation(const wxString& id) throw(OperationNotFound);
|
||||||
void UpdateOperation(Operation& op);
|
void UpdateOperation(Operation& op);
|
||||||
int GetDisplayedRow(const wxString& id);
|
int GetDisplayedRow(const wxString& id);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user