3 #include "TableColumnList.h"
12 #include "TableColumn.h"
21 TableColumnList::TableColumnList() {
29 TableColumnList::TableColumnList(TableColumnList
const &other) {
37 TableColumnList::~TableColumnList() {
41 delete m_sortingOrder;
42 m_sortingOrder = NULL;
46 TableColumn *&TableColumnList::operator[](
int index) {
47 checkIndexRange(index);
49 return (*m_cols)[index];
53 TableColumn *&TableColumnList::operator[](QString title) {
54 for (
int i = 0; i < m_cols->size(); i++)
55 if (m_cols->at(i)->getTitle() == title)
58 QString msg =
"There is no column with a title of [";
60 msg +=
"] inside this column list";
65 void TableColumnList::append(TableColumn *newCol) {
67 QString msg =
"Attempted to add NULL column to the columnlist";
71 m_cols->append(newCol);
72 m_sortingOrder->append(newCol);
73 connect(newCol, SIGNAL(sortOutDated()),
this, SIGNAL(sortOutDated()));
77 void TableColumnList::prepend(TableColumn *newCol) {
78 m_cols->prepend(newCol);
79 m_sortingOrder->append(newCol);
83 int TableColumnList::indexOf(TableColumn
const *someCol)
const {
85 for (
int i = 0; index < 0 && i < m_cols->size(); i++)
86 if ((*m_cols)[i] == someCol)
93 bool TableColumnList::contains(TableColumn
const *someCol)
const {
94 return indexOf(someCol) != -1;
98 bool TableColumnList::contains(QString columnTitle)
const {
99 bool foundTitle =
false;
100 for (
int i = 0; i < m_cols->size() && !foundTitle; i++)
101 foundTitle = (m_cols->at(i)->getTitle() == columnTitle);
106 void TableColumnList::lower(TableColumn *col,
bool emitSortOutDated) {
107 int oldIndex = m_sortingOrder->indexOf(col);
108 checkIndexRange(oldIndex);
111 if (oldIndex < m_sortingOrder->size() - 1) {
112 m_sortingOrder->removeAt(oldIndex);
113 m_sortingOrder->insert(oldIndex + 1, col);
116 if (emitSortOutDated)
126 void TableColumnList::raise(TableColumn *col,
bool emitSortOutDated) {
127 int oldIndex = m_sortingOrder->indexOf(col);
128 checkIndexRange(oldIndex);
132 m_sortingOrder->removeAt(oldIndex);
133 m_sortingOrder->insert(oldIndex - 1, col);
136 if (emitSortOutDated)
146 void TableColumnList::raiseToTop(TableColumn *col) {
147 while (m_sortingOrder->at(0) != col)
159 int TableColumnList::size()
const {
161 return m_cols->size();
165 TableColumnList &TableColumnList::operator=(
166 TableColumnList other) {
167 swap(*m_cols, *other.m_cols);
168 swap(*m_sortingOrder, *other.m_sortingOrder);
183 if (visibleColumn < visibleCols.size() && visibleColumn >= 0) {
186 for (
int i = 0; i < visibleColumn; i++)
187 indent += visibleCols[i]->getWidth() - 1;
190 maxX = minX + visibleCols[visibleColumn]->getWidth() - 1;
203 for (
int i = 0; i < size(); i++)
204 if (m_cols->at(i)->isVisible())
205 visibleColumns.append(m_cols->at(i));
210 *visibleColumns.m_sortingOrder = *m_sortingOrder;
211 for (
int i = m_sortingOrder->size() - 1; i >= 0; i--)
212 if (!visibleColumns.contains((*visibleColumns.m_sortingOrder)[i]))
213 visibleColumns.m_sortingOrder->removeAt(i);
217 return visibleColumns;
221 int TableColumnList::getVisibleWidth()
const {
224 for (
int i = 0; i < size(); i++)
225 if (m_cols->at(i)->isVisible())
226 width += m_cols->at(i)->getWidth() - 1;
235 ASSERT(m_sortingOrder);
238 for (
int i = 0; i < m_sortingOrder->size(); i++)
239 if (m_sortingOrder->at(i)->getTitle().size())
240 validSortingOrder.append(m_sortingOrder->at(i));
242 return validSortingOrder;
246 QStringList TableColumnList::getSortingOrderAsStrings()
const {
248 for (
int i = 0; i < m_sortingOrder->size(); i++)
249 if (m_sortingOrder->at(i)->getTitle().size())
250 m_sortingOrderStrings.append(m_sortingOrder->at(i)->getTitle());
252 return m_sortingOrderStrings;
256 void TableColumnList::setSortingOrder(
QStringList newOrder) {
257 for (
int i = newOrder.size() - 1; i >= 0; i--)
258 if (contains(newOrder[i]))
259 raiseToTop(
operator[](newOrder[i]));
263 void TableColumnList::checkIndexRange(
int index) {
266 if (index < 0 || index >= m_cols->size()) {
267 QString msg =
"index [";
269 msg +=
"] is out of range. Size of list is: ";
270 msg += m_cols->size();
276 void TableColumnList::nullify() {
278 m_sortingOrder = NULL;
This error is for when a programmer made an API call that was illegal.
#define _FILEINFO_
Macro for the filename and line number.
QPair< int, int > getVisibleXRange(int visibleColumn)