// rdservicelistmodel.cpp // // Data model for Rivendell services // // (C) Copyright 2021 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 "rdservicelistmodel.h" RDServiceListModel::RDServiceListModel(bool incl_none,QObject *parent) : QAbstractTableModel(parent) { d_include_none=incl_none; // // 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("Pgm Code")); d_alignments.push_back(left); d_headers.push_back(tr("Track Group")); d_alignments.push_back(left); d_headers.push_back(tr("Log Shelf Life")); d_alignments.push_back(right); d_headers.push_back(tr("ELR Shelf Life")); d_alignments.push_back(right); d_headers.push_back(tr("Auto Refresh")); d_alignments.push_back(center); d_headers.push_back(tr("Chain Log")); d_alignments.push_back(center); d_headers.push_back(tr("Import Markers")); d_alignments.push_back(center); updateModel(); } RDServiceListModel::~RDServiceListModel() { } QPalette RDServiceListModel::palette() { return d_palette; } void RDServiceListModel::setPalette(const QPalette &pal) { d_palette=pal; } void RDServiceListModel::setFont(const QFont &font) { d_font=font; d_bold_font=font; d_bold_font.setWeight(QFont::Bold); } int RDServiceListModel::columnCount(const QModelIndex &parent) const { return d_headers.size(); } int RDServiceListModel::rowCount(const QModelIndex &parent) const { return d_texts.size(); } QVariant RDServiceListModel::headerData(int section,Qt::Orientation orient, int role) const { if((orient==Qt::Horizontal)&&(role==Qt::DisplayRole)) { return d_headers.at(section); } return QVariant(); } QVariant RDServiceListModel::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 RDServiceListModel::refresh(const QString &grpname) { for(int i=0;i texts; RDSqlQuery *q=NULL; QString sql=sqlFields(); sql+="order by NAME "; beginResetModel(); d_texts.clear(); if(d_include_none) { d_texts.push_back(texts); d_texts.back().push_back(tr("[none]")); for(int i=1;inext()) { d_texts.push_back(texts); updateRow(d_texts.size()-1,q); } delete q; endResetModel(); } void RDServiceListModel::updateRowLine(int line) { if(linefirst()) { updateRow(line,q); } delete q; } } void RDServiceListModel::updateRow(int row,RDSqlQuery *q) { QList texts; // Login Name texts.push_back(q->value(0)); // Description texts.push_back(q->value(1)); // Program Code texts.push_back(q->value(2)); // Track Group texts.push_back(q->value(3)); // Log Shelf Life texts.push_back(q->value(4)); // ELR Shelf Life texts.push_back(q->value(5)); // Auto Refresh texts.push_back(q->value(6)); // Chain Log texts.push_back(q->value(7)); // Import Markers texts.push_back(q->value(8)); d_texts[row]=texts; } QString RDServiceListModel::sqlFields() const { QString sql=QString("select ")+ "`SERVICES`.`NAME`,"+ // 00 "`SERVICES`.`DESCRIPTION`,"+ // 01 "`SERVICES`.`PROGRAM_CODE`,"+ // 02 "`SERVICES`.`TRACK_GROUP`,"+ // 03 "`SERVICES`.`DEFAULT_LOG_SHELFLIFE`,"+ // 04 "`SERVICES`.`ELR_SHELFLIFE`,"+ // 05 "`SERVICES`.`AUTO_REFRESH`,"+ // 06 "`SERVICES`.`CHAIN_LOG`,"+ // 07 "`SERVICES`.`INCLUDE_IMPORT_MARKERS` "+ // 08 "from `SERVICES` "; return sql; }