forked from mia/Aegisub
Use vector<int> instead of vector<bool> for tracking which rows are selected. Makes undo roughly twice as fast.
Originally committed to SVN as r4563.
This commit is contained in:
parent
358b2734da
commit
5ed401d23d
3 changed files with 33 additions and 44 deletions
|
@ -128,7 +128,8 @@ void BaseGrid::UpdateStyle() {
|
|||
// Set column widths
|
||||
std::vector<bool> column_array;
|
||||
OPT_GET("Subtitle/Grid/Column")->GetListBool(column_array);
|
||||
for (int i=0;i<10;i++) showCol[i] = column_array.at(i);
|
||||
assert(column_array.size() == columns);
|
||||
for (int i=0;i<columns;i++) showCol[i] = column_array[i];
|
||||
SetColumnWidths();
|
||||
|
||||
// Update
|
||||
|
@ -210,7 +211,7 @@ void BaseGrid::SelectRow(int row, bool addToSelected, bool select) {
|
|||
if (row < 0 || (size_t)row >= selMap.size()) return;
|
||||
if (!addToSelected) ClearSelection();
|
||||
|
||||
if (select != selMap[row]) {
|
||||
if (select != !!selMap[row]) {
|
||||
selMap[row] = select;
|
||||
|
||||
if (!addToSelected) {
|
||||
|
@ -269,7 +270,7 @@ void BaseGrid::ClearSelection() {
|
|||
///
|
||||
bool BaseGrid::IsInSelection(int row, int) const {
|
||||
if ((size_t)row >= selMap.size() || row < 0) return false;
|
||||
return selMap[row];
|
||||
return !!selMap[row];
|
||||
}
|
||||
|
||||
|
||||
|
@ -278,7 +279,7 @@ bool BaseGrid::IsInSelection(int row, int) const {
|
|||
/// @return
|
||||
///
|
||||
int BaseGrid::GetNumberSelection() const {
|
||||
return std::count(selMap.begin(), selMap.end(), true);
|
||||
return std::count(selMap.begin(), selMap.end(), 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -287,7 +288,7 @@ int BaseGrid::GetNumberSelection() const {
|
|||
/// @return
|
||||
///
|
||||
int BaseGrid::GetFirstSelRow() const {
|
||||
std::vector<bool>::const_iterator first = std::find(selMap.begin(), selMap.end(), true);
|
||||
std::vector<int>::const_iterator first = std::find(selMap.begin(), selMap.end(), 1);
|
||||
if (first == selMap.end()) return -1;
|
||||
return std::distance(selMap.begin(), first);
|
||||
}
|
||||
|
@ -941,8 +942,8 @@ void BaseGrid::SetColumnWidths() {
|
|||
for (int i=0;i<3;i++) colWidth[i+7] = showMargin[i] ? marginLen : 0;
|
||||
|
||||
// Hide columns
|
||||
for (int i=0;i<10;i++) {
|
||||
if (showCol[i] == false) colWidth[i] = 0;
|
||||
for (int i=0;i<columns;i++) {
|
||||
if (!showCol[i]) colWidth[i] = 0;
|
||||
}
|
||||
|
||||
// Set size of last
|
||||
|
@ -988,13 +989,9 @@ bool BaseGrid::IsDisplayed(AssDialogue *line) {
|
|||
///
|
||||
void BaseGrid::UpdateMaps() {
|
||||
// Store old
|
||||
int len = diagMap.size();
|
||||
std::vector<AssDialogue *> tmpDiagPtrMap;
|
||||
std::vector<bool> tmpSelMap;
|
||||
for (int i=0;i<len;i++) {
|
||||
tmpDiagPtrMap.push_back(diagPtrMap[i]);
|
||||
tmpSelMap.push_back(selMap[i]);
|
||||
}
|
||||
int len = selMap.size();
|
||||
std::vector<AssDialogue *> tmpDiagPtrMap(diagPtrMap);
|
||||
std::vector<int> tmpSelMap(selMap);
|
||||
|
||||
// Clear old
|
||||
diagPtrMap.clear();
|
||||
|
@ -1002,13 +999,11 @@ void BaseGrid::UpdateMaps() {
|
|||
selMap.clear();
|
||||
|
||||
// Re-generate lines
|
||||
int n = 0;
|
||||
AssDialogue *curdiag;
|
||||
for (entryIter cur=AssFile::top->Line.begin();cur != AssFile::top->Line.end();cur++) {
|
||||
curdiag = dynamic_cast<AssDialogue*>(*cur);
|
||||
AssDialogue *curdiag = dynamic_cast<AssDialogue*>(*cur);
|
||||
if (curdiag) {
|
||||
// Find old pos
|
||||
bool sel = false;
|
||||
int sel = 0;
|
||||
for (int i=0;i<len;i++) {
|
||||
if (tmpDiagPtrMap[i] == curdiag) {
|
||||
sel = tmpSelMap[i];
|
||||
|
@ -1020,8 +1015,6 @@ void BaseGrid::UpdateMaps() {
|
|||
diagMap.push_back(cur);
|
||||
diagPtrMap.push_back(curdiag);
|
||||
selMap.push_back(sel);
|
||||
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,8 @@ protected:
|
|||
FrameMain *parentFrame;
|
||||
|
||||
/// DOCME
|
||||
bool showCol[16];
|
||||
static const int columns = 10;
|
||||
bool showCol[columns];
|
||||
|
||||
|
||||
/// @brief DOCME
|
||||
|
@ -126,7 +127,7 @@ protected:
|
|||
int yPos;
|
||||
|
||||
/// DOCME
|
||||
std::vector<bool> selMap;
|
||||
std::vector<int> selMap;
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -132,22 +132,22 @@ SubtitlesGrid::~SubtitlesGrid() {
|
|||
void SubtitlesGrid::OnPopupMenu(bool alternate) {
|
||||
// Alternate
|
||||
if (alternate) {
|
||||
// Prepare strings
|
||||
wxArrayString strings;
|
||||
strings.Add(_("Line Number"));
|
||||
strings.Add(_("Layer"));
|
||||
strings.Add(_("Start"));
|
||||
strings.Add(_("End"));
|
||||
strings.Add(_("Style"));
|
||||
strings.Add(_("Actor"));
|
||||
strings.Add(_("Effect"));
|
||||
strings.Add(_("Left"));
|
||||
strings.Add(_("Right"));
|
||||
strings.Add(_("Vert"));
|
||||
const wxString strings[] = {
|
||||
_("Line Number"),
|
||||
_("Layer"),
|
||||
_("Start"),
|
||||
_("End"),
|
||||
_("Style"),
|
||||
_("Actor"),
|
||||
_("Effect"),
|
||||
_("Left"),
|
||||
_("Right"),
|
||||
_("Vert"),
|
||||
};
|
||||
|
||||
// Create Menu
|
||||
wxMenu menu;
|
||||
for (size_t i=0;i<strings.Count();i++) {
|
||||
for (size_t i=0;i<columns;i++) {
|
||||
menu.Append(MENU_SHOW_COL + i,strings[i],_T(""),wxITEM_CHECK)->Check(showCol[i]);
|
||||
}
|
||||
PopupMenu(&menu);
|
||||
|
@ -227,7 +227,7 @@ void SubtitlesGrid::OnShowColMenu(wxCommandEvent &event) {
|
|||
int item = event.GetId()-MENU_SHOW_COL;
|
||||
showCol[item] = !showCol[item];
|
||||
|
||||
std::vector<bool> map(showCol, showCol + sizeof(showCol) / sizeof(bool));
|
||||
std::vector<bool> map(showCol, showCol + columns);
|
||||
OPT_SET("Subtitle/Grid/Column")->SetListBool(map);
|
||||
|
||||
// Update
|
||||
|
@ -810,14 +810,9 @@ void SubtitlesGrid::LoadDefault (AssFile *_ass) {
|
|||
///
|
||||
void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModify) {
|
||||
// Store selected rows
|
||||
std::vector<int> srows;
|
||||
wxArrayInt srows;
|
||||
if (keepSelection) {
|
||||
int nrows = GetRows();
|
||||
for (int i=0;i<nrows;i++) {
|
||||
if (IsInSelection(i,0)) {
|
||||
srows.push_back(i);
|
||||
}
|
||||
}
|
||||
srows = GetSelection();
|
||||
}
|
||||
|
||||
// Clear grid
|
||||
|
@ -853,7 +848,7 @@ void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModif
|
|||
// Restore selection
|
||||
if (keepSelection) {
|
||||
for (size_t i=0;i<srows.size();i++) {
|
||||
SelectRow(srows.at(i),true);
|
||||
SelectRow(srows[i],true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue