mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 05:10:04 +00:00 
			
		
		
		
	Implement layer move functionality using buttons
This commit is contained in:
		
							parent
							
								
									b45ec9dfa5
								
							
						
					
					
						commit
						5d06f6bc21
					
				
					 3 changed files with 190 additions and 39 deletions
				
			
		|  | @ -529,6 +529,62 @@ bool LayerModel::removeRows(int row, int count, const QModelIndex& parent) | |||
|    return true; | ||||
| } | ||||
| 
 | ||||
| bool LayerModel::moveRows(const QModelIndex& sourceParent, | ||||
|                           int                sourceRow, | ||||
|                           int                count, | ||||
|                           const QModelIndex& destinationParent, | ||||
|                           int                destinationChild) | ||||
| { | ||||
|    bool moved = false; | ||||
| 
 | ||||
|    if (sourceParent != destinationParent ||     // Only accept internal moves
 | ||||
|        count < 1 ||                             // Minimum selection size of 1
 | ||||
|        sourceRow < 0 ||                         // Valid source row (start)
 | ||||
|        sourceRow + count > p->layers_.size() || // Valid source row (end)
 | ||||
|        destinationChild < 0 ||                  // Valid destination row
 | ||||
|        destinationChild > p->layers_.size()) | ||||
|    { | ||||
|       return false; | ||||
|    } | ||||
| 
 | ||||
|    if (destinationChild < sourceRow) | ||||
|    { | ||||
|       // Move up
 | ||||
|       auto first  = p->layers_.begin() + destinationChild; | ||||
|       auto middle = p->layers_.begin() + sourceRow; | ||||
|       auto last   = middle + count; | ||||
| 
 | ||||
|       beginMoveRows(sourceParent, | ||||
|                     sourceRow, | ||||
|                     sourceRow + count - 1, | ||||
|                     destinationParent, | ||||
|                     destinationChild); | ||||
|       std::rotate(first, middle, last); | ||||
|       endMoveRows(); | ||||
| 
 | ||||
|       moved = true; | ||||
|    } | ||||
|    else if (sourceRow + count < destinationChild) | ||||
|    { | ||||
|       // Move down
 | ||||
|       auto first  = p->layers_.begin() + sourceRow; | ||||
|       auto middle = first + count; | ||||
|       auto last   = p->layers_.begin() + destinationChild; | ||||
| 
 | ||||
|       beginMoveRows(sourceParent, | ||||
|                     sourceRow, | ||||
|                     sourceRow + count - 1, | ||||
|                     destinationParent, | ||||
|                     destinationChild); | ||||
|       std::rotate(first, middle, last); | ||||
|       endMoveRows(); | ||||
| 
 | ||||
|       moved = true; | ||||
|    } | ||||
| 
 | ||||
|    return moved; | ||||
| } | ||||
| 
 | ||||
| void LayerModel::HandlePlacefileRemoved(const std::string& name) | ||||
| { | ||||
|    auto it = | ||||
|  |  | |||
|  | @ -66,6 +66,11 @@ public: | |||
|    bool removeRows(int                row, | ||||
|                    int                count, | ||||
|                    const QModelIndex& parent = QModelIndex()) override; | ||||
|    bool moveRows(const QModelIndex& sourceParent, | ||||
|                  int                sourceRow, | ||||
|                  int                count, | ||||
|                  const QModelIndex& destinationParent, | ||||
|                  int                destinationChild) override; | ||||
| 
 | ||||
| public slots: | ||||
|    void HandlePlacefileRemoved(const std::string& name); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat