Line data Source code
1 : /// Including Schema Editor
2 : #include "dbe/SchemaCustomFileModel.hpp"
3 : #include "dbe/SchemaKernelWrapper.hpp"
4 : #include "dbe/SchemaStyle.hpp"
5 : /// Including C++ Headers
6 : #include <vector>
7 :
8 : #include <QBrush>
9 : #include <QColor>
10 : #include <QSize>
11 :
12 0 : dbse::CustomFileModel::CustomFileModel ( QStringList & Headers, QObject * parent )
13 : : QAbstractTableModel ( parent ),
14 0 : HeaderList ( Headers )
15 : {
16 0 : setupModel();
17 0 : }
18 :
19 0 : dbse::CustomFileModel::~CustomFileModel()
20 : {
21 0 : }
22 :
23 0 : int dbse::CustomFileModel::rowCount ( const QModelIndex & parent ) const
24 : {
25 0 : Q_UNUSED ( parent );
26 0 : return Data.size();
27 : }
28 :
29 0 : int dbse::CustomFileModel::columnCount ( const QModelIndex & parent ) const
30 : {
31 0 : Q_UNUSED ( parent );
32 0 : return HeaderList.size();
33 : }
34 :
35 : // Qt::ItemFlags dbse::CustomFileModel::flags ( const QModelIndex & index ) const
36 : // {
37 : // // if ( Data.value (index.row() ).value ( 1) == "RW" ) {
38 : // return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
39 : // // }
40 : // // else {
41 : // // return Qt::NoItemFlags;
42 : // // }
43 : // }
44 :
45 0 : QVariant dbse::CustomFileModel::headerData ( int section, Qt::Orientation orientation,
46 : int role ) const
47 : {
48 0 : if ( role != Qt::DisplayRole )
49 : {
50 0 : return QVariant();
51 : }
52 :
53 0 : if ( orientation == Qt::Horizontal )
54 : {
55 0 : return HeaderList.at ( section );
56 : }
57 :
58 0 : return QVariant();
59 : }
60 :
61 0 : QVariant dbse::CustomFileModel::data ( const QModelIndex & index, int role ) const
62 : {
63 0 : if ( role == Qt::DisplayRole ) {
64 0 : return Data.value(index.row()).value(index.column());
65 : }
66 0 : if (role == Qt::ForegroundRole) {
67 0 : if (Data.value(index.row()).value(2).contains("Active")) {
68 0 : return QBrush(QColor (SchemaStyle::get_color("foreground", "active_file")));
69 : }
70 0 : if (Data.value(index.row()).value(1) == "RW" ) {
71 0 : return QBrush(QColor (SchemaStyle::get_color("foreground", "default")));
72 : }
73 0 : return QBrush(SchemaStyle::get_color("foreground", "readonly"));
74 : }
75 0 : if (role == Qt::BackgroundRole) {
76 0 : if (Data.value(index.row()).value(2).contains("Active")) {
77 0 : return QBrush(QColor (SchemaStyle::get_color("background", "active_file")));
78 : }
79 0 : if (Data.value(index.row()).value(1) == "RW" ) {
80 0 : return QBrush(QColor (SchemaStyle::get_color("background", "default")));
81 : }
82 0 : return QBrush(SchemaStyle::get_color("background", "readonly"));
83 : }
84 0 : if (role == Qt::ToolTipRole) {
85 0 : return Data.value(index.row()).value(0);
86 : }
87 :
88 0 : return QVariant();
89 : }
90 :
91 0 : void dbse::CustomFileModel::setupModel()
92 : {
93 0 : std::vector<std::string> SchemaFiles;
94 0 : KernelWrapper::GetInstance().GetSchemaFiles ( SchemaFiles );
95 0 : std::string ActiveSchema = KernelWrapper::GetInstance().GetActiveSchema();
96 0 : std::string Modified = KernelWrapper::GetInstance().ModifiedSchemaFiles();
97 0 : for ( std::string & FileName : SchemaFiles )
98 : {
99 0 : QStringList Row;
100 0 : Row.append ( QString::fromStdString ( FileName ) );
101 :
102 0 : if ( KernelWrapper::GetInstance().IsFileWritable ( FileName ) )
103 : {
104 0 : Row.append ( "RW" );
105 : }
106 : else
107 : {
108 0 : Row.append ( "RO" );
109 : }
110 :
111 0 : std::string Status = "";
112 0 : if ( Modified.find( FileName ) != std::string::npos) {
113 0 : Status = "Modified";
114 : }
115 0 : if ( FileName == ActiveSchema) {
116 0 : if ( !Status.empty() ) {
117 0 : Status += " ";
118 : }
119 0 : Status += "Active";
120 : }
121 :
122 0 : Row.append ( QString::fromStdString ( Status ) );
123 0 : Data.append ( Row );
124 0 : }
125 0 : }
126 :
127 0 : QStringList dbse::CustomFileModel::getRowFromIndex ( QModelIndex & index )
128 : {
129 0 : if ( !index.isValid() )
130 : {
131 0 : return QStringList();
132 : }
133 :
134 0 : return Data.at ( index.row() );
135 : }
|