// rdgrouplistmodel.cpp // // Data model for Rivendell groups // // (C) Copyright 2021-2022 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // #include "rdapplication.h" #include "rdescape_string.h" #include "rdgrouplistmodel.h" RDGroupListModel::RDGroupListModel(bool show_all,bool show_unchanged, bool user_is_admin,QObject *parent) : QAbstractTableModel(parent) { d_show_all=show_all; d_show_unchanged=show_unchanged; d_user_is_admin=user_is_admin; d_service_names.push_back(tr("ALL")); d_sort_column=0; d_sort_order=Qt::AscendingOrder; d_column_fields.push_back("`NAME`"); d_column_fields.push_back("`DESCRIPTION`"); d_column_fields.push_back("`DEFAULT_LOW_CART`"); d_column_fields.push_back("`DEFAULT_HIGH_CART`"); d_column_fields.push_back("`ENFORCE_CART_RANGE`"); d_column_fields.push_back("`NOTIFY_EMAIL_ADDRESS`"); d_column_fields.push_back("`REPORT_TFC`"); d_column_fields.push_back("`REPORT_MUS`"); // // Column Attributes // unsigned left=Qt::AlignLeft|Qt::AlignVCenter; unsigned center=Qt::AlignCenter; // unsigned right=Qt::AlignRight|Qt::AlignVCenter; d_headers.push_back(tr("Name")); d_alignments.push_back(left); d_headers.push_back(tr("Description")); d_alignments.push_back(left); d_headers.push_back(tr("Start Cart")); d_alignments.push_back(center); d_headers.push_back(tr("End Cart")); d_alignments.push_back(center); d_headers.push_back(tr("Enforce Range")); d_alignments.push_back(center); d_headers.push_back(tr("E-Mail Addresses")); d_alignments.push_back(left); d_headers.push_back(tr("Traffic Report")); d_alignments.push_back(center); d_headers.push_back(tr("Music Report")); d_alignments.push_back(center); if(user_is_admin) { changeUser(); } } RDGroupListModel::~RDGroupListModel() { } QPalette RDGroupListModel::palette() { return d_palette; } void RDGroupListModel::setPalette(const QPalette &pal) { d_palette=pal; } void RDGroupListModel::setFont(const QFont &font) { d_font=font; d_bold_font=font; d_bold_font.setWeight(QFont::Bold); } int RDGroupListModel::columnCount(const QModelIndex &parent) const { return d_headers.size(); } int RDGroupListModel::rowCount(const QModelIndex &parent) const { return d_texts.size(); } QVariant RDGroupListModel::headerData(int section,Qt::Orientation orient, int role) const { if((orient==Qt::Horizontal)&&(role==Qt::DisplayRole)) { return d_headers.at(section); } return QVariant(); } QVariant RDGroupListModel::data(const QModelIndex &index,int role) const { QString str; int col=index.column(); int row=index.row(); if(row list; for(int i=0;ifirst()) { updateRow(row.row(),q); emit dataChanged(createIndex(row.row(),0), createIndex(row.row(),columnCount())); } delete q; } } void RDGroupListModel::refresh(const QString &grpname) { for(int i=0;inext()) { d_visible_groups.push_back(q->value(0).toString()); } delete q; beginResetModel(); updateModel(); endResetModel(); } void RDGroupListModel::updateModel() { QList texts; QList icons; RDSqlQuery *q=NULL; QString sql=sqlFields()+filterSql(); beginResetModel(); d_texts.clear(); d_colors.clear(); d_icons.clear(); if(d_show_all) { d_texts.push_back(texts); d_texts.back().push_back(tr("ALL")); d_colors.push_back(QVariant()); d_icons.push_back(icons); } if(d_show_unchanged) { d_texts.push_back(texts); d_texts.back().push_back(tr("[unchanged]")); d_colors.push_back(QVariant()); d_icons.push_back(icons); } q=new RDSqlQuery(sql); while(q->next()) { d_texts.push_back(texts); d_colors.push_back(QVariant()); d_icons.push_back(icons); updateRow(d_texts.size()-1,q); } delete q; endResetModel(); } void RDGroupListModel::updateRowLine(int line) { if(linefirst()) { updateRow(line,q); } delete q; } } void RDGroupListModel::updateRow(int row,RDSqlQuery *q) { QList texts; // Group Name texts.push_back(q->value(0)); d_colors[row]=QColor(q->value(9).toString()); if(q->value(5).toInt()==RDCart::Macro) { d_icons[row]=rda->iconEngine()->typeIcon(RDLogLine::Macro); } else { d_icons[row]=rda->iconEngine()->typeIcon(RDLogLine::Cart); } // Description texts.push_back(q->value(1)); // Start Cart if(q->value(2).toUInt()==0) { texts.push_back(tr("[none]")); } else { texts.push_back(QString::asprintf("%06u",q->value(2).toUInt())); } // End Cart if(q->value(3).toUInt()==0) { texts.push_back(tr("[none]")); } else { texts.push_back(QString::asprintf("%06u",q->value(3).toUInt())); } // Enforce Range texts.push_back(q->value(4)); // Notification E-Mail Addresses texts.push_back(q->value(6)); // Traffic Report texts.push_back(q->value(7)); // Music Report texts.push_back(q->value(8)); d_texts[row]=texts; } QString RDGroupListModel::sqlFields() const { QString sql=QString("select ")+ "`NAME`,"+ // 00 "`DESCRIPTION`,"+ // 01 "`DEFAULT_LOW_CART`,"+ // 02 "`DEFAULT_HIGH_CART`,"+ // 03 "`ENFORCE_CART_RANGE`,"+ // 04 "`DEFAULT_CART_TYPE`,"+ // 05 "`NOTIFY_EMAIL_ADDRESS`," // 06 "`REPORT_TFC`,"+ // 07 "`REPORT_MUS`,"+ // 08 "`COLOR` "+ // 09 "from `GROUPS` "; return sql; } QString RDGroupListModel::filterSql() const { QString sql=QString(" where ("); for(int i=0;i