11 #include "TableColumnList.h"
19 #include "IException.h"
20 #include "TableColumn.h"
28 TableColumnList::TableColumnList() {
36 TableColumnList::TableColumnList(TableColumnList
const &other) {
44 TableColumnList::~TableColumnList() {
48 delete m_sortingOrder;
49 m_sortingOrder = NULL;
53 TableColumn *&TableColumnList::operator[](
int index) {
54 checkIndexRange(index);
56 return (*m_cols)[index];
60 TableColumn *&TableColumnList::operator[](QString title) {
61 for (
int i = 0; i < m_cols->size(); i++)
62 if (m_cols->at(i)->getTitle() == title)
65 QString msg =
"There is no column with a title of [";
67 msg +=
"] inside this column list";
72 void TableColumnList::append(TableColumn *newCol) {
74 QString msg =
"Attempted to add NULL column to the columnlist";
78 m_cols->append(newCol);
79 m_sortingOrder->append(newCol);
80 connect(newCol, SIGNAL(sortOutDated()),
this, SIGNAL(sortOutDated()));
84 void TableColumnList::prepend(TableColumn *newCol) {
85 m_cols->prepend(newCol);
86 m_sortingOrder->append(newCol);
90 int TableColumnList::indexOf(TableColumn
const *someCol)
const {
92 for (
int i = 0; index < 0 && i < m_cols->size(); i++)
93 if ((*m_cols)[i] == someCol)
100 bool TableColumnList::contains(TableColumn
const *someCol)
const {
101 return indexOf(someCol) != -1;
105 bool TableColumnList::contains(QString columnTitle)
const {
106 bool foundTitle =
false;
107 for (
int i = 0; i < m_cols->size() && !foundTitle; i++)
108 foundTitle = (m_cols->at(i)->getTitle() == columnTitle);
113 void TableColumnList::lower(TableColumn *col,
bool emitSortOutDated) {
114 int oldIndex = m_sortingOrder->indexOf(col);
115 checkIndexRange(oldIndex);
118 if (oldIndex < m_sortingOrder->size() - 1) {
119 m_sortingOrder->removeAt(oldIndex);
120 m_sortingOrder->insert(oldIndex + 1, col);
123 if (emitSortOutDated)
133 void TableColumnList::raise(TableColumn *col,
bool emitSortOutDated) {
134 int oldIndex = m_sortingOrder->indexOf(col);
135 checkIndexRange(oldIndex);
139 m_sortingOrder->removeAt(oldIndex);
140 m_sortingOrder->insert(oldIndex - 1, col);
143 if (emitSortOutDated)
153 void TableColumnList::raiseToTop(TableColumn *col) {
154 while (m_sortingOrder->at(0) != col)
166 int TableColumnList::size()
const {
168 return m_cols->size();
172 TableColumnList &TableColumnList::operator=(
173 TableColumnList other) {
174 swap(*m_cols, *other.m_cols);
175 swap(*m_sortingOrder, *other.m_sortingOrder);
190 if (visibleColumn < visibleCols.size() && visibleColumn >= 0) {
193 for (
int i = 0; i < visibleColumn; i++)
194 indent += visibleCols[i]->getWidth() - 1;
197 maxX = minX + visibleCols[visibleColumn]->getWidth() - 1;
210 for (
int i = 0; i < size(); i++)
211 if (m_cols->at(i)->isVisible())
212 visibleColumns.append(m_cols->at(i));
217 *visibleColumns.m_sortingOrder = *m_sortingOrder;
218 for (
int i = m_sortingOrder->size() - 1; i >= 0; i--)
219 if (!visibleColumns.contains((*visibleColumns.m_sortingOrder)[i]))
220 visibleColumns.m_sortingOrder->removeAt(i);
224 return visibleColumns;
228 int TableColumnList::getVisibleWidth()
const {
231 for (
int i = 0; i < size(); i++)
232 if (m_cols->at(i)->isVisible())
233 width += m_cols->at(i)->getWidth() - 1;
242 ASSERT(m_sortingOrder);
245 for (
int i = 0; i < m_sortingOrder->size(); i++)
246 if (m_sortingOrder->at(i)->getTitle().size())
247 validSortingOrder.append(m_sortingOrder->at(i));
249 return validSortingOrder;
253 QStringList TableColumnList::getSortingOrderAsStrings()
const {
255 for (
int i = 0; i < m_sortingOrder->size(); i++)
256 if (m_sortingOrder->at(i)->getTitle().size())
257 m_sortingOrderStrings.append(m_sortingOrder->at(i)->getTitle());
259 return m_sortingOrderStrings;
263 void TableColumnList::setSortingOrder(
QStringList newOrder) {
264 for (
int i = newOrder.size() - 1; i >= 0; i--)
265 if (contains(newOrder[i]))
266 raiseToTop(
operator[](newOrder[i]));
270 void TableColumnList::checkIndexRange(
int index) {
273 if (index < 0 || index >= m_cols->size()) {
274 QString msg =
"index [";
276 msg +=
"] is out of range. Size of list is: ";
277 msg += m_cols->size();
283 void TableColumnList::nullify() {
285 m_sortingOrder = NULL;