/[svn]/qsampler/trunk/src/qsamplerFxSendsModel.cpp
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerFxSendsModel.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3520 - (hide annotations) (download)
Mon Jul 1 10:53:41 2019 UTC (4 years, 8 months ago) by capela
File size: 5328 byte(s)
- Traded QT_VERSION literal checking for sane QT_VERSION_CHECK macro.
1 schoenebeck 1667 // qsamplerFxSendList.cpp
2     //
3     /****************************************************************************
4 capela 2979 Copyright (C) 2010-2016, rncbc aka Rui Nuno Capela. All rights reserved.
5 schoenebeck 1667 Copyright (C) 2008, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     as published by the Free Software Foundation; either version 2
10     of the License, or (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20    
21     *****************************************************************************/
22    
23     #include "qsamplerAbout.h"
24     #include "qsamplerFxSendsModel.h"
25     #include "qsamplerFxSend.h"
26    
27     #include <QBrush>
28     #include <QIcon>
29     #include <QFont>
30    
31     namespace QSampler {
32    
33 capela 2979
34     FxSendsModel::FxSendsModel ( int iChannelID, QObject* pParent )
35     : QAbstractListModel(pParent)
36     {
37     m_iChannelID = iChannelID;
38 schoenebeck 1667 cleanRefresh();
39     }
40    
41 capela 2979
42     int FxSendsModel::rowCount ( const QModelIndex& /*parent*/ ) const
43     {
44     return m_fxSends.size();
45 schoenebeck 1667 }
46    
47 capela 2979
48     QVariant FxSendsModel::data ( const QModelIndex& index, int role ) const
49     {
50 schoenebeck 1667 if (!index.isValid())
51     return QVariant();
52    
53     switch (role) {
54     case Qt::DisplayRole:
55 capela 2979 return m_fxSends[index.row()].name();
56 schoenebeck 1667 break;
57     case Qt::ToolTipRole:
58 capela 2979 if (m_fxSends[index.row()].deletion())
59 schoenebeck 1667 return QString(
60     "Scheduled for deletion. Click on 'Apply' to actually "
61     "destroy FX Send."
62     );
63 capela 2979 return (m_fxSends[index.row()].isNew()) ?
64 schoenebeck 1667 QString(
65     "New FX send. Click on 'Apply' to actually "
66     "perform creation."
67     ) :
68     QString("FX Send ID ") +
69 capela 2979 QString::number(m_fxSends.at(index.row()).id());
70 schoenebeck 1667 break;
71     case Qt::ForegroundRole:
72 capela 2979 if (m_fxSends.at(index.row()).deletion())
73 schoenebeck 1667 return QBrush(Qt::red);
74 capela 2979 if (m_fxSends.at(index.row()).isNew())
75 schoenebeck 1667 return QBrush(Qt::green);
76     break;
77     case Qt::DecorationRole:
78 capela 2979 if (m_fxSends.at(index.row()).deletion())
79 capela 2074 return QIcon(":/images/formRemove.png");
80 capela 2979 if (m_fxSends.at(index.row()).isNew())
81 capela 2074 return QIcon(":/images/itemNew.png");
82 capela 2979 if (m_fxSends.at(index.row()).isModified())
83 capela 2074 return QIcon(":/images/formEdit.png");
84     return QIcon(":/images/itemFile.png");
85 schoenebeck 1667 case Qt::FontRole: {
86 capela 2979 if (m_fxSends.at(index.row()).isModified()) {
87 schoenebeck 1667 QFont font;
88     font.setBold(true);
89     return font;
90     }
91     break;
92     }
93     default:
94     return QVariant();
95     }
96 capela 2979
97 schoenebeck 1667 return QVariant();
98     }
99    
100 capela 2979
101     bool FxSendsModel::setData (
102     const QModelIndex& index, const QVariant& value, int /*role*/ )
103 schoenebeck 1667 {
104     if (!index.isValid())
105     return false;
106    
107 capela 2979 m_fxSends[index.row()].setName(value.toString());
108 schoenebeck 1667 emit dataChanged(index, index);
109     emit fxSendsDirtyChanged(true);
110    
111     return true;
112     }
113    
114 capela 2979
115     QVariant FxSendsModel::headerData (
116     int section, Qt::Orientation /*orientation*/, int role ) const
117 schoenebeck 1667 {
118     if (role == Qt::DisplayRole && section == 0)
119     return QString("FX Send Name");
120     else
121     return QVariant();
122     }
123    
124 capela 2979
125     Qt::ItemFlags FxSendsModel::flags ( const QModelIndex& /*index*/) const
126     {
127 schoenebeck 1667 return Qt::ItemIsEditable | Qt::ItemIsEnabled;
128     }
129    
130 capela 2979
131     FxSend *FxSendsModel::addFxSend (void)
132     {
133 schoenebeck 1667 #if CONFIG_FXSEND
134 capela 2979 FxSend fxSend(m_iChannelID);
135 schoenebeck 1667 fxSend.setName("New FX Send");
136 capela 2979 m_fxSends.push_back(fxSend);
137     createIndex(m_fxSends.size() - 1, 0);
138 capela 3520 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
139 schoenebeck 1667 QAbstractListModel::reset();
140 capela 2387 #else
141     QAbstractListModel::beginResetModel();
142     QAbstractListModel::endResetModel();
143     #endif
144 schoenebeck 1667 emit fxSendsDirtyChanged(true);
145 capela 2979 return &m_fxSends.last();
146     #else
147 schoenebeck 1667 return NULL;
148     #endif // CONFIG_FXSEND
149     }
150    
151 capela 2979
152     FxSend *FxSendsModel::fxSend ( const QModelIndex& index )
153     {
154 schoenebeck 1667 if (!index.isValid())
155     return NULL;
156    
157 capela 2979 return &m_fxSends[index.row()];
158 schoenebeck 1667 }
159    
160 capela 2979
161     void FxSendsModel::removeFxSend ( const QModelIndex& index )
162     {
163     FxSend *pFxSend = fxSend(index);
164 schoenebeck 1667 if (!pFxSend) return;
165     pFxSend->setDeletion(true);
166 capela 3520 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
167 schoenebeck 1667 QAbstractListModel::reset();
168 capela 2387 #else
169     QAbstractListModel::beginResetModel();
170     QAbstractListModel::endResetModel();
171     #endif
172 schoenebeck 1667 emit fxSendsDirtyChanged(true);
173     }
174    
175 capela 2979
176     void FxSendsModel::cleanRefresh (void)
177     {
178     m_fxSends.clear();
179     const QList<int>& sends = FxSend::allFxSendsOfSamplerChannel(m_iChannelID);
180 schoenebeck 1667 for (int i = 0; i < sends.size(); ++i) {
181 capela 2979 const int iFxSendId = sends.at(i);
182     FxSend fxSend(m_iChannelID, iFxSendId);
183 schoenebeck 1667 fxSend.getFromSampler();
184 capela 2979 m_fxSends.push_back(fxSend);
185 schoenebeck 1667 }
186 capela 3520 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
187 schoenebeck 1667 QAbstractListModel::reset();
188 capela 2387 #else
189     QAbstractListModel::beginResetModel();
190     QAbstractListModel::endResetModel();
191     #endif
192 schoenebeck 1667 emit fxSendsDirtyChanged(false);
193     }
194    
195 capela 2979
196     void FxSendsModel::onExternalModifiication ( const QModelIndex& index )
197     {
198 schoenebeck 1668 if (!index.isValid()) return;
199     emit dataChanged(index, index);
200     emit fxSendsDirtyChanged(true);
201     }
202    
203 schoenebeck 1667
204 capela 2979 void FxSendsModel::applyToSampler (void)
205     {
206     for (int i = 0; i < m_fxSends.size(); ++i)
207     m_fxSends[i].applyToSampler();
208    
209 schoenebeck 1667 // make a clean refresh
210     // (throws out all FxSend objects marked for deletion)
211     cleanRefresh();
212     }
213    
214 capela 2979
215 schoenebeck 1667 } // namespace QSampler
216    
217 capela 2979
218 schoenebeck 1667 // end of qsamplerFxSendList.cpp

  ViewVC Help
Powered by ViewVC