src/libraries.cpp

changeset 300
3a4b132b8353
parent 265
b2b7af293c46
child 380
16f6717a218b
equal deleted inserted replaced
299:cf9a854b56a9 300:3a4b132b8353
74 74
75 /** 75 /**
76 * @brief Removes a library by index. Does nothing if the index is not valid. 76 * @brief Removes a library by index. Does nothing if the index is not valid.
77 * @param libraryIndex Index of the library 77 * @param libraryIndex Index of the library
78 */ 78 */
79 void LibrariesModel::removeLibrary(const qsizetype libraryIndex) 79 void LibrariesModel::removeLibrary(const index_t libraryIndex)
80 { 80 {
81 Q_ASSERT(this->isValidIndex(libraryIndex)); 81 Q_ASSERT(this->isValidIndex(libraryIndex));
82 if (this->isValidIndex(libraryIndex)) 82 if (this->isValidIndex(libraryIndex))
83 { 83 {
84 Q_EMIT layoutAboutToBeChanged(); 84 Q_EMIT layoutAboutToBeChanged();
91 * @brief Gets a library by index. 91 * @brief Gets a library by index.
92 * @warning Index is assumed to be valid. 92 * @warning Index is assumed to be valid.
93 * @param libraryIndex Index of the library 93 * @param libraryIndex Index of the library
94 * @return const reference 94 * @return const reference
95 */ 95 */
96 const Library& LibrariesModel::library(qsizetype libraryIndex) const 96 const Library& LibrariesModel::library(index_t libraryIndex) const
97 { 97 {
98 Q_ASSERT(this->isValidIndex(libraryIndex)); 98 Q_ASSERT(this->isValidIndex(libraryIndex));
99 return this->libraries[libraryIndex]; 99 return this->libraries[libraryIndex];
100 } 100 }
101 101
102 /** 102 /**
103 * @brief Changes the path of the specified library 103 * @brief Changes the path of the specified library
104 * @param libraryIndex Index of the library 104 * @param libraryIndex Index of the library
105 * @param path New path 105 * @param path New path
106 */ 106 */
107 void LibrariesModel::setLibraryPath(qsizetype libraryIndex, const QDir& path) 107 void LibrariesModel::setLibraryPath(index_t libraryIndex, const QDir& path)
108 { 108 {
109 if (this->isValidIndex(libraryIndex)) 109 if (this->isValidIndex(libraryIndex))
110 { 110 {
111 this->libraries[libraryIndex].path = path; 111 this->libraries[libraryIndex].path = path;
112 this->signalLibraryChange(libraryIndex); 112 this->signalLibraryChange(libraryIndex);
116 /** 116 /**
117 * @brief Changes the role of the specified library 117 * @brief Changes the role of the specified library
118 * @param libraryIndex Index of the library 118 * @param libraryIndex Index of the library
119 * @param role New role 119 * @param role New role
120 */ 120 */
121 void LibrariesModel::setLibraryRole(qsizetype libraryIndex, const Library::Role role) 121 void LibrariesModel::setLibraryRole(index_t libraryIndex, const Library::Role role)
122 { 122 {
123 if (this->isValidIndex(libraryIndex)) 123 if (this->isValidIndex(libraryIndex))
124 { 124 {
125 this->libraries[libraryIndex].role = role; 125 this->libraries[libraryIndex].role = role;
126 this->signalLibraryChange(libraryIndex); 126 this->signalLibraryChange(libraryIndex);
147 } 147 }
148 148
149 /** 149 /**
150 * @returns the amount of libraries 150 * @returns the amount of libraries
151 */ 151 */
152 qsizetype LibrariesModel::count() const 152 index_t LibrariesModel::count() const
153 { 153 {
154 return this->libraries.size(); 154 return this->libraries.size();
155 } 155 }
156 156
157 void LibrariesModel::moveLibrary(const qsizetype libraryFromIndex, const qsizetype libraryToIndex) 157 void LibrariesModel::moveLibrary(const index_t libraryFromIndex, const index_t libraryToIndex)
158 { 158 {
159 if (isValidIndex(libraryFromIndex) and 159 if (isValidIndex(libraryFromIndex) and
160 (isValidIndex(libraryToIndex) or libraryToIndex == count()) and 160 (isValidIndex(libraryToIndex) or libraryToIndex == count()) and
161 libraryFromIndex != libraryToIndex) 161 libraryFromIndex != libraryToIndex)
162 { 162 {
179 /** 179 /**
180 * @brief Checks whether the specified index points to a valid library. 180 * @brief Checks whether the specified index points to a valid library.
181 * @param libraryIndex Index to check 181 * @param libraryIndex Index to check
182 * @returns whether or not it is valid 182 * @returns whether or not it is valid
183 */ 183 */
184 bool LibrariesModel::isValidIndex(const qsizetype libraryIndex) const 184 bool LibrariesModel::isValidIndex(const index_t libraryIndex) const
185 { 185 {
186 return libraryIndex >= 0 && libraryIndex < this->libraries.size(); 186 return libraryIndex >= 0 && libraryIndex < this->libraries.size();
187 } 187 }
188 188
189 /** 189 /**
316 /** 316 /**
317 * @brief Signals view objects that the specified library has changed. This is necessary 317 * @brief Signals view objects that the specified library has changed. This is necessary
318 * to update the table widget know when libraries are changed. 318 * to update the table widget know when libraries are changed.
319 * @param libraryIndex Index of the library. 319 * @param libraryIndex Index of the library.
320 */ 320 */
321 void LibrariesModel::signalLibraryChange(const qsizetype libraryIndex) 321 void LibrariesModel::signalLibraryChange(const index_t libraryIndex)
322 { 322 {
323 Q_ASSERT(isValidIndex(libraryIndex)); 323 Q_ASSERT(isValidIndex(libraryIndex));
324 const QModelIndex topLeft = this->index(static_cast<int>(libraryIndex), 0); 324 const QModelIndex topLeft = this->index(static_cast<int>(libraryIndex), 0);
325 const QModelIndex bottomRight = this->index(static_cast<int>(libraryIndex), columnCount({}) - 1); 325 const QModelIndex bottomRight = this->index(static_cast<int>(libraryIndex), columnCount({}) - 1);
326 Q_EMIT dataChanged(topLeft, bottomRight); 326 Q_EMIT dataChanged(topLeft, bottomRight);

mercurial