Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2025 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #include "tableviewcell.h"
23 :
24 : using namespace muse::uicomponents;
25 :
26 0 : TableViewCell::TableViewCell(QObject* parent)
27 0 : : QObject(parent)
28 : {
29 0 : }
30 :
31 0 : muse::Val TableViewCell::value() const
32 : {
33 0 : return m_val;
34 : }
35 :
36 0 : void TableViewCell::setValue(const Val& value)
37 : {
38 0 : if (m_val == value) {
39 0 : return;
40 : }
41 :
42 0 : m_val = value;
43 0 : emit valueChanged();
44 : }
45 :
46 0 : void TableViewCell::setRequestChangeFunction(const std::function<bool(int, int, const Val&)>& func)
47 : {
48 0 : m_requestChangeFunction = func;
49 0 : }
50 :
51 0 : QVariant TableViewCell::value_property() const
52 : {
53 0 : return m_val.toQVariant();
54 : }
55 :
56 0 : void TableViewCell::setValue_property(const QVariant& newValue)
57 : {
58 0 : Val newVal = Val::fromQVariant(newValue);
59 0 : if (m_val == newVal) {
60 0 : return;
61 : }
62 :
63 0 : if (m_requestChangeFunction && !m_requestChangeFunction(m_row, m_column, newVal)) {
64 0 : return;
65 : }
66 :
67 0 : m_val = newVal;
68 0 : emit valueChanged();
69 0 : }
70 :
71 0 : int TableViewCell::row() const
72 : {
73 0 : return m_row;
74 : }
75 :
76 0 : void TableViewCell::setRow(int row)
77 : {
78 0 : if (m_row == row) {
79 0 : return;
80 : }
81 :
82 0 : m_row = row;
83 0 : emit rowChanged();
84 : }
85 :
86 0 : int TableViewCell::column() const
87 : {
88 0 : return m_column;
89 : }
90 :
91 0 : void TableViewCell::setColumn(int column)
92 : {
93 0 : if (m_column == column) {
94 0 : return;
95 : }
96 :
97 0 : m_column = column;
98 0 : emit columnChanged();
99 : }
100 :
101 0 : bool TableViewCell::hovered() const
102 : {
103 0 : return m_hovered;
104 : }
105 :
106 0 : void TableViewCell::setHovered(bool hovered)
107 : {
108 0 : if (m_hovered == hovered) {
109 0 : return;
110 : }
111 :
112 0 : m_hovered = hovered;
113 0 : emit hoveredChanged();
114 : }
115 :
116 0 : bool TableViewCell::pressed() const
117 : {
118 0 : return m_pressed;
119 : }
120 :
121 0 : void TableViewCell::setPressed(bool pressed)
122 : {
123 0 : if (m_pressed == pressed) {
124 0 : return;
125 : }
126 :
127 0 : m_pressed = pressed;
128 0 : emit pressedChanged();
129 : }
|