#include "evemodel.h"
#include <QProcess>
#include <QSize>
EveModel
::EveModel(QObject* parent
/* = 0 */ ) *m_headers << tr("Variable") << tr("Value") << tr("Origin") << tr("Description");
m_records = new QList<QStringList>();
m_delvars = new QList<QStringList>();
initListFromMem(*m_records);
}
int EveModel::rowCount(const QModelIndex& parent /*=QModelIndex() */) const {
if( parent.isValid() || ( m_records->count() == 0 ) )
return 0;
else
return m_records->count() - 1;
}
int EveModel::columnCount(const QModelIndex& parent /*=QModelIndex()*/ ) const {
Q_UNUSED(parent);
if ( m_records->count() )
return 7;
else
return 0;
}
QVariant EveModel
::data(const QModelIndex
& index,
int role
/* =Qt::DisplayRole */ ) const { if ( !index.isValid() || !m_records->count() )
if ( role == Qt::DisplayRole || role == Qt::EditRole )
return record.at(index.column());
if ( role == Qt::ToolTipRole ) {
tip = "<table>";
//int maxLines = record.count();
for (int i = 0; i < 4/*maxLines*/; i++) {
key = headerData(
i, Qt::Horizontal, Qt::DisplayRole).toString();
value = record.at(i);
if (!value.isEmpty())
tip
+= QString("<tr><td><b>%1</b>: %2</td></tr>").
arg(key, value
);
}
tip += "</table>";
return tip;
}
}
Qt
::ItemFlags EveModel
::flags(const QModelIndex &index
) const { if ( !index.isValid() || !m_records->count() )
return 0;
}
bool EveModel::setData ( const QModelIndex& index, const QVariant& value, int role /*=Qt::EditRole */ )
{
if ( index.isValid() && ( role == Qt::EditRole ) )
{
if ( ( *m_records ) [index.row() +1][6].isEmpty() )
( *m_records ) [index.row() +1][6] = ( *m_records ) [index.row() +1][index.column() ];
( *m_records ) [index.row() +1][index.column() ] = value.toString();
emit dataChanged ( index, index );
return true;
}
return false;
}
bool EveModel::setData ( const QModelIndex& index,
int role )
{
if ( index.isValid() )
{
if ( ( *m_records ) [index.row() +1][6].isEmpty() )
( *m_records ) [index.row() +1][6] = ( *m_records ) [index.row() +1][1];
( *m_records ) [index.row() +1][0] = variable;
( *m_records ) [index.row() +1][1] = value;
( *m_records ) [index.row() +1][4] = placeToSave;
emit dataChanged ( index.sibling ( index.row()+1, 0 ), index.sibling ( index.row()+1, 6 ) );
reset();
return true;
}
return false;
}
QVariant EveModel
::headerData(int section, Qt
::Orientation orientation,
int role
/* =Qt::DisplayRole */ ) const {
if (orientation == Qt::Horizontal) {
if (role == Qt::DisplayRole)
return m_headers
->count
() > section ? m_headers
->at
(section
) : QAbstractTableModel::headerData(section, orientation, role
);
if (role == Qt::SizeHintRole) {
}
}
else if (orientation == Qt::Vertical) {
if (role == Qt::DisplayRole)
}
}
EveModel::~EveModel() {
m_headers->clear();
delete m_headers;
m_delvars->clear();
delete m_delvars;
m_records->clear();
delete m_records;
}
void EveModel::initListFromMem(QList<QStringList>& outputList) {
outputList.clear();
QRegExp rx
("([a-zA-Z0-9_]+)=(.+)");
{
rx.indexIn(str);
if (!list.isEmpty())
{
list.removeFirst();
if ( !list.at(0).isEmpty() ) {
list << tr("System");
setDescription(list);
list << tr("local");
list << tr("");
list << tr("");
outputList.append(list);
}
}
}
}
void EveModel::setDescription(QStringList& list) {
if ("HOME" == list.at(0)) {
//this->homePath = list.at(1);
list << tr("This is the path to the home directory");
}
else if ("LOGNAME" == list.at(0)) {
//if( "root" == list.at(1) )
// this->isRoot = true;
list << tr("This is your logname");
}
else if ("SHELL" == list.at(0)) {
//if( "/bin/bash" == list.at(1) )
// this->isBash = true;
list << tr("Your shell");
}
else
list << tr("");
}
bool EveModel::insertRows(int row, int count, const QModelIndex& parent /* =QModelIndex()*/){
Q_UNUSED(parent);
emptyRecord << tr("NEW") << tr("VALUE") << tr("System") << tr("") << tr("") << tr("") << tr("");
m_records->append(emptyRecord);
endInsertRows();
return true;
}
bool EveModel::removeRows( int row, int count, const QModelIndex& parent) {
//Q_UNUSED(parent);
if( (m_records->at(row+1)).at(3) != "System")
m_delvars->append(m_records->at(row+1));
m_records->removeAt(row+1);
reset();
endRemoveRows();
if ( !parent.isValid() || m_records->count() == 0)
emit disableDel();
return true;
}
#include "evemodel.h"
#include <QProcess>
#include <QSize>
EveModel::EveModel(QObject* parent /* = 0 */ )
: QAbstractTableModel(parent) {
m_headers = new QStringList();
*m_headers << tr("Variable") << tr("Value") << tr("Origin") << tr("Description");
m_records = new QList<QStringList>();
m_delvars = new QList<QStringList>();
initListFromMem(*m_records);
}
int EveModel::rowCount(const QModelIndex& parent /*=QModelIndex() */) const {
if( parent.isValid() || ( m_records->count() == 0 ) )
return 0;
else
return m_records->count() - 1;
}
int EveModel::columnCount(const QModelIndex& parent /*=QModelIndex()*/ ) const {
Q_UNUSED(parent);
if ( m_records->count() )
return 7;
else
return 0;
}
QVariant EveModel::data(const QModelIndex& index, int role /* =Qt::DisplayRole */ ) const {
if ( !index.isValid() || !m_records->count() )
return QVariant();
QStringList record = m_records->at(index.row()+1);
if ( role == Qt::DisplayRole || role == Qt::EditRole )
return record.at(index.column());
if ( role == Qt::ToolTipRole ) {
QString tip, key, value;
tip = "<table>";
//int maxLines = record.count();
for (int i = 0; i < 4/*maxLines*/; i++) {
key = headerData(
i, Qt::Horizontal, Qt::DisplayRole).toString();
value = record.at(i);
if (!value.isEmpty())
tip += QString("<tr><td><b>%1</b>: %2</td></tr>").arg(key, value);
}
tip += "</table>";
return tip;
}
return QVariant();
}
Qt::ItemFlags EveModel::flags(const QModelIndex &index) const {
if ( !index.isValid() || !m_records->count() )
return 0;
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
}
bool EveModel::setData ( const QModelIndex& index, const QVariant& value, int role /*=Qt::EditRole */ )
{
if ( index.isValid() && ( role == Qt::EditRole ) )
{
if ( ( *m_records ) [index.row() +1][6].isEmpty() )
( *m_records ) [index.row() +1][6] = ( *m_records ) [index.row() +1][index.column() ];
( *m_records ) [index.row() +1][index.column() ] = value.toString();
emit dataChanged ( index, index );
return true;
}
return false;
}
bool EveModel::setData ( const QModelIndex& index,
const QString variable,
const QString value,
const QString placeToSave,
const QString initValue,
int role )
{
if ( index.isValid() )
{
if ( ( *m_records ) [index.row() +1][6].isEmpty() )
( *m_records ) [index.row() +1][6] = ( *m_records ) [index.row() +1][1];
( *m_records ) [index.row() +1][0] = variable;
( *m_records ) [index.row() +1][1] = value;
( *m_records ) [index.row() +1][4] = placeToSave;
emit dataChanged ( index.sibling ( index.row()+1, 0 ), index.sibling ( index.row()+1, 6 ) );
reset();
return true;
}
return false;
}
QVariant EveModel::headerData(int section, Qt::Orientation orientation, int role /* =Qt::DisplayRole */ ) const {
if (orientation == Qt::Horizontal) {
if (role == Qt::DisplayRole)
return m_headers->count() > section ? m_headers->at(section) : QAbstractTableModel::headerData(section, orientation, role);
if (role == Qt::SizeHintRole) {
return QSize(1, 30);
}
}
else if (orientation == Qt::Vertical) {
if (role == Qt::DisplayRole)
return QVariant();
}
return QAbstractTableModel::headerData(section, orientation, role);
}
EveModel::~EveModel() {
m_headers->clear();
delete m_headers;
m_delvars->clear();
delete m_delvars;
m_records->clear();
delete m_records;
}
void EveModel::initListFromMem(QList<QStringList>& outputList) {
outputList.clear();
QStringList sysvars = QProcess::systemEnvironment();
QRegExp rx("([a-zA-Z0-9_]+)=(.+)");
foreach( QString str, sysvars)
{
rx.indexIn(str);
QStringList list = rx.capturedTexts();
if (!list.isEmpty())
{
list.removeFirst();
if ( !list.at(0).isEmpty() ) {
list << tr("System");
setDescription(list);
list << tr("local");
list << tr("");
list << tr("");
outputList.append(list);
}
}
}
}
void EveModel::setDescription(QStringList& list) {
if ("HOME" == list.at(0)) {
//this->homePath = list.at(1);
list << tr("This is the path to the home directory");
}
else if ("LOGNAME" == list.at(0)) {
//if( "root" == list.at(1) )
// this->isRoot = true;
list << tr("This is your logname");
}
else if ("SHELL" == list.at(0)) {
//if( "/bin/bash" == list.at(1) )
// this->isBash = true;
list << tr("Your shell");
}
else
list << tr("");
}
bool EveModel::insertRows(int row, int count, const QModelIndex& parent /* =QModelIndex()*/){
Q_UNUSED(parent);
QStringList emptyRecord;
emptyRecord << tr("NEW") << tr("VALUE") << tr("System") << tr("") << tr("") << tr("") << tr("");
beginInsertRows(QModelIndex(), row, row);
m_records->append(emptyRecord);
endInsertRows();
return true;
}
bool EveModel::removeRows( int row, int count, const QModelIndex& parent) {
//Q_UNUSED(parent);
beginRemoveRows(QModelIndex(), row, row+1);
if( (m_records->at(row+1)).at(3) != "System")
m_delvars->append(m_records->at(row+1));
m_records->removeAt(row+1);
reset();
endRemoveRows();
if ( !parent.isValid() || m_records->count() == 0)
emit disableDel();
return true;
}
To copy to clipboard, switch view to plain text mode
Bookmarks