PTableViewData::PTableViewData(QWidget *parent) : QTableView(parent){ connect(this->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(saveResize(int, int, int))); this->reset(); //this->setSelectionMode(QAbstractItemView::SingleSelection); this->setSelectionBehavior(QAbstractItemView::SelectRows); this->setSortingEnabled(true); this->horizontalHeader()->setMovable(true);}void PTableViewData::setModelData(QString psevdo, QString fileName, QList<int> qLstIgnore, QAbstractTableModel *model){ this->psevdo = psevdo; this->fileName = fileName; this->dataModel = model; qLstActions.clear(); for(int i=0; i < dataModel->columnCount(); i++) { QString name = dataModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(); if(name == "") name = QString().setNum(i); qLstActions.append(new QAction(name, this)); qLstActions.last()->setCheckable(true); QSettings set(fileName, QSettings::IniFormat); QString ch = set.value(psevdo + "_COLUMN/" + QString().setNum(i)).toString(); if(ch == "") ch = "1"; if(ch == "1") qLstActions.last()->setChecked(true); else qLstActions.last()->setChecked(false); for(int j=0; j < qLstIgnore.count();j++) { if(qLstIgnore.at(j) == i) qLstActions.last()->setVisible(false); } connect(qLstActions.last(), SIGNAL(triggered()), this, SLOT(setStateTable())); } this->horizontalHeader()->addActions(qLstActions); this->horizontalHeader()->setContextMenuPolicy(Qt::ActionsContextMenu); setStateTable();}void PTableViewData::setModelData(QString psevdo, QString fileName, QList<int> qLstIgnore, QSortFilterProxyModel *model){ this->psevdo = psevdo; this->fileName = fileName; this->dataModel = model->sourceModel(); this->headerModel = model; qLstActions.clear(); for(int i=0; i < dataModel->columnCount(); i++) { QString name = headerModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(); if(name == "") name = QString().setNum(i); qLstActions.append(new QAction(name, this)); qLstActions.last()->setCheckable(true); QSettings set(fileName, QSettings::IniFormat); QString ch = set.value(psevdo + "_COLUMN/" + QString().setNum(i)).toString(); if(ch == "") ch = "1"; if(ch == "1") qLstActions.last()->setChecked(true); else qLstActions.last()->setChecked(false); for(int j=0; j < qLstIgnore.count();j++) { if(qLstIgnore.at(j) == i) qLstActions.last()->setVisible(false); } connect(qLstActions.last(), SIGNAL(triggered()), this, SLOT(setStateTable())); } this->horizontalHeader()->addActions(qLstActions); this->horizontalHeader()->setContextMenuPolicy(Qt::ActionsContextMenu); setStateTable();}void PTableViewData::setStateTable(){ QSettings set(fileName, QSettings::IniFormat); for(int i=0; i < qLstActions.count();i++) { if(qLstActions.at(i)->isVisible() && !qLstActions.at(i)->isChecked()) this->hideColumn(i); else if(qLstActions.at(i)->isVisible() && qLstActions.at(i)->isChecked()) this->showColumn(i); set.setValue(psevdo + "_COLUMN/" + QString().setNum(i), QString().setNum(qLstActions.at(i)->isChecked())); } for(int i =0; i < this->horizontalHeader()->count();i++) { int s = set.value(psevdo + "_COLUMNSIZE/" + QString().setNum(i)).toInt(); if(s == 0) s = 80; this->setColumnWidth(i, s); }}void PTableViewData::saveResize(int column, int oldsize, int size){ if(size!=0) { QSettings set(fileName, QSettings::IniFormat); set.setValue(psevdo + "_COLUMNSIZE/" + QString().setNum(column), QString().setNum(size)); }}